| @@ -612,23 +612,6 @@ public: | |||
| */ | |||
| void setMidiProgramById(const uint32_t bank, const uint32_t program, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept; | |||
| // ------------------------------------------------------------------- | |||
| // Set gui stuff | |||
| /*! | |||
| * Idle function. | |||
| * | |||
| * @note This function must be always called from the main thread. | |||
| */ | |||
| virtual void idle(); | |||
| /*! | |||
| * Show (or hide) the plugin's custom UI according to @a yesNo. | |||
| * | |||
| * @note This function must be always called from the main thread. | |||
| */ | |||
| virtual void showCustomUI(const bool yesNo); | |||
| // ------------------------------------------------------------------- | |||
| // Plugin state | |||
| @@ -677,12 +660,14 @@ public: | |||
| */ | |||
| virtual void offlineModeChanged(const bool isOffline); | |||
| #if 0 | |||
| // ------------------------------------------------------------------- | |||
| // Misc | |||
| /*! | |||
| * Lock the plugin's master mutex. | |||
| * Idle function (non-UI), called at regular intervals. | |||
| * This function is called from the main thread only if PLUGIN_USES_SINGLE_THREAD is set. | |||
| */ | |||
| void lock(); | |||
| #endif | |||
| virtual void idle(); | |||
| /*! | |||
| * Try to lock the plugin's master mutex. | |||
| @@ -749,12 +734,25 @@ public: | |||
| /*! | |||
| * Process all the post-poned events. | |||
| * This function must be called from the main thread (ie, idle()) if PLUGIN_USES_SINGLE_THREAD is set. | |||
| * This function is called from the main thread if PLUGIN_USES_SINGLE_THREAD is set. | |||
| */ | |||
| void postRtEventsRun(); | |||
| // ------------------------------------------------------------------- | |||
| // Post-poned UI Stuff | |||
| // UI Stuff | |||
| /*! | |||
| * Show (or hide) the plugin's custom UI according to @a yesNo. | |||
| * This function is always called from the main thread. | |||
| */ | |||
| virtual void showCustomUI(const bool yesNo); | |||
| /*! | |||
| * UI idle function, called at regular intervals. | |||
| * This function is called from the main thread only if PLUGIN_USES_SINGLE_THREAD is set. | |||
| * @note This function may sometimes be called even if the UI is not visible yet. | |||
| */ | |||
| virtual void uiIdle(); | |||
| /*! | |||
| * Tell the UI a parameter has changed. | |||
| @@ -292,9 +292,21 @@ void CarlaEngine::idle() noexcept | |||
| if (plugin != nullptr && plugin->isEnabled()) | |||
| { | |||
| try { | |||
| plugin->idle(); | |||
| } CARLA_SAFE_EXCEPTION_CONTINUE("Plugin idle"); | |||
| const uint hints(plugin->getHints()); | |||
| if (hints & PLUGIN_NEEDS_SINGLE_THREAD) | |||
| { | |||
| try { | |||
| plugin->idle(); | |||
| } CARLA_SAFE_EXCEPTION_CONTINUE("Plugin idle"); | |||
| if (hints & PLUGIN_HAS_CUSTOM_UI) | |||
| { | |||
| try { | |||
| plugin->uiIdle(); | |||
| } CARLA_SAFE_EXCEPTION_CONTINUE("Plugin uiIdle"); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -76,8 +76,8 @@ void CarlaEngineThread::run() noexcept | |||
| if (! needsSingleThread) | |||
| { | |||
| try { | |||
| plugin->postRtEventsRun(); | |||
| } CARLA_SAFE_EXCEPTION("postRtEventsRun()") | |||
| plugin->idle(); | |||
| } CARLA_SAFE_EXCEPTION("idle()") | |||
| } | |||
| if (oscRegisted || needsUiUpdates) | |||
| @@ -101,6 +101,13 @@ void CarlaEngineThread::run() noexcept | |||
| if (needsUiUpdates) | |||
| plugin->uiParameterChange(j, value); | |||
| } | |||
| if (needsUiUpdates) | |||
| { | |||
| try { | |||
| plugin->uiIdle(); | |||
| } CARLA_SAFE_EXCEPTION("uiIdle()") | |||
| } | |||
| } | |||
| #ifndef BUILD_BRIDGE | |||
| @@ -1323,48 +1323,6 @@ void CarlaPlugin::setMidiProgramById(const uint32_t bank, const uint32_t program | |||
| } | |||
| } | |||
| // ------------------------------------------------------------------- | |||
| // Set ui stuff | |||
| void CarlaPlugin::idle() | |||
| { | |||
| if (! pData->enabled) | |||
| return; | |||
| if (pData->hints & PLUGIN_NEEDS_SINGLE_THREAD) | |||
| { | |||
| // Process postponed events | |||
| postRtEventsRun(); | |||
| // Update parameter outputs | |||
| for (uint32_t i=0; i < pData->param.count; ++i) | |||
| { | |||
| if (pData->param.data[i].type == PARAMETER_OUTPUT) | |||
| uiParameterChange(i, getParameterValue(i)); | |||
| } | |||
| } | |||
| if (pData->transientTryCounter == 0) | |||
| return; | |||
| if (++pData->transientTryCounter % 10 != 0) | |||
| return; | |||
| if (pData->transientTryCounter >= 200) | |||
| return; | |||
| carla_stdout("Trying to get window..."); | |||
| CarlaString uiTitle(pData->name); | |||
| uiTitle += " (GUI)"; | |||
| if (CarlaPluginUI::tryTransientWinIdMatch(getUiBridgeProcessId(), uiTitle, pData->engine->getOptions().frontendWinId, true)) | |||
| pData->transientTryCounter = 0; | |||
| } | |||
| void CarlaPlugin::showCustomUI(const bool) | |||
| { | |||
| CARLA_SAFE_ASSERT(false); | |||
| } | |||
| // ------------------------------------------------------------------- | |||
| // Plugin state | |||
| @@ -1397,6 +1355,17 @@ void CarlaPlugin::offlineModeChanged(const bool) | |||
| { | |||
| } | |||
| // ------------------------------------------------------------------- | |||
| // Misc | |||
| void CarlaPlugin::idle() | |||
| { | |||
| if (! pData->enabled) | |||
| return; | |||
| postRtEventsRun(); | |||
| } | |||
| bool CarlaPlugin::tryLock(const bool forcedOffline) noexcept | |||
| { | |||
| if (forcedOffline) | |||
| @@ -1760,7 +1729,37 @@ void CarlaPlugin::postRtEventsRun() | |||
| } | |||
| // ------------------------------------------------------------------- | |||
| // Post-poned UI Stuff | |||
| // UI Stuff | |||
| void CarlaPlugin::showCustomUI(const bool) | |||
| { | |||
| CARLA_SAFE_ASSERT(false); | |||
| } | |||
| void CarlaPlugin::uiIdle() | |||
| { | |||
| // Update parameter outputs if needed | |||
| for (uint32_t i=0; i < pData->param.count; ++i) | |||
| { | |||
| if (pData->param.data[i].type == PARAMETER_OUTPUT) | |||
| uiParameterChange(i, getParameterValue(i)); | |||
| } | |||
| if (pData->transientTryCounter == 0) | |||
| return; | |||
| if (++pData->transientTryCounter % 10 != 0) | |||
| return; | |||
| if (pData->transientTryCounter >= 200) | |||
| return; | |||
| carla_stdout("Trying to get window..."); | |||
| CarlaString uiTitle(pData->name); | |||
| uiTitle += " (GUI)"; | |||
| if (CarlaPluginUI::tryTransientWinIdMatch(getUiBridgeProcessId(), uiTitle, pData->engine->getOptions().frontendWinId, true)) | |||
| pData->transientTryCounter = 0; | |||
| } | |||
| void CarlaPlugin::uiParameterChange(const uint32_t index, const float value) noexcept | |||
| { | |||
| @@ -321,7 +321,7 @@ public: | |||
| } | |||
| } | |||
| void idle() override | |||
| void uiIdle() override | |||
| { | |||
| if (fWindow != nullptr) | |||
| { | |||
| @@ -332,7 +332,7 @@ public: | |||
| } | |||
| } | |||
| CarlaPlugin::idle(); | |||
| CarlaPlugin::uiIdle(); | |||
| } | |||
| // ------------------------------------------------------------------- | |||
| @@ -399,7 +399,7 @@ public: | |||
| } | |||
| // ------------------------------------------------------------------- | |||
| // Set ui stuff | |||
| // Misc | |||
| void idle() override | |||
| { | |||
| @@ -1416,6 +1416,38 @@ public: | |||
| } | |||
| void idle() override | |||
| { | |||
| if (fLatencyChanged && fLatencyIndex != -1) | |||
| { | |||
| fLatencyChanged = false; | |||
| const int32_t latency(static_cast<int32_t>(fParamBuffers[fLatencyIndex])); | |||
| if (latency >= 0) | |||
| { | |||
| const uint32_t ulatency(static_cast<uint32_t>(latency)); | |||
| if (pData->latency != ulatency) | |||
| { | |||
| carla_stdout("latency changed to %i", latency); | |||
| const ScopedSingleProcessLocker sspl(this, true); | |||
| pData->latency = ulatency; | |||
| pData->client->setLatency(ulatency); | |||
| #ifndef BUILD_BRIDGE | |||
| pData->recreateLatencyBuffers(); | |||
| #endif | |||
| } | |||
| } | |||
| else | |||
| carla_safe_assert_int("latency >= 0", __FILE__, __LINE__, latency); | |||
| } | |||
| CarlaPlugin::idle(); | |||
| } | |||
| void uiIdle() override | |||
| { | |||
| if (fAtomBufferOut.isDataAvailableForReading()) | |||
| { | |||
| @@ -1448,33 +1480,6 @@ public: | |||
| } | |||
| } | |||
| if (fLatencyChanged && fLatencyIndex != -1) | |||
| { | |||
| fLatencyChanged = false; | |||
| const int32_t latency(static_cast<int32_t>(fParamBuffers[fLatencyIndex])); | |||
| if (latency >= 0) | |||
| { | |||
| const uint32_t ulatency(static_cast<uint32_t>(latency)); | |||
| if (pData->latency != ulatency) | |||
| { | |||
| carla_stdout("latency changed to %i", latency); | |||
| const ScopedSingleProcessLocker sspl(this, true); | |||
| pData->latency = ulatency; | |||
| pData->client->setLatency(ulatency); | |||
| #ifndef BUILD_BRIDGE | |||
| pData->recreateLatencyBuffers(); | |||
| #endif | |||
| } | |||
| } | |||
| else | |||
| carla_safe_assert_int("latency >= 0", __FILE__, __LINE__, latency); | |||
| } | |||
| if (fPipeServer.isPipeRunning()) | |||
| { | |||
| fPipeServer.idlePipe(); | |||
| @@ -1515,7 +1520,7 @@ public: | |||
| #endif | |||
| } | |||
| CarlaPlugin::idle(); | |||
| CarlaPlugin::uiIdle(); | |||
| } | |||
| // ------------------------------------------------------------------- | |||
| @@ -777,10 +777,18 @@ public: | |||
| if (fDescriptor->idle != nullptr && (fDescriptor->hints & ::NATIVE_PLUGIN_NEEDS_DSP_IDLE) != 0) | |||
| fDescriptor->idle(fHandle); | |||
| CarlaPlugin::idle(); | |||
| } | |||
| void uiIdle() override | |||
| { | |||
| CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); | |||
| CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr,); | |||
| if (fIsUiVisible && fDescriptor->ui_idle != nullptr) | |||
| fDescriptor->ui_idle(fHandle); | |||
| CarlaPlugin::idle(); | |||
| CarlaPlugin::uiIdle(); | |||
| } | |||
| // ------------------------------------------------------------------- | |||
| @@ -484,9 +484,6 @@ public: | |||
| void idle() override | |||
| { | |||
| if (fNeedIdle) | |||
| dispatcher(effIdle, 0, 0, nullptr, 0.0f); | |||
| if (fUI.window != nullptr) | |||
| { | |||
| fUI.window->idle(); | |||
| @@ -498,6 +495,19 @@ public: | |||
| CarlaPlugin::idle(); | |||
| } | |||
| void uiIdle() override | |||
| { | |||
| if (fUI.window != nullptr) | |||
| { | |||
| fUI.window->idle(); | |||
| if (fUI.isVisible) | |||
| dispatcher(effEditIdle, 0, 0, nullptr, 0.0f); | |||
| } | |||
| CarlaPlugin::uiIdle(); | |||
| } | |||
| // ------------------------------------------------------------------- | |||
| // Plugin state | |||