diff --git a/dpf b/dpf index 717c759..614eeaf 160000 --- a/dpf +++ b/dpf @@ -1 +1 @@ -Subproject commit 717c7596c29530998fc8522d000c9e856618a56b +Subproject commit 614eeaf0ef0390d4956feb991e9038980cf50371 diff --git a/plugins/Cardinal/src/AudioFile.cpp b/plugins/Cardinal/src/AudioFile.cpp index 528c04a..18d51c1 100644 --- a/plugins/Cardinal/src/AudioFile.cpp +++ b/plugins/Cardinal/src/AudioFile.cpp @@ -17,7 +17,7 @@ #include "plugincontext.hpp" #include "ModuleWidgets.hpp" -#include "extra/Thread.hpp" +#include "extra/Runner.hpp" #include "CarlaNativePlugin.h" @@ -58,7 +58,7 @@ static void host_ui_closed(NativeHostHandle) {} // -------------------------------------------------------------------------------------------------------------------- -struct CarlaInternalPluginModule : Module, Thread { +struct CarlaInternalPluginModule : Module, Runner { enum ParamIds { NUM_PARAMS }; @@ -168,7 +168,7 @@ struct CarlaInternalPluginModule : Module, Thread { // host-sync disabled by default fCarlaPluginDescriptor->set_parameter_value(fCarlaPluginHandle, kParameterHostSync, 0.0f); - startThread(); + startRunner(500); } ~CarlaInternalPluginModule() override @@ -176,18 +176,15 @@ struct CarlaInternalPluginModule : Module, Thread { if (fCarlaPluginHandle == nullptr) return; - stopThread(-1); + stopRunner(); fCarlaPluginDescriptor->deactivate(fCarlaPluginHandle); fCarlaPluginDescriptor->cleanup(fCarlaPluginHandle); } - void run() override + bool run() override { - while (!shouldThreadExit()) - { - d_msleep(500); - fCarlaPluginDescriptor->dispatcher(fCarlaPluginHandle, NATIVE_PLUGIN_OPCODE_IDLE, 0, 0, nullptr, 0.0f); - } + fCarlaPluginDescriptor->dispatcher(fCarlaPluginHandle, NATIVE_PLUGIN_OPCODE_IDLE, 0, 0, nullptr, 0.0f); + return true; } const NativeTimeInfo* hostGetTimeInfo() const noexcept diff --git a/plugins/Cardinal/src/Ildaeil.cpp b/plugins/Cardinal/src/Ildaeil.cpp index 5d1b4ee..46c091e 100644 --- a/plugins/Cardinal/src/Ildaeil.cpp +++ b/plugins/Cardinal/src/Ildaeil.cpp @@ -32,8 +32,9 @@ # include "ImGuiWidget.hpp" # include "ModuleWidgets.hpp" # include "extra/FileBrowserDialog.hpp" +# include "extra/Mutex.hpp" +# include "extra/Runner.hpp" # include "extra/ScopedPointer.hpp" -# include "extra/Thread.hpp" # include "../../src/extra/SharedResourcePointer.hpp" #else # include "extra/Mutex.hpp" @@ -589,7 +590,7 @@ static intptr_t host_dispatcher(const NativeHostHandle handle, const NativeHostD // -------------------------------------------------------------------------------------------------------------------- #ifndef HEADLESS -struct IldaeilWidget : ImGuiWidget, IdleCallback, Thread { +struct IldaeilWidget : ImGuiWidget, IdleCallback, Runner { static constexpr const uint kButtonHeight = 20; struct PluginInfoCache { @@ -670,6 +671,19 @@ struct IldaeilWidget : ImGuiWidget, IdleCallback, Thread { kIdleNothing } fIdleState = kIdleInit; + struct RunnerData { + bool needsReinit = true; + uint pluginCount = 0; + uint pluginIndex = 0; + + void init() + { + needsReinit = true; + pluginCount = 0; + pluginIndex = 0; + } + } fRunnerData; + PluginType fPluginType = PLUGIN_LV2; PluginType fNextPluginType = fPluginType; uint fPluginCount = 0; @@ -741,8 +755,7 @@ struct IldaeilWidget : ImGuiWidget, IdleCallback, Thread { module->fUI = nullptr; } - if (isThreadRunning()) - stopThread(-1); + stopRunner(); fPluginGenericUI = nullptr; @@ -1046,13 +1059,13 @@ struct IldaeilWidget : ImGuiWidget, IdleCallback, Thread { { case kIdleInit: fIdleState = kIdleNothing; - startThread(); + initAndStartRunner(); break; case kIdleInitPluginAlreadyLoaded: fIdleState = kIdleNothing; createOrUpdatePluginGenericUI(handle); - startThread(); + initAndStartRunner(); break; case kIdlePluginLoadedFromDSP: @@ -1087,10 +1100,9 @@ struct IldaeilWidget : ImGuiWidget, IdleCallback, Thread { case kIdleChangePluginType: fIdleState = kIdleNothing; fPluginSelected = -1; - if (isThreadRunning()) - stopThread(-1); + stopRunner(); fPluginType = fNextPluginType; - startThread(); + initAndStartRunner(); break; case kIdleNothing: @@ -1130,93 +1142,117 @@ struct IldaeilWidget : ImGuiWidget, IdleCallback, Thread { loadPlugin(handle, label); } - void run() override + bool initAndStartRunner() { - const char* path; - switch (fPluginType) - { - case PLUGIN_LV2: - path = std::getenv("LV2_PATH"); - break; - case PLUGIN_JSFX: - path = getPathForJSFX(); - break; - default: - path = nullptr; - break; - } + if (isRunnerActive()) + stopRunner(); - if (path != nullptr) - carla_set_engine_option(module->fCarlaHostHandle, ENGINE_OPTION_PLUGIN_PATH, fPluginType, path); - - fPluginCount = 0; - delete[] fPlugins; - - uint count; + fRunnerData.needsReinit = true; + return startRunner(); + } + bool run() override + { + if (fRunnerData.needsReinit) { - const MutexLocker cml(sPluginInfoLoadMutex); + fRunnerData.needsReinit = false; - d_stdout("Will scan plugins now..."); - count = carla_get_cached_plugin_count(fPluginType, path); - d_stdout("Scanning found %u plugins", count); - } + const char* path; + switch (fPluginType) + { + case PLUGIN_LV2: + path = std::getenv("LV2_PATH"); + break; + case PLUGIN_JSFX: + path = getPathForJSFX(); + break; + default: + path = nullptr; + break; + } - if (fDrawingState == kDrawingLoading) - { - fDrawingState = kDrawingPluginList; - fPluginSearchFirstShow = true; - } + if (path != nullptr) + carla_set_engine_option(module->fCarlaHostHandle, ENGINE_OPTION_PLUGIN_PATH, fPluginType, path); - if (count != 0) - { - fPlugins = new PluginInfoCache[count]; + fPluginCount = 0; + delete[] fPlugins; - for (uint i=0, j; i < count && ! shouldThreadExit(); ++i) { const MutexLocker cml(sPluginInfoLoadMutex); - const CarlaCachedPluginInfo* const info = carla_get_cached_plugin_info(fPluginType, i); - DISTRHO_SAFE_ASSERT_CONTINUE(info != nullptr); - - if (! info->valid) - continue; - if (info->audioIns != 0 && info->audioIns != 2) - continue; - if (info->midiIns != 0 && info->midiIns != 1) - continue; - if (info->midiOuts != 0 && info->midiOuts != 1) - continue; + d_stdout("Will scan plugins now..."); + fRunnerData.pluginCount = carla_get_cached_plugin_count(fPluginType, path); + d_stdout("Scanning found %u plugins", fRunnerData.pluginCount); + } - if (fPluginType == PLUGIN_INTERNAL) - { - if (std::strcmp(info->label, "audiogain_s") == 0) - continue; - if (std::strcmp(info->label, "cv2audio") == 0) - continue; - if (std::strcmp(info->label, "lfo") == 0) - continue; - if (std::strcmp(info->label, "midi2cv") == 0) - continue; - if (std::strcmp(info->label, "midithrough") == 0) - continue; - if (std::strcmp(info->label, "3bandsplitter") == 0) - continue; - } + if (fDrawingState == kDrawingLoading) + { + fDrawingState = kDrawingPluginList; + fPluginSearchFirstShow = true; + } - j = fPluginCount; - fPlugins[j].name = strdup(info->name); - fPlugins[j].label = strdup(info->label); - ++fPluginCount; + if (fRunnerData.pluginCount != 0) + { + fPlugins = new PluginInfoCache[fRunnerData.pluginCount]; + fPluginScanningFinished = false; + return true; + } + else + { + fPlugins = nullptr; + fPluginScanningFinished = true; + return false; } } - else - { - fPlugins = nullptr; - } - if (! shouldThreadExit()) - fPluginScanningFinished = true; + const uint index = fRunnerData.pluginIndex++; + DISTRHO_SAFE_ASSERT_UINT2_RETURN(index < fRunnerData.pluginCount, + index, fRunnerData.pluginCount, false); + + do { + const MutexLocker cml(sPluginInfoLoadMutex); + + const CarlaCachedPluginInfo* const info = carla_get_cached_plugin_info(fPluginType, index); + DISTRHO_SAFE_ASSERT_CONTINUE(info != nullptr); + + if (! info->valid) + break; + if (info->audioIns != 0 && info->audioIns != 2) + break; + if (info->midiIns != 0 && info->midiIns != 1) + break; + if (info->midiOuts != 0 && info->midiOuts != 1) + break; + + if (fPluginType == PLUGIN_INTERNAL) + { + if (std::strcmp(info->label, "audiogain_s") == 0) + break; + if (std::strcmp(info->label, "cv2audio") == 0) + break; + if (std::strcmp(info->label, "lfo") == 0) + break; + if (std::strcmp(info->label, "midi2cv") == 0) + break; + if (std::strcmp(info->label, "midithrough") == 0) + break; + if (std::strcmp(info->label, "3bandsplitter") == 0) + break; + } + + const uint pindex = fPluginCount; + fPlugins[pindex].name = strdup(info->name); + fPlugins[pindex].label = strdup(info->label); + ++fPluginCount; + } while (false); + + // run again + if (fRunnerData.pluginIndex != fRunnerData.pluginCount) + return true; + + // stop here + fPluginScanningFinished = true; + return false; } void drawImGui() override