From fe7486750b959a1910c0aaa7ad1a6fb6af8342cd Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Sun, 25 Jul 2010 15:16:57 +0200 Subject: [PATCH] ZynAddSubFX: allow hiding UI by closing main window It's now possible to hide the ZynAddSubFX UI by simply closing its main window instead of going back to LMMS and toggle the "Show UI" button. Furthermore moved code for GUI thread into a non-static member function of RemoteZynAddSubFx and removed the old code for handling IdHideUI messages. --- plugins/zynaddsubfx/RemoteZynAddSubFx.cpp | 81 +++++++++++------------ plugins/zynaddsubfx/ZynAddSubFx.cpp | 41 +++++++++++- plugins/zynaddsubfx/ZynAddSubFx.h | 20 +++++- plugins/zynaddsubfx/src/UI/MasterUI.cc | 8 +-- plugins/zynaddsubfx/src/UI/MasterUI.fl | 8 +-- 5 files changed, 106 insertions(+), 52 deletions(-) diff --git a/plugins/zynaddsubfx/RemoteZynAddSubFx.cpp b/plugins/zynaddsubfx/RemoteZynAddSubFx.cpp index 19402847f..5e4b2c34b 100644 --- a/plugins/zynaddsubfx/RemoteZynAddSubFx.cpp +++ b/plugins/zynaddsubfx/RemoteZynAddSubFx.cpp @@ -134,10 +134,20 @@ public: LocalZynAddSubFx::processAudio( _out ); } - static void * guiThread( void * _arg ); + static void * guiThread( void * _arg ) + { + RemoteZynAddSubFx * _this = + static_cast( _arg ); + + _this->guiThread(); + + return NULL; + } private: + void guiThread(); + const int m_guiSleepTime; pthread_t m_guiThreadHandle; @@ -149,33 +159,38 @@ private: -void * RemoteZynAddSubFx::guiThread( void * _arg ) + +void RemoteZynAddSubFx::guiThread() { - int e; + int exitProgram; MasterUI * ui = NULL; - RemoteZynAddSubFx * _this = static_cast( _arg ); - Master * master = _this->m_master; - - while( !_this->m_guiExit ) + while( !m_guiExit ) { if( ui ) { - Fl::wait( _this->m_guiSleepTime / 1000.0 ); + Fl::wait( m_guiSleepTime / 1000.0 ); } else { #ifdef LMMS_BUILD_WIN32 - Sleep( _this->m_guiSleepTime ); + Sleep( m_guiSleepTime ); #else - usleep( _this->m_guiSleepTime*1000 ); + usleep( m_guiSleepTime*1000 ); #endif } - pthread_mutex_lock( &_this->m_guiMutex ); - while( _this->m_guiMessages.size() ) + if( exitProgram == 1 ) { - RemotePluginClient::message m = _this->m_guiMessages.front(); - _this->m_guiMessages.pop(); + pthread_mutex_lock( &m_master->mutex ); + sendMessage( IdHideUI ); + exitProgram = 0; + pthread_mutex_unlock( &m_master->mutex ); + } + pthread_mutex_lock( &m_guiMutex ); + while( m_guiMessages.size() ) + { + RemotePluginClient::message m = m_guiMessages.front(); + m_guiMessages.pop(); switch( m.id ) { case IdShowUI: @@ -183,44 +198,28 @@ void * RemoteZynAddSubFx::guiThread( void * _arg ) if( !ui ) { Fl::scheme( "plastic" ); - ui = new MasterUI( master, &e ); + ui = new MasterUI( m_master, &exitProgram ); } ui->showUI(); ui->refresh_master_ui(); break; - case IdHideUI: - if( !ui ) break; - switch( config.cfg.UserInterfaceMode ) - { - case 0: - ui->selectuiwindow->hide(); - break; - case 1: - ui->masterwindow->hide(); - break; - case 2: - ui->simplemasterwindow->hide(); - break; - } - break; - case IdLoadSettingsFromFile: { - _this->LocalZynAddSubFx::loadXML( m.getString() ); + LocalZynAddSubFx::loadXML( m.getString() ); if( ui ) { ui->refresh_master_ui(); } - pthread_mutex_lock( &master->mutex ); - _this->sendMessage( IdLoadSettingsFromFile ); - pthread_mutex_unlock( &master->mutex ); + pthread_mutex_lock( &m_master->mutex ); + sendMessage( IdLoadSettingsFromFile ); + pthread_mutex_unlock( &m_master->mutex ); break; } case IdLoadPresetFromFile: { - _this->LocalZynAddSubFx::loadPreset( m.getString(), ui ? + LocalZynAddSubFx::loadPreset( m.getString(), ui ? ui->npartcounter->value()-1 : 0 ); if( ui ) { @@ -228,9 +227,9 @@ void * RemoteZynAddSubFx::guiThread( void * _arg ) ui->updatepanel(); ui->refresh_master_ui(); } - pthread_mutex_lock( &master->mutex ); - _this->sendMessage( IdLoadPresetFromFile ); - pthread_mutex_unlock( &master->mutex ); + pthread_mutex_lock( &m_master->mutex ); + sendMessage( IdLoadPresetFromFile ); + pthread_mutex_unlock( &m_master->mutex ); break; } @@ -238,13 +237,11 @@ void * RemoteZynAddSubFx::guiThread( void * _arg ) break; } } - pthread_mutex_unlock( &_this->m_guiMutex ); + pthread_mutex_unlock( &m_guiMutex ); } Fl::flush(); delete ui; - - return NULL; } diff --git a/plugins/zynaddsubfx/ZynAddSubFx.cpp b/plugins/zynaddsubfx/ZynAddSubFx.cpp index 72e769e9f..671d26c25 100644 --- a/plugins/zynaddsubfx/ZynAddSubFx.cpp +++ b/plugins/zynaddsubfx/ZynAddSubFx.cpp @@ -69,6 +69,39 @@ Plugin::Descriptor PLUGIN_EXPORT zynaddsubfx_plugin_descriptor = +ZynAddSubFxRemotePlugin::ZynAddSubFxRemotePlugin() : + QObject(), + RemotePlugin( "RemoteZynAddSubFx", false ) +{ +} + + + + +ZynAddSubFxRemotePlugin::~ZynAddSubFxRemotePlugin() +{ +} + + + +bool ZynAddSubFxRemotePlugin::processMessage( const message & _m ) +{ + switch( _m.id ) + { + case IdHideUI: + emit clickedCloseButton(); + return true; + default: + break; + } + + return RemotePlugin::processMessage( _m ); +} + + + + + ZynAddSubFxInstrument::ZynAddSubFxInstrument( InstrumentTrack * _instrumentTrack ) : Instrument( _instrumentTrack, &zynaddsubfx_plugin_descriptor ), @@ -285,7 +318,7 @@ void ZynAddSubFxInstrument::initPlugin() if( m_hasGUI ) { - m_remotePlugin = new RemotePlugin( "RemoteZynAddSubFx", false ); + m_remotePlugin = new ZynAddSubFxRemotePlugin(); m_remotePlugin->lock(); m_remotePlugin->waitForInitDone( false ); @@ -366,6 +399,12 @@ void ZynAddSubFxView::toggleUI() ZynAddSubFxInstrument * model = castModel(); model->m_hasGUI = m_toggleUIButton->isChecked(); model->reloadPlugin(); + + if( model->m_remotePlugin ) + { + connect( model->m_remotePlugin, SIGNAL( clickedCloseButton() ), + m_toggleUIButton, SLOT( toggle() ) ); + } } diff --git a/plugins/zynaddsubfx/ZynAddSubFx.h b/plugins/zynaddsubfx/ZynAddSubFx.h index 3f2d91549..2792f30d7 100644 --- a/plugins/zynaddsubfx/ZynAddSubFx.h +++ b/plugins/zynaddsubfx/ZynAddSubFx.h @@ -39,6 +39,24 @@ class ZynAddSubFxView; class notePlayHandle; + +class ZynAddSubFxRemotePlugin : public QObject, public RemotePlugin +{ + Q_OBJECT +public: + ZynAddSubFxRemotePlugin(); + virtual ~ZynAddSubFxRemotePlugin(); + + virtual bool processMessage( const message & _m ); + + +signals: + void clickedCloseButton(); + +} ; + + + class ZynAddSubFxInstrument : public Instrument { Q_OBJECT @@ -77,7 +95,7 @@ private: bool m_hasGUI; QMutex m_pluginMutex; LocalZynAddSubFx * m_plugin; - RemotePlugin * m_remotePlugin; + ZynAddSubFxRemotePlugin * m_remotePlugin; friend class ZynAddSubFxView; diff --git a/plugins/zynaddsubfx/src/UI/MasterUI.cc b/plugins/zynaddsubfx/src/UI/MasterUI.cc index bd8545239..75a212a45 100644 --- a/plugins/zynaddsubfx/src/UI/MasterUI.cc +++ b/plugins/zynaddsubfx/src/UI/MasterUI.cc @@ -433,10 +433,10 @@ void MasterUI::cb_masterwindow_i(Fl_Double_Window*, void*) { #ifdef VSTAUDIOOUT fl_alert("ZynAddSubFX could not be closed this way, because it's a VST plugin. Please use the host aplication to close it."); #else -if (fl_choice("Exit and leave the unsaved data?","No","Yes",NULL)) { +//if (fl_choice("Exit and leave the unsaved data?","No","Yes",NULL)) { config.save(); *exitprogram=1; -}; +//}; #endif } void MasterUI::cb_masterwindow(Fl_Double_Window* o, void* v) { @@ -996,10 +996,10 @@ void MasterUI::cb_simplemasterwindow_i(Fl_Double_Window*, void*) { #ifdef VSTAUDIOOUT fl_alert("ZynAddSubFX could not be closed this way, because it's a VST plugin. Please use the host aplication to close it."); #else -if (fl_choice("Exit and leave the unsaved data?","No","Yes",NULL)) { +//if (fl_choice("Exit and leave the unsaved data?","No","Yes",NULL)) { config.save(); *exitprogram=1; -}; +//}; #endif } void MasterUI::cb_simplemasterwindow(Fl_Double_Window* o, void* v) { diff --git a/plugins/zynaddsubfx/src/UI/MasterUI.fl b/plugins/zynaddsubfx/src/UI/MasterUI.fl index a844def6c..af8440e1e 100644 --- a/plugins/zynaddsubfx/src/UI/MasterUI.fl +++ b/plugins/zynaddsubfx/src/UI/MasterUI.fl @@ -421,10 +421,10 @@ class MasterUI {} { callback {\#ifdef VSTAUDIOOUT fl_alert("ZynAddSubFX could not be closed this way, because it's a VST plugin. Please use the host aplication to close it."); \#else -if (fl_choice("Exit and leave the unsaved data?","No","Yes",NULL)) { +//if (fl_choice("Exit and leave the unsaved data?","No","Yes",NULL)) { config.save(); *exitprogram=1; -}; +//}; \#endif} xywh {31 206 390 465} type Double hide xclass zynaddsubfx } { @@ -1076,10 +1076,10 @@ updatepanel();} callback {\#ifdef VSTAUDIOOUT fl_alert("ZynAddSubFX could not be closed this way, because it's a VST plugin. Please use the host aplication to close it."); \#else -if (fl_choice("Exit and leave the unsaved data?","No","Yes",NULL)) { +//if (fl_choice("Exit and leave the unsaved data?","No","Yes",NULL)) { config.save(); *exitprogram=1; -}; +//}; \#endif} xywh {400 405 600 335} type Double hide } {