Use Runner instead of Thread for AudioFile and Ildaeil modules
Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
parent
be26b6f61c
commit
7af9041635
3 changed files with 126 additions and 93 deletions
2
dpf
2
dpf
|
|
@ -1 +1 @@
|
||||||
Subproject commit 717c7596c29530998fc8522d000c9e856618a56b
|
Subproject commit 614eeaf0ef0390d4956feb991e9038980cf50371
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
#include "plugincontext.hpp"
|
#include "plugincontext.hpp"
|
||||||
#include "ModuleWidgets.hpp"
|
#include "ModuleWidgets.hpp"
|
||||||
#include "extra/Thread.hpp"
|
#include "extra/Runner.hpp"
|
||||||
|
|
||||||
#include "CarlaNativePlugin.h"
|
#include "CarlaNativePlugin.h"
|
||||||
|
|
||||||
|
|
@ -58,7 +58,7 @@ static void host_ui_closed(NativeHostHandle) {}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
struct CarlaInternalPluginModule : Module, Thread {
|
struct CarlaInternalPluginModule : Module, Runner {
|
||||||
enum ParamIds {
|
enum ParamIds {
|
||||||
NUM_PARAMS
|
NUM_PARAMS
|
||||||
};
|
};
|
||||||
|
|
@ -168,7 +168,7 @@ struct CarlaInternalPluginModule : Module, Thread {
|
||||||
// host-sync disabled by default
|
// host-sync disabled by default
|
||||||
fCarlaPluginDescriptor->set_parameter_value(fCarlaPluginHandle, kParameterHostSync, 0.0f);
|
fCarlaPluginDescriptor->set_parameter_value(fCarlaPluginHandle, kParameterHostSync, 0.0f);
|
||||||
|
|
||||||
startThread();
|
startRunner(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
~CarlaInternalPluginModule() override
|
~CarlaInternalPluginModule() override
|
||||||
|
|
@ -176,18 +176,15 @@ struct CarlaInternalPluginModule : Module, Thread {
|
||||||
if (fCarlaPluginHandle == nullptr)
|
if (fCarlaPluginHandle == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
stopThread(-1);
|
stopRunner();
|
||||||
fCarlaPluginDescriptor->deactivate(fCarlaPluginHandle);
|
fCarlaPluginDescriptor->deactivate(fCarlaPluginHandle);
|
||||||
fCarlaPluginDescriptor->cleanup(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
|
const NativeTimeInfo* hostGetTimeInfo() const noexcept
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,9 @@
|
||||||
# include "ImGuiWidget.hpp"
|
# include "ImGuiWidget.hpp"
|
||||||
# include "ModuleWidgets.hpp"
|
# include "ModuleWidgets.hpp"
|
||||||
# include "extra/FileBrowserDialog.hpp"
|
# include "extra/FileBrowserDialog.hpp"
|
||||||
|
# include "extra/Mutex.hpp"
|
||||||
|
# include "extra/Runner.hpp"
|
||||||
# include "extra/ScopedPointer.hpp"
|
# include "extra/ScopedPointer.hpp"
|
||||||
# include "extra/Thread.hpp"
|
|
||||||
# include "../../src/extra/SharedResourcePointer.hpp"
|
# include "../../src/extra/SharedResourcePointer.hpp"
|
||||||
#else
|
#else
|
||||||
# include "extra/Mutex.hpp"
|
# include "extra/Mutex.hpp"
|
||||||
|
|
@ -589,7 +590,7 @@ static intptr_t host_dispatcher(const NativeHostHandle handle, const NativeHostD
|
||||||
// --------------------------------------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef HEADLESS
|
#ifndef HEADLESS
|
||||||
struct IldaeilWidget : ImGuiWidget, IdleCallback, Thread {
|
struct IldaeilWidget : ImGuiWidget, IdleCallback, Runner {
|
||||||
static constexpr const uint kButtonHeight = 20;
|
static constexpr const uint kButtonHeight = 20;
|
||||||
|
|
||||||
struct PluginInfoCache {
|
struct PluginInfoCache {
|
||||||
|
|
@ -670,6 +671,19 @@ struct IldaeilWidget : ImGuiWidget, IdleCallback, Thread {
|
||||||
kIdleNothing
|
kIdleNothing
|
||||||
} fIdleState = kIdleInit;
|
} 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 fPluginType = PLUGIN_LV2;
|
||||||
PluginType fNextPluginType = fPluginType;
|
PluginType fNextPluginType = fPluginType;
|
||||||
uint fPluginCount = 0;
|
uint fPluginCount = 0;
|
||||||
|
|
@ -741,8 +755,7 @@ struct IldaeilWidget : ImGuiWidget, IdleCallback, Thread {
|
||||||
module->fUI = nullptr;
|
module->fUI = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isThreadRunning())
|
stopRunner();
|
||||||
stopThread(-1);
|
|
||||||
|
|
||||||
fPluginGenericUI = nullptr;
|
fPluginGenericUI = nullptr;
|
||||||
|
|
||||||
|
|
@ -1046,13 +1059,13 @@ struct IldaeilWidget : ImGuiWidget, IdleCallback, Thread {
|
||||||
{
|
{
|
||||||
case kIdleInit:
|
case kIdleInit:
|
||||||
fIdleState = kIdleNothing;
|
fIdleState = kIdleNothing;
|
||||||
startThread();
|
initAndStartRunner();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kIdleInitPluginAlreadyLoaded:
|
case kIdleInitPluginAlreadyLoaded:
|
||||||
fIdleState = kIdleNothing;
|
fIdleState = kIdleNothing;
|
||||||
createOrUpdatePluginGenericUI(handle);
|
createOrUpdatePluginGenericUI(handle);
|
||||||
startThread();
|
initAndStartRunner();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kIdlePluginLoadedFromDSP:
|
case kIdlePluginLoadedFromDSP:
|
||||||
|
|
@ -1087,10 +1100,9 @@ struct IldaeilWidget : ImGuiWidget, IdleCallback, Thread {
|
||||||
case kIdleChangePluginType:
|
case kIdleChangePluginType:
|
||||||
fIdleState = kIdleNothing;
|
fIdleState = kIdleNothing;
|
||||||
fPluginSelected = -1;
|
fPluginSelected = -1;
|
||||||
if (isThreadRunning())
|
stopRunner();
|
||||||
stopThread(-1);
|
|
||||||
fPluginType = fNextPluginType;
|
fPluginType = fNextPluginType;
|
||||||
startThread();
|
initAndStartRunner();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kIdleNothing:
|
case kIdleNothing:
|
||||||
|
|
@ -1130,8 +1142,21 @@ struct IldaeilWidget : ImGuiWidget, IdleCallback, Thread {
|
||||||
loadPlugin(handle, label);
|
loadPlugin(handle, label);
|
||||||
}
|
}
|
||||||
|
|
||||||
void run() override
|
bool initAndStartRunner()
|
||||||
{
|
{
|
||||||
|
if (isRunnerActive())
|
||||||
|
stopRunner();
|
||||||
|
|
||||||
|
fRunnerData.needsReinit = true;
|
||||||
|
return startRunner();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool run() override
|
||||||
|
{
|
||||||
|
if (fRunnerData.needsReinit)
|
||||||
|
{
|
||||||
|
fRunnerData.needsReinit = false;
|
||||||
|
|
||||||
const char* path;
|
const char* path;
|
||||||
switch (fPluginType)
|
switch (fPluginType)
|
||||||
{
|
{
|
||||||
|
|
@ -1152,14 +1177,12 @@ struct IldaeilWidget : ImGuiWidget, IdleCallback, Thread {
|
||||||
fPluginCount = 0;
|
fPluginCount = 0;
|
||||||
delete[] fPlugins;
|
delete[] fPlugins;
|
||||||
|
|
||||||
uint count;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
const MutexLocker cml(sPluginInfoLoadMutex);
|
const MutexLocker cml(sPluginInfoLoadMutex);
|
||||||
|
|
||||||
d_stdout("Will scan plugins now...");
|
d_stdout("Will scan plugins now...");
|
||||||
count = carla_get_cached_plugin_count(fPluginType, path);
|
fRunnerData.pluginCount = carla_get_cached_plugin_count(fPluginType, path);
|
||||||
d_stdout("Scanning found %u plugins", count);
|
d_stdout("Scanning found %u plugins", fRunnerData.pluginCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fDrawingState == kDrawingLoading)
|
if (fDrawingState == kDrawingLoading)
|
||||||
|
|
@ -1168,55 +1191,68 @@ struct IldaeilWidget : ImGuiWidget, IdleCallback, Thread {
|
||||||
fPluginSearchFirstShow = true;
|
fPluginSearchFirstShow = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count != 0)
|
if (fRunnerData.pluginCount != 0)
|
||||||
{
|
{
|
||||||
fPlugins = new PluginInfoCache[count];
|
fPlugins = new PluginInfoCache[fRunnerData.pluginCount];
|
||||||
|
fPluginScanningFinished = false;
|
||||||
for (uint i=0, j; i < count && ! shouldThreadExit(); ++i)
|
return true;
|
||||||
{
|
|
||||||
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;
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
j = fPluginCount;
|
|
||||||
fPlugins[j].name = strdup(info->name);
|
|
||||||
fPlugins[j].label = strdup(info->label);
|
|
||||||
++fPluginCount;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fPlugins = nullptr;
|
fPlugins = nullptr;
|
||||||
|
fPluginScanningFinished = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! shouldThreadExit())
|
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;
|
fPluginScanningFinished = true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawImGui() override
|
void drawImGui() override
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue