Skip to content

Commit

Permalink
Move Zyn GUI to main thread (LMMS#4065)
Browse files Browse the repository at this point in the history
  • Loading branch information
tresf authored Dec 22, 2017
1 parent 2ce5b1e commit 5b1b76a
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions plugins/zynaddsubfx/RemoteZynAddSubFx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,11 @@ class RemoteZynAddSubFx : public RemotePluginClient, public LocalZynAddSubFx
waitForMessage( IdInitDone );

pthread_mutex_init( &m_guiMutex, NULL );
pthread_create( &m_guiThreadHandle, NULL, guiThread, this );
pthread_create( &m_messageThreadHandle, NULL, messageLoop, this );
}

virtual ~RemoteZynAddSubFx()
{
m_guiExit = true;
#ifdef LMMS_BUILD_WIN32
Sleep( m_guiSleepTime * 2 );
#else
usleep( m_guiSleepTime * 2 * 1000 );
#endif

Nio::stop();
}

Expand All @@ -87,7 +80,7 @@ class RemoteZynAddSubFx : public RemotePluginClient, public LocalZynAddSubFx
LocalZynAddSubFx::setBufferSize( bufferSize() );
}

void run()
void messageLoop()
{
message m;
while( ( m = receiveMessage() ).id != IdQuit )
Expand All @@ -96,6 +89,7 @@ class RemoteZynAddSubFx : public RemotePluginClient, public LocalZynAddSubFx
processMessage( m );
pthread_mutex_unlock( &m_master->mutex );
}
m_guiExit = true;
}

virtual bool processMessage( const message & _m )
Expand Down Expand Up @@ -151,23 +145,22 @@ class RemoteZynAddSubFx : public RemotePluginClient, public LocalZynAddSubFx
LocalZynAddSubFx::processAudio( _out );
}

static void * guiThread( void * _arg )
static void * messageLoop( void * _arg )
{
RemoteZynAddSubFx * _this =
static_cast<RemoteZynAddSubFx *>( _arg );

_this->guiThread();
_this->messageLoop();

return NULL;
}

void guiLoop();

private:
void guiThread();

const int m_guiSleepTime;

pthread_t m_guiThreadHandle;
pthread_t m_messageThreadHandle;
pthread_mutex_t m_guiMutex;
std::queue<RemotePluginClient::message> m_guiMessages;
bool m_guiExit;
Expand All @@ -177,7 +170,7 @@ class RemoteZynAddSubFx : public RemotePluginClient, public LocalZynAddSubFx



void RemoteZynAddSubFx::guiThread()
void RemoteZynAddSubFx::guiLoop()
{
int exitProgram = 0;
MasterUI * ui = NULL;
Expand Down Expand Up @@ -292,7 +285,7 @@ int main( int _argc, char * * _argv )
RemoteZynAddSubFx * remoteZASF = new RemoteZynAddSubFx( _argv[1] );
#endif

remoteZASF->run();
remoteZASF->guiLoop();

delete remoteZASF;

Expand Down

0 comments on commit 5b1b76a

Please sign in to comment.