From b88b8f13c7b1855b5d27d79e971732287e37169d Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 27 Apr 2022 12:40:06 +0100 Subject: [PATCH] LV2 Host: Supply correct bundle path during instantiation --- .../format_types/juce_LV2PluginFormat.cpp | 59 ++++++++++--------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/modules/juce_audio_processors/format_types/juce_LV2PluginFormat.cpp b/modules/juce_audio_processors/format_types/juce_LV2PluginFormat.cpp index 5f012c0a66..7f145bf4c2 100644 --- a/modules/juce_audio_processors/format_types/juce_LV2PluginFormat.cpp +++ b/modules/juce_audio_processors/format_types/juce_LV2PluginFormat.cpp @@ -30,12 +30,11 @@ namespace juce namespace lv2_host { -template -auto with (Struct&& s, Member&& member, Value&& value) noexcept +template +auto with (Struct s, Value Struct::* member, Value value) noexcept { - auto copy = std::forward (s); - copy.*member = std::forward (value); - return copy; + s.*member = std::move (value); + return s; } /* Converts a void* to an LV2_Atom* if the buffer looks like it holds a well-formed Atom, or @@ -2122,6 +2121,8 @@ private: JUCE_LEAK_DETECTOR (PortMap) }; +struct FreeString { void operator() (void* ptr) const noexcept { lilv_free (ptr); } }; + class PluginState { public: @@ -2140,7 +2141,6 @@ public: std::string toString (LilvWorld* world, LV2_URID_Map* map, LV2_URID_Unmap* unmap, const char* uri) const { - struct FreeString { void operator() (void* ptr) const noexcept { lilv_free (ptr); } }; std::unique_ptr result { lilv_state_to_string (world, map, unmap, @@ -2256,17 +2256,16 @@ struct UiDescriptorLibrary class UiDescriptorArgs { public: - const char* libraryPath = nullptr; - const char* uiUri = nullptr; + String libraryPath; + String uiUri; - auto withLibraryPath (const char* v) const noexcept { return with (&UiDescriptorArgs::libraryPath, v); } - auto withUiUri (const char* v) const noexcept { return with (&UiDescriptorArgs::uiUri, v); } + auto withLibraryPath (String v) const noexcept { return with (&UiDescriptorArgs::libraryPath, v); } + auto withUiUri (String v) const noexcept { return with (&UiDescriptorArgs::uiUri, v); } private: - template - UiDescriptorArgs with (Member&& member, const char* value) const noexcept + UiDescriptorArgs with (String UiDescriptorArgs::* member, String value) const noexcept { - return juce::lv2_host::with (*this, std::forward (member), value); + return juce::lv2_host::with (*this, member, std::move (value)); } }; @@ -2280,7 +2279,7 @@ public: explicit UiDescriptor (const UiDescriptorArgs& args) : library (args.libraryPath), - descriptor (extractUiDescriptor (library, args.uiUri)) + descriptor (extractUiDescriptor (library, args.uiUri.toRawUTF8())) {} void portEvent (LV2UI_Handle ui, @@ -2564,20 +2563,25 @@ private: class UiInstanceArgs { public: - const char* bundlePath = nullptr; - const char* pluginUri = nullptr; + File bundlePath; + URL pluginUri; - auto withBundlePath (const char* v) const noexcept { return with (&UiInstanceArgs::bundlePath, v); } - auto withPluginUri (const char* v) const noexcept { return with (&UiInstanceArgs::pluginUri, v); } + auto withBundlePath (File v) const noexcept { return with (&UiInstanceArgs::bundlePath, std::move (v)); } + auto withPluginUri (URL v) const noexcept { return with (&UiInstanceArgs::pluginUri, std::move (v)); } private: template - UiInstanceArgs with (Member&& member, const char* value) const noexcept + UiInstanceArgs with (Member UiInstanceArgs::* member, Member value) const noexcept { - return juce::lv2_host::with (*this, std::forward (member), value); + return juce::lv2_host::with (*this, member, std::move (value)); } }; +static File bundlePathFromUri (const char* uri) +{ + return File { std::unique_ptr { lilv_file_uri_parse (uri, nullptr) }.get() }; +} + /* Creates and holds a UI instance for a plugin with a specific URI, using the provided descriptor. */ @@ -2665,14 +2669,14 @@ private: using Instance = std::unique_ptr; using Idle = int (*) (LV2UI_Handle); - Instance makeInstance (const char* pluginUri, const char* bundlePath, const LV2_Feature* const* features) + Instance makeInstance (const URL& pluginUri, const File& bundlePath, const LV2_Feature* const* features) { if (descriptor->get() == nullptr) return { nullptr, [] (LV2UI_Handle) {} }; return Instance { descriptor->get()->instantiate (descriptor->get(), - pluginUri, - bundlePath, + pluginUri.toString (false).toRawUTF8(), + bundlePath.getFullPathName().toRawUTF8(), writeFunction, this, &widget, @@ -2752,10 +2756,9 @@ public: auto withSampleRate (float v) const { return with (&UiFeaturesDataOptions::sampleRate, v); } private: - template - UiFeaturesDataOptions with (Member&& member, Value&& value) const + UiFeaturesDataOptions with (float UiFeaturesDataOptions::* member, float value) const { - return juce::lv2_host::with (*this, std::forward (member), std::forward (value)); + return juce::lv2_host::with (*this, member, value); } }; @@ -3034,8 +3037,8 @@ public: *this, touchListener, &uiDescriptor, - UiInstanceArgs{}.withBundlePath (uiBundleUri.toRawUTF8()) - .withPluginUri (instance.instance.getUri()), + UiInstanceArgs{}.withBundlePath (bundlePathFromUri (uiBundleUri.toRawUTF8())) + .withPluginUri (URL (instance.instance.getUri())), viewComponent.getWidget(), instance, opts)),