From 607331c4ddf3a9bbac23916ccf5ed03e69ab4705 Mon Sep 17 00:00:00 2001 From: w1z7ard Date: Mon, 11 Feb 2008 06:02:05 +0000 Subject: [PATCH] huge update with a few very awful bugs left git-svn-id: https://projectm.svn.sourceforge.net/svnroot/projectm/trunk@815 6778bc44-b910-0410-a7a0-be141de4315d --- src/projectM-engine/BeatDetect.cpp | 5 - src/projectM-engine/CustomWave.cpp | 16 ++-- src/projectM-engine/FBO.cpp | 20 +--- src/projectM-engine/InitCond.cpp | 10 +- src/projectM-engine/PCM.cpp | 49 +++++----- src/projectM-engine/PCM.hpp | 23 ++--- src/projectM-engine/Param.cpp | 8 +- src/projectM-engine/Param.hpp | 10 +- src/projectM-engine/Parser.cpp | 23 +---- .../RandomNumberGenerators.cpp | 2 +- .../RandomNumberGenerators.hpp | 2 +- src/projectM-engine/Renderer.cpp | 17 +--- src/projectM-engine/projectM.cpp | 37 ++++---- src/projectM-engine/projectM.hpp | 8 +- src/projectM-xmms/main.cpp | 2 +- src/qprojectM-jack/qprojectM-jack.cpp | 2 +- src/qprojectM-pulseaudio/CMakeLists.txt | 2 + .../QPulseAudioDeviceChooser.cpp | 3 +- .../QPulseAudioDeviceChooser.hpp | 2 +- .../QPulseAudioThread.cpp | 93 ++++++++---------- .../QPulseAudioThread.hpp | 36 +++++-- .../qprojectM-pulseaudio.cpp | 11 +-- src/qprojectM/QPlaylistFileDialog.hpp | 4 +- src/qprojectM/QProjectMConfigDialog.cpp | 47 ++++++++-- src/qprojectM/QProjectMConfigDialog.hpp | 6 +- src/qprojectM/QProjectMConfigDialog.ui | 4 +- src/qprojectM/QProjectM_MainWindow.cpp | 94 ++++++++++--------- src/qprojectM/QProjectM_MainWindow.hpp | 47 +++++++--- 28 files changed, 302 insertions(+), 281 deletions(-) diff --git a/src/projectM-engine/BeatDetect.cpp b/src/projectM-engine/BeatDetect.cpp index 57ca15f16..e96323ef4 100755 --- a/src/projectM-engine/BeatDetect.cpp +++ b/src/projectM-engine/BeatDetect.cpp @@ -170,11 +170,6 @@ void BeatDetect::getBeatVals( float *vdataL,float *vdataR ) { mid_att=.6 * mid_att + .4 * mid; bass_att=.6 * bass_att + .4 * bass; - DWRITE( "BeatDetect::getBeatVals: treb: %f\tmid: %f\tbass: %f\n", - treb, mid, bass ); - DWRITE( "BeatDetect::getBeatVals: treb_att: %f\tmid_att: %f\tbass_att: %f\n", - treb_att, mid_att, bass_att ); - // *vol=(beat_instant[3])/(beat_history[3]); beat_buffer_pos++; if( beat_buffer_pos>79)beat_buffer_pos=0; diff --git a/src/projectM-engine/CustomWave.cpp b/src/projectM-engine/CustomWave.cpp index 9572c2213..706b6a4b7 100755 --- a/src/projectM-engine/CustomWave.cpp +++ b/src/projectM-engine/CustomWave.cpp @@ -411,42 +411,42 @@ CustomWave::CustomWave(int _id): param = Param::new_param_float ( "q1", P_FLAG_QVAR, &this->q1, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0 ); if ( ParamUtils::insert ( param, &this->param_tree ) < 0 ) { - DWRITE ( "%s\n", "failed to insert param!" ); + } param = Param::new_param_float ( "q2", P_FLAG_QVAR, &this->q2, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0 ); if ( ParamUtils::insert ( param, &this->param_tree ) < 0 ) { - DWRITE ( "%s\n", "failed to insert param!" ); + } param = Param::new_param_float ( "q3", P_FLAG_QVAR, &this->q3, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0 ); if ( ParamUtils::insert ( param, &this->param_tree ) < 0 ) { - DWRITE ( "%s\n", "failed to insert param!" ); + } param = Param::new_param_float ( "q4", P_FLAG_QVAR, &this->q4, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0 ); if ( ParamUtils::insert ( param, &this->param_tree ) < 0 ) { - DWRITE ( "%s\n", "failed to insert param!" ); + } param = Param::new_param_float ( "q5", P_FLAG_QVAR, &this->q5, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0 ); if ( ParamUtils::insert ( param, &this->param_tree ) < 0 ) { - DWRITE ( "%s\n", "failed to insert param!" ); + } param = Param::new_param_float ( "q6", P_FLAG_QVAR, &this->q6, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0 ); if ( ParamUtils::insert ( param, &this->param_tree ) < 0 ) { - DWRITE ( "%s\n", "failed to insert param!" ); + } param = Param::new_param_float ( "q7", P_FLAG_QVAR, &this->q7, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0 ); if ( ParamUtils::insert ( param, &this->param_tree ) < 0 ) { - DWRITE ( "%s\n", "failed to insert param!" ); + } param = Param::new_param_float ( "q8", P_FLAG_QVAR, &this->q8, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0 ); if ( ParamUtils::insert ( param, &this->param_tree ) < 0 ) { - DWRITE ( "%s\n", "failed to insert param!" ); + } /* End of parameter loading. Note that the read only parameters associated with custom waves (ie, sample) are variables stored in PresetFrameIO.hpp, diff --git a/src/projectM-engine/FBO.cpp b/src/projectM-engine/FBO.cpp index d09dcd4f6..5db00a5ed 100755 --- a/src/projectM-engine/FBO.cpp +++ b/src/projectM-engine/FBO.cpp @@ -147,9 +147,6 @@ RenderTarget::RenderTarget(int texsize, int width, int height) : useFBO(false) { else this->useFBO=0; } - - DWRITE( "using teximage hack fallback\n" ); - /** Fallback pbuf;fer creation via teximage hack */ /** Check the texture size against the viewport size */ /** If the viewport is smaller, then we'll need to scale the texture size down */ @@ -160,18 +157,13 @@ RenderTarget::RenderTarget(int texsize, int width, int height) : useFBO(false) { /* Create the texture that will be bound to the render this */ if ( glIsTexture( this->textureID[0] ) ) { - DWRITE( "texture already exists\n" ); - if ( this->texsize != origtexsize ) { - DWRITE( "deleting existing texture due to resize\n" ); + if ( this->texsize != origtexsize ) glDeleteTextures( 1, &this->textureID[0] ); - } } if ( !glIsTexture( this->textureID[0] ) ) { glGenTextures(1, &this->textureID[0] ); - DWRITE( "allocate texture: %d\ttexsize: %d x %d\n", - this->textureID[0], this->texsize, this->texsize ); glBindTexture(GL_TEXTURE_2D, this->textureID[0] ); //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); @@ -201,9 +193,9 @@ RenderTarget::RenderTarget(int texsize, int width, int height) : useFBO(false) { /* Create the texture that will be bound to the render this */ if ( glIsTexture( this->textureID[0] ) ) { - DWRITE( "texture already exists\n" ); + if ( this->texsize != origtexsize ) { - DWRITE( "deleting existing texture due to resize\n" ); + glDeleteTextures( 1, &this->textureID[0] ); } } @@ -211,8 +203,6 @@ RenderTarget::RenderTarget(int texsize, int width, int height) : useFBO(false) { if ( !glIsTexture( this->textureID[0] ) ) { glGenTextures(1, &this->textureID[0] ); - DWRITE( "allocate texture: %d\ttexsize: %d x %d\n", - this->textureID[0], this->texsize, this->texsize ); glBindTexture(GL_TEXTURE_2D, this->textureID[0] ); //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); @@ -260,7 +250,7 @@ void RenderTarget::unlock() { } /** Fallback texture path */ - DWRITE( "copying framebuffer to texture\n" ); + glBindTexture( GL_TEXTURE_2D, this->textureID[0] ); glCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 0, 0, this->texsize, this->texsize ); @@ -275,8 +265,6 @@ int RenderTarget::nearestPower2( int value, TextureScale scaleRule ) { int x = value; int power = 0; - DWRITE( "nearestPower2(): %d\n", value ); - while ( ( x & 0x01 ) != 1 ) { x >>= 1; } diff --git a/src/projectM-engine/InitCond.cpp b/src/projectM-engine/InitCond.cpp index 321756aa0..2dae471f0 100755 --- a/src/projectM-engine/InitCond.cpp +++ b/src/projectM-engine/InitCond.cpp @@ -91,10 +91,7 @@ param->matrix_flag = false; /* Parameter is an integer type, just like C */ if ( param->type == P_TYPE_INT) { - if (INIT_COND_DEBUG) { - DWRITE( "init_cond: %s = %d (TYPE INT)\n", param->name.c_str(), init_val.int_val); - } - assert(param->engine_val); + assert(param->engine_val); *((int*)param->engine_val) = init_val.int_val; return; } @@ -102,11 +99,6 @@ param->matrix_flag = false; /* Parameter is of a float type, just like C */ if (param->type == P_TYPE_DOUBLE) { - if (INIT_COND_DEBUG) { - DWRITE( "init_cond: %s = %f (TYPE DOUBLE) -> %f -> %X -> %X\n", param->name.c_str(), - init_val.float_val, *((float *)param->engine_val), - param, param->engine_val ); - } assert(param->engine_val); *((float*)param->engine_val) = init_val.float_val; return; diff --git a/src/projectM-engine/PCM.cpp b/src/projectM-engine/PCM.cpp index 593169c60..3f3ba948e 100755 --- a/src/projectM-engine/PCM.cpp +++ b/src/projectM-engine/PCM.cpp @@ -32,29 +32,32 @@ #include "wipemalloc.h" #include "fftsg.h" #include "PCM.hpp" +#include + +int PCM::maxsamples = 2048; //initPCM(int samples) // //Initializes the PCM buffer to // number of samples specified. - +#include PCM::PCM() { initPCM( 2048 ); + std::cerr << "MAX SAMPLES:" << maxsamples << std::endl; } void PCM::initPCM(int samples) { int i; - DWRITE( "initPCM()\n" ); - waveSmoothing = 0; //Allocate memory for PCM data buffer + assert(samples == 2048); PCMd = (float **)wipemalloc(2 * sizeof(float *)); PCMd[0] = (float *)wipemalloc(samples * sizeof(float)); PCMd[1] = (float *)wipemalloc(samples * sizeof(float)); - maxsamples=samples; + //maxsamples=samples; newsamples=0; numsamples = maxsamples; @@ -98,33 +101,37 @@ PCM::~PCM() { } -void PCM::addPCMfloat(float *PCMdata, int samples) +#include + +void PCM::addPCMfloat(const float *PCMdata, int samples) const { int i,j; - + std::cerr << "start:" << this->start << std::endl; + static bool firstTime = true; + + if (firstTime) { + start = 0; + firstTime = false; + } + for(i=0;i namespace RandomNumberGenerators { -7 + } diff --git a/src/projectM-engine/RandomNumberGenerators.hpp b/src/projectM-engine/RandomNumberGenerators.hpp index 45f32babe..7404eb834 100644 --- a/src/projectM-engine/RandomNumberGenerators.hpp +++ b/src/projectM-engine/RandomNumberGenerators.hpp @@ -52,4 +52,4 @@ inline float gaussian(float mean, float sigma) } -#endif \ No newline at end of file +#endif diff --git a/src/projectM-engine/Renderer.cpp b/src/projectM-engine/Renderer.cpp index ef64c9104..a5ce5249e 100644 --- a/src/projectM-engine/Renderer.cpp +++ b/src/projectM-engine/Renderer.cpp @@ -124,9 +124,7 @@ void Renderer::RenderFrame(PresetOutputs *presetOutputs, PresetInputs *presetInp - totalframes++; - - DWRITE( "start Pass 1 \n" ); + totalframes++; //BEGIN PASS 1 // @@ -163,8 +161,7 @@ void Renderer::RenderFrame(PresetOutputs *presetOutputs, PresetInputs *presetInp glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); - - DWRITE( "renderFrame: renderTarget->texsize: %d x %d\n", this->renderTarget->texsize, this->renderTarget->texsize ); + if(this->renderTarget->useFBO) { @@ -218,7 +215,7 @@ void Renderer::RenderFrame(PresetOutputs *presetOutputs, PresetInputs *presetInp } else glViewport( 0, 0, this->vw, this->vh ); - DWRITE( "viewport: %d x %d\n", this->vw, this->vh ); + glBindTexture( GL_TEXTURE_2D, this->renderTarget->textureID[0] ); @@ -249,7 +246,6 @@ void Renderer::RenderFrame(PresetOutputs *presetOutputs, PresetInputs *presetInp if(renderTarget->renderToTexture) glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); - DWRITE("End of Pass 2\n" ); } @@ -708,8 +704,6 @@ void Renderer::WaveformMath(PresetOutputs *presetOutputs, PresetInputs *presetIn presetOutputs->two_waves = false; - DWRITE( "WaveformMath: %d\n", presetOutputs->nWaveMode ); - switch(presetOutputs->nWaveMode) { @@ -720,7 +714,6 @@ void Renderer::WaveformMath(PresetOutputs *presetOutputs, PresetInputs *presetIn presetOutputs->wave_scale =1.0; presetOutputs->wave_y=-1*(presetOutputs->wave_y-1.0); - DWRITE( "nsamples: %d\n", beatDetect->pcm->numsamples ); presetOutputs->wave_samples = isSmoothing ? 512-32 : beatDetect->pcm->numsamples; // presetOutputs->wave_samples= 512-32; @@ -1377,7 +1370,7 @@ void Renderer::draw_help( ) #ifdef USE_FTGL //glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO); - DWRITE("pre-help"); + glColor4f(1.0, 1.0, 1.0, 1.0); glPushMatrix(); glTranslatef(0, 1, 0); @@ -1426,7 +1419,7 @@ void Renderer::draw_help( ) glPopMatrix(); // glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); - DWRITE("post-help"); + #endif /** USE_FTGL */ } diff --git a/src/projectM-engine/projectM.cpp b/src/projectM-engine/projectM.cpp index bdf3312b2..543250c3e 100755 --- a/src/projectM-engine/projectM.cpp +++ b/src/projectM-engine/projectM.cpp @@ -83,8 +83,10 @@ projectM::~projectM() delete ( renderer ); if ( beatDetect ) delete ( beatDetect ); - if ( pcm ) - delete ( pcm ); + if ( _pcm ) { + delete ( _pcm ); + _pcm = 0; + } } DLLEXPORT unsigned projectM::initRenderToTexture() @@ -98,11 +100,11 @@ DLLEXPORT void projectM::projectM_resetTextures() } DLLEXPORT projectM::projectM ( std::string config_file ) : - beatDetect ( 0 ), renderer ( 0 ), smoothFrame ( 0 ), m_presetQueuePos(0), oldFrame(1) + beatDetect ( 0 ), renderer ( 0 ), smoothFrame ( 0 ), m_presetQueuePos(0), oldFrame(1), _pcm(0) { - + readConfig ( config_file ); projectM_reset(); - readConfig ( config_file ); + projectM_resetGL ( _settings.windowWidth, _settings.windowHeight); } @@ -135,6 +137,9 @@ bool projectM::writeConfig(const std::string & configFile, const Settings & sett } int projectM::sampledPresetDuration() { + + + return ( int ) (_settings.fps * fmax(1, fmin(60, RandomNumberGenerators::gaussian (settings().presetDuration, settings().easterEgg)))); } @@ -172,7 +177,7 @@ void projectM::readConfig (const std::string & configFile ) else _settings.aspectCorrection = renderer->correction = 0; - projectM_resetGL ( _settings.windowWidth, _settings.windowHeight); + } @@ -204,16 +209,8 @@ DLLEXPORT void projectM::renderFrame() // printf("start:%d at:%d min:%d stop:%d on:%d %d\n",startframe, frame frame-startframe,avgtime, noSwitch,progress); presetInputs.ResetMesh(); -// printf("%f %d\n",Time,frame); - - beatDetect->detectFromSamples(); - DWRITE ( "=== vol: %f\tbass: %f\tmid: %f\ttreb: %f ===\n", - beatDetect->vol,beatDetect->bass,beatDetect->mid,beatDetect->treb ); - DWRITE ( "=== bass_att: %f ===\n", - beatDetect->bass_att ); - presetInputs.bass = beatDetect->bass; presetInputs.mid = beatDetect->mid; presetInputs.treb = beatDetect->treb; @@ -347,7 +344,7 @@ DLLEXPORT void projectM::renderFrame() this->timestart=getTicks ( &this->startTime ); #endif /** !WIN32 */ - DWRITE ( "exiting renderFrame()\n" ); + } void projectM::projectM_reset() @@ -385,8 +382,6 @@ void projectM::projectM_init ( int gx, int gy, int fps, int texsize, int width, presetOutputs.Initialize ( gx, gy ); presetOutputs2.Initialize ( gx, gy ); - DWRITE ( "projectM plugin: Initializing\n" ); - /** Initialise start time */ #ifndef WIN32 gettimeofday ( &this->startTime, NULL ); @@ -405,8 +400,11 @@ void projectM::projectM_init ( int gx, int gy, int fps, int texsize, int width, /** We need to initialise this before the builtin param db otherwise bass/mid etc won't bind correctly */ assert ( !beatDetect ); - pcm = new PCM(); - beatDetect = new BeatDetect ( pcm ); + std::cerr << "pcm new" << std::endl; + if (!_pcm) + _pcm = new PCM(); + assert(pcm()); + beatDetect = new BeatDetect ( _pcm ); initPresetTools(); #if 0 @@ -535,6 +533,7 @@ void projectM::projectM_init ( int gx, int gy, int fps, int texsize, int width, renderer->setPresetName ( m_activePreset->presetName() ); + assert(pcm()); // printf ( "exiting projectM_init()\n" ); } diff --git a/src/projectM-engine/projectM.hpp b/src/projectM-engine/projectM.hpp index a3bdfac84..3b169e8f7 100755 --- a/src/projectM-engine/projectM.hpp +++ b/src/projectM-engine/projectM.hpp @@ -122,7 +122,7 @@ class projectM { public: - PCM *pcm; + DLLEXPORT projectM(std::string config_file); DLLEXPORT projectM(int gx, int gy, int fps, int texsize, int width, int height,std::string preset_url,std::string title_fonturl, std::string title_menuurl); @@ -210,7 +210,11 @@ public: /// Occurs when active preset has switched. Switched to index is returned virtual void presetSwitchedEvent(bool isHardCut, unsigned int index) const {}; + inline const PCM * pcm() { + return _pcm; + } private: + int sampledPresetDuration(); BeatDetect * beatDetect; Renderer *renderer; @@ -279,6 +283,8 @@ private: /// A preset outputs container used for smooth preset switching PresetOutputs presetOutputs2; + PCM * _pcm; + int oldFrame;// = 1; }; diff --git a/src/projectM-xmms/main.cpp b/src/projectM-xmms/main.cpp index f52a4261c..f81ba6b18 100755 --- a/src/projectM-xmms/main.cpp +++ b/src/projectM-xmms/main.cpp @@ -196,7 +196,7 @@ int worker_func(void*) key = sdl2pmKeycode( event.key.keysym.sym ); mod = sdl2pmModifier( event.key.keysym.mod ); - if ( evt == PROJECTM_KEYDOWN ) { + if ( evt == PROJECTM_KEYDOWN ) { if(key == PROJECTM_K_c) { diff --git a/src/qprojectM-jack/qprojectM-jack.cpp b/src/qprojectM-jack/qprojectM-jack.cpp index 9d02b7f14..b6056c7c1 100644 --- a/src/qprojectM-jack/qprojectM-jack.cpp +++ b/src/qprojectM-jack/qprojectM-jack.cpp @@ -162,7 +162,7 @@ process (jack_nframes_t nframes, void *arg) //memcpy (out, in,sizeof (jack_default_audio_sample_t) * nframes); - globalPM->pcm->addPCMfloat(in,nframes); + globalPM->pcm()->addPCMfloat(in,nframes); // printf("%x %f\n",nframes,in[128]); diff --git a/src/qprojectM-pulseaudio/CMakeLists.txt b/src/qprojectM-pulseaudio/CMakeLists.txt index eaea9bcaa..404620cfd 100644 --- a/src/qprojectM-pulseaudio/CMakeLists.txt +++ b/src/qprojectM-pulseaudio/CMakeLists.txt @@ -7,8 +7,10 @@ include(${QT_USE_FILE} FindPkgConfig.cmake) FIND_PACKAGE(OpenGL) FIND_PACKAGE(Qt4 REQUIRED) + pkg_search_module(PROJECTM REQUIRED libprojectM) pkg_search_module(PROJECTM REQUIRED libqprojectM) +pkg_search_module(PROJECTM REQUIRED pulse) # the variable "qprojectM_SRCS" contains all .cpp files of this project set(qprojectM_pulseaudio_SRCS diff --git a/src/qprojectM-pulseaudio/QPulseAudioDeviceChooser.cpp b/src/qprojectM-pulseaudio/QPulseAudioDeviceChooser.cpp index c61a0fd5a..c03dd0da4 100644 --- a/src/qprojectM-pulseaudio/QPulseAudioDeviceChooser.cpp +++ b/src/qprojectM-pulseaudio/QPulseAudioDeviceChooser.cpp @@ -37,7 +37,6 @@ void QPulseAudioDeviceChooser::readSettings() void QPulseAudioDeviceChooser::updateDevicesListViewLock(int state) { - devicesListView->setEnabled(state != Qt::Checked); @@ -51,7 +50,7 @@ QPulseAudioDeviceChooser::QPulseAudioDeviceChooser ( QPulseAudioThread * qpulseA { setupUi ( this ); - readSettings(); + readSettings(); this->devicesListView->setModel ( &_qpulseAudioDeviceModel ); connect ( tryFirstPlayBackMonitorCheckBox, SIGNAL(stateChanged(int)), this, SLOT(updateDevicesListViewLock(int))); diff --git a/src/qprojectM-pulseaudio/QPulseAudioDeviceChooser.hpp b/src/qprojectM-pulseaudio/QPulseAudioDeviceChooser.hpp index 45deaa403..4cb2c4433 100644 --- a/src/qprojectM-pulseaudio/QPulseAudioDeviceChooser.hpp +++ b/src/qprojectM-pulseaudio/QPulseAudioDeviceChooser.hpp @@ -8,7 +8,7 @@ class QDialog; class QPulseAudioDeviceChooser : public QDialog, public Ui::pulseDeviceChooserDialog { - + Q_OBJECT public: diff --git a/src/qprojectM-pulseaudio/QPulseAudioThread.cpp b/src/qprojectM-pulseaudio/QPulseAudioThread.cpp index f6f863ba8..514632cc0 100644 --- a/src/qprojectM-pulseaudio/QPulseAudioThread.cpp +++ b/src/qprojectM-pulseaudio/QPulseAudioThread.cpp @@ -4,30 +4,10 @@ #include #include - - -/* $Id: pacat.c 1426 2007-02-13 15:35:19Z ossman $ */ - -/*** - This file is part of PulseAudio. +/* Adopted from PulseAudio. Copyright 2004-2006 Lennart Poettering Copyright 2006 Pierre Ossman for Cendio AB - - PulseAudio is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published - by the Free Software Foundation; either version 2 of the License, - or (at your option) any later version. - - PulseAudio is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with PulseAudio; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - USA. ***/ #ifdef HAVE_CONFIG_H @@ -44,6 +24,8 @@ #include #include +#include +#include "QProjectM_MainWindow.hpp" #define TIME_EVENT_USEC 50000 @@ -54,30 +36,30 @@ #define BUFSIZE 1024 -static pa_context *context = NULL; -static pa_stream *stream = NULL; -static pa_mainloop_api *mainloop_api = NULL; -static pa_time_event *time_event = NULL; -static float *buffer = NULL; -static size_t buffer_length = 0, buffer_index = 0; -static pa_threaded_mainloop* mainloop = NULL; -static pa_io_event* stdio_event = NULL; -static char *server = NULL; -static char *stream_name = NULL, *client_name = NULL, *device =0; + pa_context *QPulseAudioThread::context = NULL; + pa_stream *QPulseAudioThread::stream = NULL; + pa_mainloop_api *QPulseAudioThread::mainloop_api = NULL; + pa_time_event *QPulseAudioThread::time_event = NULL; + float *QPulseAudioThread::buffer = NULL; + size_t QPulseAudioThread::buffer_length = 0, QPulseAudioThread::buffer_index = 0; + pa_threaded_mainloop * QPulseAudioThread::mainloop = NULL; + pa_io_event * QPulseAudioThread::stdio_event = NULL; + char * QPulseAudioThread::server = NULL; + char * QPulseAudioThread::stream_name = NULL, *QPulseAudioThread::client_name = NULL, *QPulseAudioThread::device =0; -static int verbose = 0; -static pa_volume_t volume = PA_VOLUME_NORM; + int QPulseAudioThread::verbose = 0; -static pa_channel_map channel_map; -static int channel_map_set = 0; -static pa_sample_spec sample_spec ; + pa_volume_t QPulseAudioThread::volume = PA_VOLUME_NORM; + + pa_channel_map QPulseAudioThread::channel_map; + int QPulseAudioThread::channel_map_set = 0; + pa_sample_spec QPulseAudioThread::sample_spec ; QPulseAudioThread::SourceContainer QPulseAudioThread::s_sourceList; QPulseAudioThread::SourceContainer::const_iterator QPulseAudioThread::s_sourcePosition; - -#include - -QPulseAudioThread::QPulseAudioThread ( int _argc, char **_argv, projectM * _projectM, QObject * parent ) : QThread ( parent ), argc ( _argc ), argv ( _argv ), m_projectM ( _projectM ) + + +QPulseAudioThread::QPulseAudioThread ( int _argc, char **_argv, QProjectM * _projectM, QObject * parent ) : QThread ( parent ), argc ( _argc ), argv ( _argv ), m_projectM ( _projectM ) { } @@ -98,10 +80,10 @@ QPulseAudioThread::SourceContainer::const_iterator QPulseAudioThread::readSettin if ( tryFirst ) { - qDebug() << "try first is true"; + return s_sourceList.end(); } else { - qDebug() << "try first is false"; + QString deviceName = settings.value("pulseAudioDeviceName", QString()).toString(); qDebug() << "device name is " << deviceName; @@ -110,7 +92,7 @@ QPulseAudioThread::SourceContainer::const_iterator QPulseAudioThread::readSettin if (*pos == deviceName) { return pos; } - } + } } return s_sourceList.end(); } @@ -149,7 +131,6 @@ void QPulseAudioThread::cleanup() pa_threaded_mainloop_free ( mainloop ); } - if ( buffer ) pa_xfree ( buffer ); @@ -276,8 +257,11 @@ void QPulseAudioThread::pa_stream_success_callback(pa_stream *s, int success, vo else qDebug() << "play"; - pausedFlag = !pausedFlag; + pausedFlag = !pausedFlag; + //m_projectM._audioMutex.unlock(); + // necessarily static + // can do pulse stuff here... } @@ -448,7 +432,7 @@ void QPulseAudioThread::context_drain_complete ( pa_context*c, void *userdata ) /* Some data may be written to STDOUT */ void QPulseAudioThread::stdout_callback ( pa_mainloop_api*a, pa_io_event *e, int fd, pa_io_event_flags_t f, void *userdata ) { - ssize_t r; + assert ( a == mainloop_api && e && stdio_event == e ); if ( !buffer ) @@ -458,15 +442,19 @@ void QPulseAudioThread::stdout_callback ( pa_mainloop_api*a, pa_io_event *e, int } else { - projectM * prjm = static_cast ( userdata ); + QProjectM * prjm = static_cast ( userdata ); //int * int_buf = (int *) buffer; //qDebug() << int_buf[buffer_index]; //qDebug() << buffer[buffer_index]; - - prjm->pcm->addPCMfloat - ( buffer+buffer_index, buffer_length / ( sizeof ( float ) ) ); + assert(prjm); + assert(prjm->pcm()); + assert(buffer); + qDebug() << "buffer index: " << buffer_index << ", buffer length:" << buffer_length; + prjm->pcm()->addPCMfloat + ( buffer+buffer_index, buffer_length / ( sizeof ( float ) ) ); + assert ( buffer_length ); - + pa_xfree ( buffer ); buffer = NULL; buffer_length = buffer_index = 0; @@ -609,7 +597,7 @@ void QPulseAudioThread::run() const char * error = "FOO"; int ret = 1, r, c; - char *bn = "projectM"; + const char *bn = "projectM"; pa_operation * operation ; sample_spec.format = PA_SAMPLE_FLOAT32LE; sample_spec.rate = 44100; @@ -666,6 +654,7 @@ void QPulseAudioThread::run() signal ( SIGPIPE, SIG_IGN ); #endif + assert(m_projectM); if ( ! ( stdio_event = mainloop_api->io_new ( mainloop_api, STDOUT_FILENO, PA_IO_EVENT_OUTPUT, diff --git a/src/qprojectM-pulseaudio/QPulseAudioThread.hpp b/src/qprojectM-pulseaudio/QPulseAudioThread.hpp index f85c68581..136454d87 100644 --- a/src/qprojectM-pulseaudio/QPulseAudioThread.hpp +++ b/src/qprojectM-pulseaudio/QPulseAudioThread.hpp @@ -6,7 +6,8 @@ #include #include #include - +#include +// extern "C" { #include @@ -14,7 +15,7 @@ extern "C" #include } -class projectM; +class QProjectM; class QPulseAudioThread : public QThread @@ -23,7 +24,7 @@ class QPulseAudioThread : public QThread public: typedef QHash SourceContainer; QPulseAudioThread () {} - QPulseAudioThread(int _argc, char **_argv, projectM * projectM, QObject *parent); + QPulseAudioThread(int _argc, char **_argv, QProjectM * projectM, QObject *parent); virtual ~QPulseAudioThread(); void run(); void cleanup(); @@ -38,9 +39,10 @@ class QPulseAudioThread : public QThread } public slots: - inline void projectM_New(projectM * projectM) { + inline void projectM_New(QProjectM * projectM) { m_projectM = projectM; - cork(); + qDebug() << "CORKING"; + cork(); } void cork(); @@ -55,6 +57,8 @@ class QPulseAudioThread : public QThread void deviceChanged(); private: + QProjectM * m_projectM; +// static SourceContainer::const_iterator readSettings(); static void reconnect(SourceContainer::const_iterator pos); @@ -83,8 +87,26 @@ class QPulseAudioThread : public QThread static SourceContainer s_sourceList; static SourceContainer::const_iterator s_sourcePosition; int argc; - char ** argv; - projectM * m_projectM; + char ** argv; + static pa_context *context; + static pa_stream *stream; + static pa_mainloop_api *mainloop_api; + static pa_time_event *time_event; + static float * buffer; + static size_t buffer_length, buffer_index; + static pa_threaded_mainloop * mainloop; + static pa_io_event * stdio_event; + static char * server; + static char * stream_name, *client_name, *device; + static int verbose; + + static pa_volume_t volume; + + static pa_channel_map channel_map; + static int channel_map_set;; + static pa_sample_spec sample_spec ; + + }; #endif diff --git a/src/qprojectM-pulseaudio/qprojectM-pulseaudio.cpp b/src/qprojectM-pulseaudio/qprojectM-pulseaudio.cpp index f46aba87a..a29003d05 100644 --- a/src/qprojectM-pulseaudio/qprojectM-pulseaudio.cpp +++ b/src/qprojectM-pulseaudio/qprojectM-pulseaudio.cpp @@ -103,23 +103,22 @@ int main ( int argc, char*argv[] ) QPulseAudioThread * pulseThread = new QPulseAudioThread(argc, argv, mainWindow->getQProjectM(), mainWindow); - // First projectM_Initialized() has already happened, so manually start + // First projectM_Initialized() has already happened, so manually start pulseThread->start(); QApplication::connect - (mainWindow->getQProjectMWidget(), SIGNAL(projectM_Initialized(projectM *)), pulseThread, SLOT(projectM_New(projectM*))); - + (mainWindow->getQProjectMWidget(), SIGNAL(projectM_Initialized(QProjectM *)), pulseThread, SLOT(projectM_New(QProjectM*))); QApplication::connect (mainWindow->getQProjectMWidget(), SIGNAL(projectM_BeforeDestroy()), pulseThread, SLOT(cork())); - QPulseAudioDeviceChooser devChooser(pulseThread, mainWindow); + QPulseAudioDeviceChooser devChooser(pulseThread, mainWindow); QApplication::connect(&pulseAction, SIGNAL(triggered()), &devChooser, SLOT(open())); - int ret = app.exec(); devChooser.writeSettings(); - mainWindow->unregisterSettingsAction(&pulseAction); + if (mainWindow) + mainWindow->unregisterSettingsAction(&pulseAction); /// @bug this blows up the program! //delete(mainWindow); diff --git a/src/qprojectM/QPlaylistFileDialog.hpp b/src/qprojectM/QPlaylistFileDialog.hpp index ae47853b9..91497bedf 100644 --- a/src/qprojectM/QPlaylistFileDialog.hpp +++ b/src/qprojectM/QPlaylistFileDialog.hpp @@ -30,9 +30,9 @@ public: QPlaylistFileDialog(QWidget * parent = 0): - QFileDialog(parent, "Open a new preset playlist", QString(), "Preset Playlists (*.ppl)" ) { + QFileDialog(parent, "Open a playlist file or directory", QString(), "Preset Playlists (*.ppl)" ) { - this->setFileMode(QFileDialog::ExistingFile); + this->setFileMode(QFileDialog::ExistingFiles); } ~QPlaylistFileDialog() { } diff --git a/src/qprojectM/QProjectMConfigDialog.cpp b/src/qprojectM/QProjectMConfigDialog.cpp index f5cec6277..c78310c02 100644 --- a/src/qprojectM/QProjectMConfigDialog.cpp +++ b/src/qprojectM/QProjectMConfigDialog.cpp @@ -2,16 +2,16 @@ #include #include #include "QPlaylistFileDialog.hpp" +#include - -QProjectMConfigDialog::QProjectMConfigDialog(const std::string & configFile, QProjectMWidget * qprojectMWidget, QWidget * parent, Qt::WindowFlags f) : QDialog(parent, f), _configFile(configFile), _qprojectMWidget(qprojectMWidget) { +QProjectMConfigDialog::QProjectMConfigDialog(const std::string & configFile, QProjectMWidget * qprojectMWidget, QWidget * parent, Qt::WindowFlags f) : QDialog(parent, f), _configFile(configFile), _qprojectMWidget(qprojectMWidget), _settings("projectM", "qprojectM") { _ui.setupUi(this); connect(_ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonBoxHandler(QAbstractButton*))); connect(this, SIGNAL(projectM_Reset()), _qprojectMWidget, SLOT(resetProjectM())); connect (_ui.startupPlaylistToolButton, SIGNAL(clicked()), this, SLOT(openPlaylistFileDialog())); - connect (_ui.titleFontPathToolButton, SIGNAL(clicked()), this, SLOT(openFontFileDialog())); - connect (_ui.menuFontPathToolButton, SIGNAL(clicked()), this, SLOT(openFontFileDialog())); + connect (_ui.titleFontPathToolButton, SIGNAL(clicked()), this, SLOT(openTitleFontFileDialog())); + connect (_ui.menuFontPathToolButton, SIGNAL(clicked()), this, SLOT(openMenuFontFileDialog())); loadConfig(); } @@ -47,7 +47,32 @@ void QProjectMConfigDialog::openPlaylistFileDialog() { } -void QProjectMConfigDialog::openFontFileDialog() { +void QProjectMConfigDialog::openMenuFontFileDialog() { + + + QFileDialog dialog(this, "Select a menu font", _settings.value("Menu Font Directory", QString()).toString(), "True Type Fonts (*.ttf)" ); + dialog.setFileMode(QFileDialog::ExistingFile); + + + if (dialog.exec()) { + assert(!dialog.selectedFiles().empty()); + _ui.menuFontPathLineEdit->setText(dialog.selectedFiles()[0]); + + _settings.setValue("Menu Font Directory", dialog.directory().absolutePath()); + } + + +} + +void QProjectMConfigDialog::openTitleFontFileDialog() { + QFileDialog dialog(this, "Select a title font", _settings.value("Title Font Directory", QString()).toString(), "True Type Fonts (*.ttf)" ); + dialog.setFileMode(QFileDialog::ExistingFile); + + if (dialog.exec()) { + assert(!dialog.selectedFiles().empty()); + _ui.titleFontPathLineEdit->setText(dialog.selectedFiles()[0]); + _settings.setValue("Title Font Directory", dialog.directory().absolutePath()); + } } @@ -69,9 +94,13 @@ void QProjectMConfigDialog::saveConfig() { settings.fps = _ui.maxFPSSpinBox->value(); settings.aspectCorrection = _ui.useAspectCorrectionCheckBox->checkState() == Qt::Checked; settings.beatSensitivity = _ui.beatSensitivitySpinBox->value(); - + settings.easterEgg = _ui.easterEggParameterSpinBox->value(); projectM::writeConfig(_configFile, settings); + QSettings qSettings("projectM", "qprojectM"); + + qSettings.setValue("FullscreenOnStartup", _ui.fullscreenOnStartupCheckBox->checkState() == Qt::Checked); + qSettings.setValue("MenuOnStartup", _ui.menuOnStartupCheckBox->checkState() == Qt::Checked); qDebug() << "save end"; } @@ -87,8 +116,8 @@ void QProjectMConfigDialog::populateTextureSizeComboBox() { void QProjectMConfigDialog::loadConfig() { - qDebug() << "load config"; - const projectM::Settings & settings =(* _qprojectMWidget->getQProjectM()).settings(); + qDebug() << "load config BEGIN"; + const projectM::Settings & settings = (* _qprojectMWidget->getQProjectM()).settings(); _ui.meshSizeWidthSpinBox->setValue(settings.meshX); _ui.meshSizeHeightSpinBox->setValue(settings.meshY); @@ -109,7 +138,7 @@ void QProjectMConfigDialog::loadConfig() { _ui.smoothPresetDurationSpinBox->setValue(settings.smoothPresetDuration); _ui.presetDurationSpinBox->setValue(settings.presetDuration); - + _ui.easterEggParameterSpinBox->setValue(settings.easterEgg); qDebug() << "load config END"; } diff --git a/src/qprojectM/QProjectMConfigDialog.hpp b/src/qprojectM/QProjectMConfigDialog.hpp index ea54e1f42..6ca642941 100644 --- a/src/qprojectM/QProjectMConfigDialog.hpp +++ b/src/qprojectM/QProjectMConfigDialog.hpp @@ -2,7 +2,7 @@ #define QPROJECTM_CONFIG_DIALOG_HPP #include "ui_QProjectMConfigDialog.h" #include "QProjectM_MainWindow.hpp" - +#include class QProjectMConfigDialog : public QDialog { Q_OBJECT @@ -13,11 +13,13 @@ class QProjectMConfigDialog : public QDialog { void loadConfig(); private slots: void openPlaylistFileDialog(); - void openFontFileDialog(); + void openMenuFontFileDialog(); + void openTitleFontFileDialog(); void saveConfig(); void buttonBoxHandler(QAbstractButton * button); private: + QSettings _settings; const std::string _configFile; QProjectMWidget * _qprojectMWidget; Ui::QProjectMConfigDialog _ui; diff --git a/src/qprojectM/QProjectMConfigDialog.ui b/src/qprojectM/QProjectMConfigDialog.ui index 1147458a2..f4b829d31 100644 --- a/src/qprojectM/QProjectMConfigDialog.ui +++ b/src/qprojectM/QProjectMConfigDialog.ui @@ -618,7 +618,7 @@ p, li { white-space: pre-wrap; } Easter Egg Parameter - + 374 @@ -634,7 +634,7 @@ p, li { white-space: pre-wrap; } <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">A mystery parameter!</p></body></html> - 1.000000000000000 + 20.000000000000000 0.010000000000000 diff --git a/src/qprojectM/QProjectM_MainWindow.cpp b/src/qprojectM/QProjectM_MainWindow.cpp index aee3af5c2..150fb7a5e 100644 --- a/src/qprojectM/QProjectM_MainWindow.cpp +++ b/src/qprojectM/QProjectM_MainWindow.cpp @@ -71,7 +71,8 @@ class PlaylistWriteFunctor { }; QProjectM_MainWindow::QProjectM_MainWindow ( const std::string & config_file ) - :m_QPresetFileDialog ( new QPresetFileDialog ( this ) ), m_QPlaylistFileDialog ( new QPlaylistFileDialog ( this ) ), oldPresetIndex ( -1 ), playlistModel(0), configDialog(0) + :m_QPresetFileDialog ( new QPresetFileDialog ( this ) ), m_QPlaylistFileDialog ( new QPlaylistFileDialog ( this ) ), + oldPresetIndex ( -1 ), playlistModel(0), configDialog(0), _menuVisible(true) { @@ -89,14 +90,14 @@ QProjectM_MainWindow::QProjectM_MainWindow ( const std::string & config_file ) connect ( ui->clearPresetList_PushButton, SIGNAL ( pressed() ), this, SLOT ( clearPlaylist() ) ); - connect ( m_QProjectMWidget, SIGNAL ( projectM_Initialized(projectM*) ), this, SLOT ( postProjectM_Initialize() ) ); + connect ( m_QProjectMWidget, SIGNAL ( projectM_Initialized(QProjectM*) ), this, SLOT ( postProjectM_Initialize() ) ); m_QProjectMWidget->makeCurrent(); m_QProjectMWidget->setFocus(); m_timer->start ( 0 ); - readConfig(config_file); + //readConfig(config_file); setCentralWidget ( m_QProjectMWidget ); createActions(); createMenus(); @@ -123,17 +124,19 @@ void QProjectM_MainWindow::writeConfig() { void QProjectM_MainWindow::readConfig(const std::string & configFile ) { + QSettings settings ( "projectM", "qprojectM" ); - ConfigFile config ( configFile ); - - - if ( config.read ( "Fullscreen", false ) ) + if ( settings.value("FullscreenOnStartup", false).toBool() ) this->setWindowState ( this->windowState() | Qt::WindowFullScreen ); else this->setWindowState ( this->windowState() & ~Qt::WindowFullScreen ); - int wvw = config.read ( "Window Width", 512 ); - int wvh = config.read ( "Window Height", 512 ); + setMenuVisible(settings.value("MenuOnStartup", false).toBool()); + + ConfigFile config ( configFile ); + + int wvw = config.read ( "Window Width", 1024 ); + int wvh = config.read ( "Window Height", 768 ); // Suggest to the widget the projectM window size configuration settings m_QProjectMWidget->setBaseSize ( wvw, wvh ); @@ -206,6 +209,7 @@ void QProjectM_MainWindow::selectPlaylistItem ( const QModelIndex & index ) void QProjectM_MainWindow::postProjectM_Initialize() { + qDebug() << "QProjectM_MainWindow::postProjectM_Initialize()"; ui->tableView->setModel(0); if (playlistModel) @@ -214,15 +218,17 @@ void QProjectM_MainWindow::postProjectM_Initialize() playlistModel = new QPlaylistModel ( *m_QProjectMWidget->getQProjectM(),this ); ui->tableView->setModel ( playlistModel ); - static int FOOBAR = 0; - if (FOOBAR == 0) + /// @bug only do this at startup? refreshPlaylist(); - FOOBAR++; - if (!configDialog) + if (!configDialog) { configDialog = new QProjectMConfigDialog(m_QProjectMWidget->configFile(), m_QProjectMWidget, this); + + } + + readConfig(m_QProjectMWidget->configFile()); connect ( m_QProjectMWidget->getQProjectM(), SIGNAL ( presetSwitchedSignal ( bool,unsigned int ) ), this, SLOT ( updatePlaylistSelection ( bool,unsigned int ) ) ); @@ -241,8 +247,27 @@ void QProjectM_MainWindow::postProjectM_Initialize() } -void QProjectM_MainWindow::changeRating ( const QModelIndex & index ) -{ +void QProjectM_MainWindow::setMenuVisible(bool visible) { + + + + if (visible) { + ui->presetPlayListDockWidget->show(); + menuBar()->show(); + statusBar()->show(); + //m_QProjectMWidget->setFocus(); + _menuVisible = true; + } else { + ui->presetPlayListDockWidget->hide(); + menuBar()->hide(); + statusBar()->hide(); + _menuVisible = false; + } + +} + +void QProjectM_MainWindow::changeRating ( const QModelIndex & index ) { + if ( index.column() == 0 ) return; @@ -294,32 +319,7 @@ void QProjectM_MainWindow::keyReleaseEvent ( QKeyEvent * e ) case Qt::Key_M: if ( ui->presetSearchBarLineEdit->hasFocus() ) return; - - if ( ui->presetPlayListDockWidget->isVisible() ) - { - ui->presetPlayListDockWidget->hide(); - } - else - ui->presetPlayListDockWidget->show(); - - if ( menuBar()->isVisible() ) - { - menuBar()->hide(); - m_QProjectMWidget->setFocus(); - } - else - { - menuBar()->show(); - } - - if ( statusBar()->isVisible() ) - { - statusBar()->hide(); - } - else - { - statusBar()->show(); - } + setMenuVisible(!_menuVisible); return; case Qt::Key_R: @@ -562,9 +562,13 @@ void QProjectM_MainWindow::createStatusBar() void QProjectM_MainWindow::readSettings() { - QSettings settings ( "projectM", "QProjectM" ); + + // The settings exclusively due to qprojectM + QSettings settings ( "projectM", "qprojectM" ); QPoint pos = settings.value ( "pos", QPoint ( 200, 200 ) ).toPoint(); - QSize size = settings.value ( "size", QSize ( 1000, 600 ) ).toSize(); + QSize size = settings.value ( "size", QSize ( 1024, 768 ) ).toSize(); + + // Load up where the playlist file dialog last was visited last time m_QPlaylistFileDialog->setDirectory ( settings.value ( "playlistPath", m_QPlaylistFileDialog->directory().absolutePath() ).toString() ); @@ -574,14 +578,12 @@ void QProjectM_MainWindow::readSettings() void QProjectM_MainWindow::writeSettings() { - QSettings settings ( "projectM", "QProjectM" ); + QSettings settings ( "projectM", "qprojectM" ); settings.setValue ( "pos", pos() ); settings.setValue ( "size", size() ); settings.setValue ( "playlistPath", m_QPlaylistFileDialog->directory().absolutePath() ); } - - void QProjectM_MainWindow::loadFile ( const QString &fileName, int rating ) { diff --git a/src/qprojectM/QProjectM_MainWindow.hpp b/src/qprojectM/QProjectM_MainWindow.hpp index 94f4a69e8..bfb28ca7e 100644 --- a/src/qprojectM/QProjectM_MainWindow.hpp +++ b/src/qprojectM/QProjectM_MainWindow.hpp @@ -29,6 +29,7 @@ #include #include #include +#include #include "projectM.hpp" @@ -80,8 +81,7 @@ class QProjectMWidget : public QGLWidget QProjectM * getQProjectM() { return m_projectM; } private: - void destroyProjectM() { - + void destroyProjectM() { emit(projectM_BeforeDestroy()); if (m_projectM) { @@ -89,26 +89,40 @@ class QProjectMWidget : public QGLWidget m_projectM = 0; } } + public slots: void resetProjectM() { + + qDebug() << "reset start"; + // First wait for audio thread to stop by + // waiting on it's mutex +// s_audioMutex.tryLock(20000); + + // Now destroy the projectM instance destroyProjectM(); + + // Make a new projectM instance and reset the opengl state initializeGL(); + + // Allow audio thread to continue its business +// _audioMutex.unlock(); + qDebug() << "reinit'ed"; } - + void setPresetLock(int state) { m_projectM->setPresetLock((bool)state); - presetLockChanged((bool)state); + emit(presetLockChanged((bool)state)); } signals: void projectM_BeforeDestroy(); - void projectM_Initialized(projectM *); + void projectM_Initialized(QProjectM *); void presetLockChanged(bool isLocked); private: std::string config_file; QProjectM * m_projectM; - + QMutex _audioMutex; protected: @@ -159,14 +173,15 @@ void keyReleaseEvent ( QKeyEvent * e ) { void initializeGL() { + + this->m_projectM = new QProjectM(config_file); projectM_Initialized(m_projectM); } void resizeGL(int w, int h) { - // setup viewport, projection etc.: - /// @bug is setup necessary on resize or should just be in initializeGL() ? + // Setup viewport, projection etc setup_opengl(w,h); m_projectM->projectM_resetGL( w, h ); } @@ -180,7 +195,7 @@ void keyReleaseEvent ( QKeyEvent * e ) { void setup_opengl( int w, int h ) { - + /* Our shading model--Gouraud (smooth). */ glShadeModel( GL_SMOOTH); /* Culling. */ @@ -201,12 +216,12 @@ void keyReleaseEvent ( QKeyEvent * e ) { // gluOrtho2D(0.0, (GLfloat) width, 0.0, (GLfloat) height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - - // glFrustum(0.0, height, 0.0,width,10,40); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); + + // glFrustum(0.0, height, 0.0,width,10,40); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); -glDrawBuffer(GL_BACK); + glDrawBuffer(GL_BACK); glReadBuffer(GL_BACK); glEnable(GL_BLEND); @@ -248,6 +263,7 @@ public: virtual ~QProjectM_MainWindow(); void registerSettingsAction(QAction * action); void unregisterSettingsAction(QAction * action); + void setMenuVisible(bool visible); void keyReleaseEvent ( QKeyEvent * e ); QProjectM * getQProjectM(); @@ -287,11 +303,12 @@ private slots: QString m_currentPlaylistFile; QPlaylistModel * playlistModel; - Ui::QProjectM_MainWindow * ui; + Ui::QProjectM_MainWindow * ui; QProjectMConfigDialog * configDialog; QHash historyHash; + bool _menuVisible; int oldPresetIndex; QTimer * m_timer;