diff --git a/source/backend/plugin/CarlaPluginVST2.cpp b/source/backend/plugin/CarlaPluginVST2.cpp index bb529ab57..c9a18bc01 100644 --- a/source/backend/plugin/CarlaPluginVST2.cpp +++ b/source/backend/plugin/CarlaPluginVST2.cpp @@ -73,6 +73,7 @@ public: fIsInitializing(true), fIsProcessing(false), fChangingValuesThread(kNullThread), + fIdleThread(kNullThread), fMainThread(pthread_self()), fProcThread(kNullThread), #ifdef CARLA_OS_MAC @@ -555,7 +556,10 @@ public: void idle() override { if (fNeedIdle) + { + const ScopedValueSetter svs(fIdleThread, pthread_self(), kNullThread); dispatcher(effIdle); + } CarlaPlugin::idle(); } @@ -1866,8 +1870,13 @@ protected: const pthread_t thisThread = pthread_self(); + if (pthread_equal(thisThread, kNullThread)) + { + carla_stderr("audioMasterAutomate called with null thread!?"); + setParameterValue(uindex, fixedValue, false, true, true); + } // Called from plugin process thread, nasty! (likely MIDI learn) - /**/ if (pthread_equal(thisThread, fProcThread)) + else if (pthread_equal(thisThread, fProcThread)) { CARLA_SAFE_ASSERT(fIsProcessing); pData->postponeRtEvent(kPluginPostRtEventParameterChange, index, 0, fixedValue); @@ -1875,21 +1884,26 @@ protected: // Called from effSetChunk or effSetProgram else if (pthread_equal(thisThread, fChangingValuesThread)) { + carla_debug("audioMasterAutomate called while setting state"); pData->postponeRtEvent(kPluginPostRtEventParameterChange, index, 0, fixedValue); } - // Called from UI + // Called from effIdle + else if (pthread_equal(thisThread, fIdleThread)) + { + carla_debug("audioMasterAutomate called from idle thread"); + pData->postponeRtEvent(kPluginPostRtEventParameterChange, index, 0, fixedValue); + } + // Called from UI? else if (fUI.isVisible) { + carla_debug("audioMasterAutomate called while UI visible"); CarlaPlugin::setParameterValue(uindex, fixedValue, false, true, true); } // Unknown - // TODO - check if plugin or UI is initializing else { carla_stdout("audioMasterAutomate called from unknown source"); - - setParameterValue(uindex, fixedValue, true, true, true); - //pData->postponeRtEvent(kPluginPostRtEventParameterChange, index, 0, fixedValue); + setParameterValue(uindex, fixedValue, false, true, true); } break; } @@ -2448,6 +2462,7 @@ private: bool fIsInitializing; bool fIsProcessing; pthread_t fChangingValuesThread; + pthread_t fIdleThread; pthread_t fMainThread; pthread_t fProcThread;