From 5ad617edc0741e913cc290aa7ff7ed3b4bd42ed4 Mon Sep 17 00:00:00 2001 From: reuk Date: Mon, 17 Oct 2022 19:53:44 +0100 Subject: [PATCH] LV2 Host: By default, search in lib64 directories on multilib systems when host is 64-bit --- .../format_types/LV2_SDK/juce_lv2_config.h | 2 +- .../format_types/juce_LV2PluginFormat.cpp | 44 ++++++++++++++++--- .../juce_core/files/juce_FileSearchPath.cpp | 9 +++- modules/juce_core/files/juce_FileSearchPath.h | 3 ++ 4 files changed, 50 insertions(+), 8 deletions(-) diff --git a/modules/juce_audio_processors/format_types/LV2_SDK/juce_lv2_config.h b/modules/juce_audio_processors/format_types/LV2_SDK/juce_lv2_config.h index 8f2260d063..07ce919af1 100644 --- a/modules/juce_audio_processors/format_types/LV2_SDK/juce_lv2_config.h +++ b/modules/juce_audio_processors/format_types/LV2_SDK/juce_lv2_config.h @@ -67,7 +67,7 @@ #define LILV_DEFAULT_LV2_PATH \ "%APPDATA%\\LV2" LILV_PATH_SEP \ "%COMMONPROGRAMFILES%\\LV2" - #elif JUCE_LINUX || JUCE_ANDROID + #elif JUCE_LINUX || JUCE_BSD || JUCE_ANDROID #define LILV_DEFAULT_LV2_PATH \ "~/.lv2" LILV_PATH_SEP \ "/usr/lib/lv2" LILV_PATH_SEP \ diff --git a/modules/juce_audio_processors/format_types/juce_LV2PluginFormat.cpp b/modules/juce_audio_processors/format_types/juce_LV2PluginFormat.cpp index 374c5bc141..933bad1d35 100644 --- a/modules/juce_audio_processors/format_types/juce_LV2PluginFormat.cpp +++ b/modules/juce_audio_processors/format_types/juce_LV2PluginFormat.cpp @@ -1841,7 +1841,12 @@ class World public: World() : world (lilv_world_new()) {} - void loadAll() { lilv_world_load_all (world.get()); } + void loadAllFromPaths (const NodeString& paths) + { + lilv_world_set_option (world.get(), LILV_OPTION_LV2_PATH, paths.get()); + lilv_world_load_all (world.get()); + } + void loadBundle (const NodeUri& uri) { lilv_world_load_bundle (world.get(), uri.get()); } void unloadBundle (const NodeUri& uri) { lilv_world_unload_bundle (world.get(), uri.get()); } @@ -5189,7 +5194,7 @@ class LV2PluginFormat::Pimpl public: Pimpl() { - world->loadAll(); + loadAllPluginsFromPaths (getDefaultLocationsToSearch()); const auto tempFile = lv2ResourceFolder.getFile(); @@ -5252,9 +5257,9 @@ public: return findPluginByUri (description.fileOrIdentifier) != nullptr; } - StringArray searchPathsForPlugins (const FileSearchPath&, bool, bool) + StringArray searchPathsForPlugins (const FileSearchPath& paths, bool, bool) { - world->loadAll(); + loadAllPluginsFromPaths (paths); StringArray result; @@ -5264,7 +5269,30 @@ public: return result; } - FileSearchPath getDefaultLocationsToSearch() { return {}; } + FileSearchPath getDefaultLocationsToSearch() + { + #if JUCE_MAC + return { "~/Library/Audio/Plug-Ins/LV2;" + "~/.lv2;" + "/usr/local/lib/lv2;" + "/usr/lib/lv2;" + "/Library/Audio/Plug-Ins/LV2;" }; + #elif JUCE_WINDOWS + return { "%APPDATA%\\LV2;" + "%COMMONPROGRAMFILES%\\LV2" }; + #else + #if JUCE_64BIT + if (File ("/usr/lib64/lv2").exists() || File ("/usr/local/lib64/lv2").exists()) + return { "~/.lv2;" + "/usr/lib64/lv2;" + "/usr/local/lib64/lv2" }; + #endif + + return { "~/.lv2;" + "/usr/lib/lv2;" + "/usr/local/lib/lv2" }; + #endif + } const LilvUI* findEmbeddableUi (const lv2_host::Uis* pluginUis, std::true_type) { @@ -5457,6 +5485,12 @@ public: } private: + void loadAllPluginsFromPaths (const FileSearchPath& path) + { + const auto joined = path.toStringWithSeparator (LILV_PATH_SEP); + world->loadAllFromPaths (world->newString (joined.toRawUTF8())); + } + struct Free { void operator() (char* ptr) const noexcept { free (ptr); } }; using StringPtr = std::unique_ptr; diff --git a/modules/juce_core/files/juce_FileSearchPath.cpp b/modules/juce_core/files/juce_FileSearchPath.cpp index 1cd0af2e1a..6b4ad3981b 100644 --- a/modules/juce_core/files/juce_FileSearchPath.cpp +++ b/modules/juce_core/files/juce_FileSearchPath.cpp @@ -67,14 +67,19 @@ File FileSearchPath::operator[] (int index) const } String FileSearchPath::toString() const +{ + return toStringWithSeparator (";"); +} + +String FileSearchPath::toStringWithSeparator (StringRef separator) const { auto dirs = directories; for (auto& d : dirs) - if (d.containsChar (';')) + if (d.contains (separator)) d = d.quoted(); - return dirs.joinIntoString (";"); + return dirs.joinIntoString (separator); } void FileSearchPath::add (const File& dir, int insertIndex) diff --git a/modules/juce_core/files/juce_FileSearchPath.h b/modules/juce_core/files/juce_FileSearchPath.h index 144419d0ad..8b48162ba5 100644 --- a/modules/juce_core/files/juce_FileSearchPath.h +++ b/modules/juce_core/files/juce_FileSearchPath.h @@ -78,6 +78,9 @@ public: /** Returns the search path as a semicolon-separated list of directories. */ String toString() const; + /** Returns the search paths, joined with the provided separator. */ + String toStringWithSeparator (StringRef separator) const; + //============================================================================== /** Adds a new directory to the search path.