@@ -249,6 +249,26 @@ class RemoteVstPlugin : public RemotePluginClient
249249 pthread_mutex_unlock ( &m_pluginLock );
250250 }
251251
252+ inline void lockShm ()
253+ {
254+ pthread_mutex_lock ( &m_shmLock );
255+ }
256+
257+ inline void unlockShm ()
258+ {
259+ pthread_mutex_unlock ( &m_shmLock );
260+ }
261+
262+ inline bool isShmValid ()
263+ {
264+ return m_shmValid;
265+ }
266+
267+ inline void setShmIsValid ( bool valid )
268+ {
269+ m_shmValid = valid;
270+ }
271+
252272 inline bool isProcessing () const
253273 {
254274 return m_processing;
@@ -347,6 +367,9 @@ class RemoteVstPlugin : public RemotePluginClient
347367 float * * m_inputs;
348368 float * * m_outputs;
349369
370+ pthread_mutex_t m_shmLock;
371+ bool m_shmValid;
372+
350373 typedef std::vector<VstMidiEvent> VstMidiEventList;
351374 VstMidiEventList m_midiEvents;
352375
@@ -392,6 +415,8 @@ RemoteVstPlugin::RemoteVstPlugin( const char * socketPath ) :
392415 m_shouldGiveIdle( false ),
393416 m_inputs( NULL ),
394417 m_outputs( NULL ),
418+ m_shmLock(),
419+ m_shmValid( false ),
395420 m_midiEvents(),
396421 m_bpm( 0 ),
397422 m_currentSamplePos( 0 ),
@@ -402,6 +427,7 @@ RemoteVstPlugin::RemoteVstPlugin( const char * socketPath ) :
402427
403428{
404429 pthread_mutex_init ( &m_pluginLock, NULL );
430+ pthread_mutex_init ( &m_shmLock, NULL );
405431
406432 __plugin = this ;
407433
@@ -500,6 +526,7 @@ RemoteVstPlugin::~RemoteVstPlugin()
500526 delete[] m_inputs;
501527 delete[] m_outputs;
502528
529+ pthread_mutex_destroy ( &m_shmLock );
503530 pthread_mutex_destroy ( &m_pluginLock );
504531}
505532
@@ -836,6 +863,16 @@ void RemoteVstPlugin::process( const sampleFrame * _in, sampleFrame * _out )
836863
837864 // now we're ready to fetch sound from VST-plugin
838865
866+ lock ();
867+ lockShm ();
868+
869+ if ( !isShmValid () )
870+ {
871+ unlockShm ();
872+ unlock ();
873+ return ;
874+ }
875+
839876 for ( int i = 0 ; i < inputCount (); ++i )
840877 {
841878 m_inputs[i] = &((float *) _in)[i * bufferSize ()];
@@ -847,8 +884,6 @@ void RemoteVstPlugin::process( const sampleFrame * _in, sampleFrame * _out )
847884 memset ( m_outputs[i], 0 , bufferSize () * sizeof ( float ) );
848885 }
849886
850- lock ();
851-
852887#ifdef OLD_VST_SDK
853888 if ( m_plugin->flags & effFlagsCanReplacing )
854889 {
@@ -864,6 +899,7 @@ void RemoteVstPlugin::process( const sampleFrame * _in, sampleFrame * _out )
864899 }
865900#endif
866901
902+ unlockShm ();
867903 unlock ();
868904
869905 m_currentSamplePos += bufferSize ();
@@ -1380,14 +1416,19 @@ void RemoteVstPlugin::loadChunkFromFile( const std::string & _file, int _len )
13801416
13811417void RemoteVstPlugin::updateInOutCount ()
13821418{
1419+ lockShm ();
1420+
1421+ setShmIsValid ( false );
1422+
1423+ unlockShm ();
1424+
13831425 delete[] m_inputs;
13841426 delete[] m_outputs;
13851427
13861428 m_inputs = NULL ;
13871429 m_outputs = NULL ;
13881430
1389- setInputCount ( inputCount () );
1390- setOutputCount ( outputCount () );
1431+ setInputOutputCount ( inputCount (), outputCount () );
13911432
13921433 char buf[64 ];
13931434 sprintf ( buf, " inputs: %d output: %d\n " , inputCount (), outputCount () );
@@ -1842,6 +1883,11 @@ DWORD WINAPI RemoteVstPlugin::processingThread( LPVOID _param )
18421883 {
18431884 _this->processMessage ( m );
18441885 }
1886+ else if ( m.id == IdChangeSharedMemoryKey )
1887+ {
1888+ _this->processMessage ( m );
1889+ _this->setShmIsValid ( true );
1890+ }
18451891 else
18461892 {
18471893 PostMessage ( __MessageHwnd,
0 commit comments