@@ -249,6 +249,26 @@ class RemoteVstPlugin : public RemotePluginClient
249
249
pthread_mutex_unlock ( &m_pluginLock );
250
250
}
251
251
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
+
252
272
inline bool isProcessing () const
253
273
{
254
274
return m_processing;
@@ -347,6 +367,9 @@ class RemoteVstPlugin : public RemotePluginClient
347
367
float * * m_inputs;
348
368
float * * m_outputs;
349
369
370
+ pthread_mutex_t m_shmLock;
371
+ bool m_shmValid;
372
+
350
373
typedef std::vector<VstMidiEvent> VstMidiEventList;
351
374
VstMidiEventList m_midiEvents;
352
375
@@ -392,6 +415,8 @@ RemoteVstPlugin::RemoteVstPlugin( const char * socketPath ) :
392
415
m_shouldGiveIdle( false ),
393
416
m_inputs( NULL ),
394
417
m_outputs( NULL ),
418
+ m_shmLock(),
419
+ m_shmValid( false ),
395
420
m_midiEvents(),
396
421
m_bpm( 0 ),
397
422
m_currentSamplePos( 0 ),
@@ -402,6 +427,7 @@ RemoteVstPlugin::RemoteVstPlugin( const char * socketPath ) :
402
427
403
428
{
404
429
pthread_mutex_init ( &m_pluginLock, NULL );
430
+ pthread_mutex_init ( &m_shmLock, NULL );
405
431
406
432
__plugin = this ;
407
433
@@ -500,6 +526,7 @@ RemoteVstPlugin::~RemoteVstPlugin()
500
526
delete[] m_inputs;
501
527
delete[] m_outputs;
502
528
529
+ pthread_mutex_destroy ( &m_shmLock );
503
530
pthread_mutex_destroy ( &m_pluginLock );
504
531
}
505
532
@@ -836,6 +863,16 @@ void RemoteVstPlugin::process( const sampleFrame * _in, sampleFrame * _out )
836
863
837
864
// now we're ready to fetch sound from VST-plugin
838
865
866
+ lock ();
867
+ lockShm ();
868
+
869
+ if ( !isShmValid () )
870
+ {
871
+ unlockShm ();
872
+ unlock ();
873
+ return ;
874
+ }
875
+
839
876
for ( int i = 0 ; i < inputCount (); ++i )
840
877
{
841
878
m_inputs[i] = &((float *) _in)[i * bufferSize ()];
@@ -847,8 +884,6 @@ void RemoteVstPlugin::process( const sampleFrame * _in, sampleFrame * _out )
847
884
memset ( m_outputs[i], 0 , bufferSize () * sizeof ( float ) );
848
885
}
849
886
850
- lock ();
851
-
852
887
#ifdef OLD_VST_SDK
853
888
if ( m_plugin->flags & effFlagsCanReplacing )
854
889
{
@@ -864,6 +899,7 @@ void RemoteVstPlugin::process( const sampleFrame * _in, sampleFrame * _out )
864
899
}
865
900
#endif
866
901
902
+ unlockShm ();
867
903
unlock ();
868
904
869
905
m_currentSamplePos += bufferSize ();
@@ -1380,14 +1416,19 @@ void RemoteVstPlugin::loadChunkFromFile( const std::string & _file, int _len )
1380
1416
1381
1417
void RemoteVstPlugin::updateInOutCount ()
1382
1418
{
1419
+ lockShm ();
1420
+
1421
+ setShmIsValid ( false );
1422
+
1423
+ unlockShm ();
1424
+
1383
1425
delete[] m_inputs;
1384
1426
delete[] m_outputs;
1385
1427
1386
1428
m_inputs = NULL ;
1387
1429
m_outputs = NULL ;
1388
1430
1389
- setInputCount ( inputCount () );
1390
- setOutputCount ( outputCount () );
1431
+ setInputOutputCount ( inputCount (), outputCount () );
1391
1432
1392
1433
char buf[64 ];
1393
1434
sprintf ( buf, " inputs: %d output: %d\n " , inputCount (), outputCount () );
@@ -1842,6 +1883,11 @@ DWORD WINAPI RemoteVstPlugin::processingThread( LPVOID _param )
1842
1883
{
1843
1884
_this->processMessage ( m );
1844
1885
}
1886
+ else if ( m.id == IdChangeSharedMemoryKey )
1887
+ {
1888
+ _this->processMessage ( m );
1889
+ _this->setShmIsValid ( true );
1890
+ }
1845
1891
else
1846
1892
{
1847
1893
PostMessage ( __MessageHwnd,
0 commit comments