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.
This commit is contained in:
Tobias Doerffel
2010-07-25 15:16:57 +02:00
parent 5c2c356ba4
commit fe7486750b
5 changed files with 106 additions and 52 deletions

View File

@@ -134,10 +134,20 @@ public:
LocalZynAddSubFx::processAudio( _out );
}
static void * guiThread( void * _arg );
static void * guiThread( void * _arg )
{
RemoteZynAddSubFx * _this =
static_cast<RemoteZynAddSubFx *>( _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<RemoteZynAddSubFx *>( _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;
}

View File

@@ -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<ZynAddSubFxInstrument>();
model->m_hasGUI = m_toggleUIButton->isChecked();
model->reloadPlugin();
if( model->m_remotePlugin )
{
connect( model->m_remotePlugin, SIGNAL( clickedCloseButton() ),
m_toggleUIButton, SLOT( toggle() ) );
}
}

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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
} {