From 7feb4b893b6620b9d826be9cfc50b8122d00dfd0 Mon Sep 17 00:00:00 2001 From: falkTX Date: Wed, 12 Oct 2022 21:03:01 +0100 Subject: [PATCH] Allow loading arbitrary files/binaries as plugins Signed-off-by: falkTX --- carla | 2 +- dpf | 2 +- plugins/Common/IldaeilUI.cpp | 66 ++++++++++++++++++++++++++++++++---- 3 files changed, 61 insertions(+), 9 deletions(-) diff --git a/carla b/carla index 6995151..df13388 160000 --- a/carla +++ b/carla @@ -1 +1 @@ -Subproject commit 699515158062a95d2bbee246e5a19e06d4e3c2bd +Subproject commit df1338860e0b6fae36b974618ecfeb005051158b diff --git a/dpf b/dpf index 1bdbb7d..55a1e21 160000 --- a/dpf +++ b/dpf @@ -1 +1 @@ -Subproject commit 1bdbb7d9e13fc6e1f25506c127efa3cd48ec91ef +Subproject commit 55a1e21ebbb42a4778f26188a9f75aecb0c1210c diff --git a/plugins/Common/IldaeilUI.cpp b/plugins/Common/IldaeilUI.cpp index 45a5be8..37f368a 100644 --- a/plugins/Common/IldaeilUI.cpp +++ b/plugins/Common/IldaeilUI.cpp @@ -167,7 +167,7 @@ class IldaeilUI : public UI, bool fPluginSearchFirstShow; char fPluginSearchString[0xff]; - String fPopupError; + String fPopupError, fPluginFilename; Size fNextSize; struct RunnerData { @@ -533,6 +533,7 @@ public: { fPluginRunning = true; fPluginGenericUI = nullptr; + fPluginFilename.clear(); showPluginUI(handle, false); #ifdef WASM_TESTING @@ -557,6 +558,36 @@ public: repaint(); } + void loadFileAsPlugin(const CarlaHostHandle handle, const char* const filename) + { + if (fPluginRunning || fPluginId != 0) + { + hidePluginUI(handle); + carla_replace_plugin(handle, fPluginId); + } + + carla_set_engine_option(handle, ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, fPluginWillRunInBridgeMode, nullptr); + + const MutexLocker cml(fPlugin->sPluginInfoLoadMutex); + + if (carla_load_file(handle, filename)) + { + fPluginRunning = true; + fPluginGenericUI = nullptr; + fPluginFilename = filename; + showPluginUI(handle, false); + } + else + { + fPopupError = carla_get_last_error(handle); + d_stdout("got error: %s", fPopupError.buffer()); + fDrawingState = kDrawingPluginError; + fPluginFilename.clear(); + } + + repaint(); + } + protected: void pluginWindowResized(const uint width, const uint height) override { @@ -609,7 +640,10 @@ protected: case kIdleResetPlugin: fIdleState = kIdleNothing; - loadPlugin(handle, carla_get_plugin_info(handle, fPluginId)->label); + if (fPluginFilename.isNotEmpty()) + loadFileAsPlugin(handle, fPluginFilename.buffer()); + else + loadPlugin(handle, carla_get_plugin_info(handle, fPluginId)->label); break; case kIdleOpenFileUI: @@ -643,10 +677,19 @@ protected: fIdleState = kIdleNothing; if (fPluginRunning) hidePluginUI(handle); - fPluginSelected = -1; - stopRunner(); - fPluginType = fNextPluginType; - initAndStartRunner(); + if (fNextPluginType == PLUGIN_TYPE_COUNT) + { + FileBrowserOptions opts; + opts.title = "Load from file"; + openFileBrowser(opts); + } + else + { + fPluginSelected = -1; + stopRunner(); + fPluginType = fNextPluginType; + initAndStartRunner(); + } break; case kIdleNothing: @@ -689,7 +732,12 @@ protected: void uiFileBrowserSelected(const char* const filename) override { if (fPlugin != nullptr && fPlugin->fCarlaHostHandle != nullptr && filename != nullptr) - carla_set_custom_data(fPlugin->fCarlaHostHandle, fPluginId, CUSTOM_DATA_TYPE_STRING, "file", filename); + { + if (fNextPluginType == PLUGIN_TYPE_COUNT) + loadFileAsPlugin(fPlugin->fCarlaHostHandle, filename); + else + carla_set_custom_data(fPlugin->fCarlaHostHandle, fPluginId, CUSTOM_DATA_TYPE_STRING, "file", filename); + } } bool initAndStartRunner() @@ -1087,6 +1135,7 @@ protected: getPluginTypeAsString(PLUGIN_INTERNAL), getPluginTypeAsString(PLUGIN_LV2), getPluginTypeAsString(PLUGIN_JSFX), + "Load from file..." }; setupMainWindowPos(); @@ -1157,6 +1206,9 @@ protected: case 2: fNextPluginType = PLUGIN_JSFX; break; + case 3: + fNextPluginType = PLUGIN_TYPE_COUNT; + break; } }