Browse Source

Start of getResourcePath utility

Signed-off-by: falkTX <falktx@falktx.com>
pull/344/head
falkTX 4 years ago
parent
commit
1da1c811c7
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
5 changed files with 80 additions and 2 deletions
  1. +1
    -0
      distrho/DistrhoPlugin.hpp
  2. +18
    -0
      distrho/DistrhoPluginUtils.hpp
  3. +1
    -1
      distrho/src/DistrhoPluginVST2.cpp
  4. +15
    -0
      distrho/src/DistrhoPluginVST3.cpp
  5. +45
    -1
      distrho/src/DistrhoUtils.cpp

+ 1
- 0
distrho/DistrhoPlugin.hpp View File

@@ -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;



+ 18
- 0
distrho/DistrhoPluginUtils.hpp View File

@@ -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



+ 1
- 1
distrho/src/DistrhoPluginVST2.cpp View File

@@ -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


+ 15
- 0
distrho/src/DistrhoPluginVST3.cpp View File

@@ -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;
}



+ 45
- 1
distrho/src/DistrhoUtils.cpp View File

@@ -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

Loading…
Cancel
Save