DPF

DISTRHO Plugin Framework
Log | Files | Refs | Submodules | README | LICENSE

commit 1da1c811c765689790c8bf4290b2f6939f8046f3
parent 1af66e49db01b5e2a5f90e85fe748c162bb83a48
Author: falkTX <falktx@falktx.com>
Date:   Thu, 21 Oct 2021 12:01:36 +0100

Start of getResourcePath utility

Signed-off-by: falkTX <falktx@falktx.com>

Diffstat:
Mdistrho/DistrhoPlugin.hpp | 1+
Mdistrho/DistrhoPluginUtils.hpp | 18++++++++++++++++++
Mdistrho/src/DistrhoPluginVST2.cpp | 2+-
Mdistrho/src/DistrhoPluginVST3.cpp | 15+++++++++++++++
Mdistrho/src/DistrhoUtils.cpp | 46+++++++++++++++++++++++++++++++++++++++++++++-
5 files changed, 80 insertions(+), 2 deletions(-)

diff --git a/distrho/DistrhoPlugin.hpp b/distrho/DistrhoPlugin.hpp @@ -841,6 +841,7 @@ public: Get the bundle path where the plugin resides. Can return null if the plugin is not available in a bundle (if it is a single binary). @see getBinaryFilename + @see getResourcePath */ const char* getBundlePath() const noexcept; diff --git a/distrho/DistrhoPluginUtils.hpp b/distrho/DistrhoPluginUtils.hpp @@ -40,6 +40,24 @@ const char* getBinaryFilename(); */ const char* getPluginFormatName() noexcept; +/** + Get the path to where resources are stored within the plugin bundle.@n + Requires a valid plugin bundle path. + + Returns a path inside the bundle where the plugin is meant to store its resources in.@n + This path varies between systems and plugin formats, like so: + + - LV2: <bundle>/resources (can be stored anywhere inside the bundle really, DPF just uses this one) + - VST2 macOS: <bundle>/Contents/Resources + - VST2 non-macOS: <bundle>/resources (see note) + + The other non-mentioned formats do not support bundles.@n + + @note For VST2 on non-macOS systems, this assumes you have your plugin inside a dedicated directory + rather than only shipping with the binary (e.g. <myplugin.vst>/myplugin.dll) +*/ +const char* getResourcePath(const char* bundlePath) noexcept; + // ----------------------------------------------------------------------------------------------------------- // Plugin helper classes diff --git a/distrho/src/DistrhoPluginVST2.cpp b/distrho/src/DistrhoPluginVST2.cpp @@ -15,7 +15,7 @@ */ #include "DistrhoPluginInternal.hpp" -#include "DistrhoPluginUtils.hpp" +#include "../DistrhoPluginUtils.hpp" #include "../extra/ScopedSafeLocale.hpp" #if DISTRHO_PLUGIN_HAS_UI && ! DISTRHO_PLUGIN_HAS_EMBED_UI diff --git a/distrho/src/DistrhoPluginVST3.cpp b/distrho/src/DistrhoPluginVST3.cpp @@ -15,6 +15,7 @@ */ #include "DistrhoPluginInternal.hpp" +#include "../DistrhoPluginUtils.hpp" #include "../extra/ScopedPointer.hpp" #if DISTRHO_PLUGIN_HAS_UI && ! DISTRHO_PLUGIN_HAS_EMBED_UI @@ -3851,6 +3852,20 @@ bool ENTRYFNNAME(void*); bool ENTRYFNNAME(void*) { + // find plugin bundle + static String bundlePath; + if (bundlePath.isEmpty()) + { + String tmpPath(getBinaryFilename()); + tmpPath.truncate(tmpPath.rfind(DISTRHO_OS_SEP)); + tmpPath.truncate(tmpPath.rfind(DISTRHO_OS_SEP)); + DISTRHO_SAFE_ASSERT_RETURN(tmpPath.endsWith("/Contents"), true); + + tmpPath.truncate(tmpPath.rfind('/')); + bundlePath = tmpPath; + d_nextBundlePath = bundlePath.buffer(); + } + return true; } diff --git a/distrho/src/DistrhoUtils.cpp b/distrho/src/DistrhoUtils.cpp @@ -18,7 +18,7 @@ # error Wrong build configuration #endif -#include "extra/String.hpp" +#include "../extra/String.hpp" #ifndef DISTRHO_OS_WINDOWS # include <dlfcn.h> @@ -85,6 +85,50 @@ const char* getPluginFormatName() noexcept #endif } +const char* getResourcePath(const char* const bundlePath) noexcept +{ + DISTRHO_SAFE_ASSERT_RETURN(bundlePath != nullptr, nullptr); + +#if defined(DISTRHO_PLUGIN_TARGET_LV2) + static String bundlePathLV2; + + if (bundlePathLV2.isEmpty()) + { + bundlePathLV2 += bundlePath; + bundlePathLV2 += DISTRHO_OS_SEP_STR "resources"; + } + + return bundlePathLV2.buffer(); +#elif defined(DISTRHO_PLUGIN_TARGET_VST2) + static String bundlePathVST2; + + if (bundlePathVST2.isEmpty()) + { + bundlePathVST2 += bundlePath; +# ifdef DISTRHO_OS_MAC + bundlePathVST2 += "/Contents/Resources"; +# else + DISTRHO_SAFE_ASSERT_RETURN(bundlePathVST2.endsWith(".vst"), nullptr); + bundlePathVST2 += DISTRHO_OS_SEP_STR "resources"; +# endif + } + + return bundlePathVST2.buffer(); +#elif defined(DISTRHO_PLUGIN_TARGET_VST3) + static String bundlePathVST3; + + if (bundlePathVST3.isEmpty()) + { + bundlePathVST3 += bundlePath; + bundlePathVST3 += "/Contents/Resources"; + } + + return bundlePathVST3.buffer(); +#endif + + return nullptr; +} + // ----------------------------------------------------------------------- END_NAMESPACE_DISTRHO