Tweaks for proper plugin resource usage

Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
falkTX 2021-10-21 17:10:54 +01:00
parent 588f316fd6
commit 28bcac708f
No known key found for this signature in database
GPG key ID: CDBAA37ABC74FBA0
7 changed files with 82 additions and 65 deletions

View file

@ -86,13 +86,13 @@ struct Initializer {
if (asset::systemDir.empty())
{
// Make system dir point to source code location as fallback
// TODO use /usr/share if on linux? if we count on it being installed..
asset::systemDir = CARDINAL_PLUGIN_SOURCE_DIR DISTRHO_OS_SEP_STR "Rack";
// And if that fails, use install target prefix
if (! system::isDirectory(system::join(asset::systemDir, "res")))
{
asset::bundlePath = CARDINAL_PLUGIN_PREFIX "/share/Cardinal/Plugins";
asset::systemDir = CARDINAL_PLUGIN_PREFIX "/share/Cardinal/Resources";
asset::bundlePath = CARDINAL_PLUGIN_PREFIX "/share/Cardinal/PluginManifests";
asset::systemDir = CARDINAL_PLUGIN_PREFIX "/share/Cardinal";
}
}
@ -212,7 +212,8 @@ public:
context->history = new rack::history::State;
context->patch = new rack::patch::Manager;
context->patch->autosavePath = fAutosavePath;
context->patch->templatePath = CARDINAL_PLUGIN_SOURCE_DIR DISTRHO_OS_SEP_STR "template.vcv";
context->patch->templatePath = rack::system::join(rack::asset::systemDir, "template.vcv");
// context->patch->templatePath = CARDINAL_PLUGIN_SOURCE_DIR DISTRHO_OS_SEP_STR "template.vcv";
context->event = new rack::widget::EventState;
context->scene = new rack::app::Scene;

View file

@ -79,6 +79,7 @@ EXTRA_DEPENDENCIES = $(EXTRA_LIBS)
DPF_PATH = ../dpf
DPF_BUILD_DIR = ../build
DPF_TARGET_DIR = ../bin
USE_VST2_BUNDLE = true
include ../dpf/Makefile.plugins.mk
# --------------------------------------------------------------
@ -166,7 +167,7 @@ all: jack lv2 vst2 vst3 resources
# --------------------------------------------------------------
CORE_RESOURCES = $(wildcard Rack/res/*)
CORE_RESOURCES = $(subst Rack/res/,,$(wildcard Rack/res/*)) template.vcv
PLUGIN_RESOURCES += $(CORE_RESOURCES:%=../bin/Cardinal.lv2/resources/%)
ifeq ($(MACOS),true)
@ -178,6 +179,10 @@ PLUGIN_RESOURCES += $(CORE_RESOURCES:%=../bin/Cardinal.vst3/Contents/Resources/%
resources: $(PLUGIN_RESOURCES)
../bin/Cardinal.%/template.vcv: template.vcv
-@mkdir -p "$(shell dirname $@)"
ln -sf $(abspath $<) $@
../bin/Cardinal.lv2/resources/%: Rack/res/%
-@mkdir -p "$(shell dirname $@)"
ln -sf $(abspath $<) $@

View file

@ -78,29 +78,57 @@ Exception::Exception(const char* format, ...)
#include <plugin/Plugin.hpp>
namespace rack {
namespace asset {
std::string systemDir;
std::string userDir;
std::string bundlePath;
static inline std::string& trim(std::string& s) {
std::string userDir; // ignored
std::string systemDir; // points to plugin resources dir (or installed/local Rack dir)
std::string bundlePath; // points to plugin manifests dir (or empty)
// get rid of "res/" prefix
static inline std::string& trim(std::string& s)
{
if (std::strncmp(s.c_str(), "res" DISTRHO_OS_SEP_STR, 4) == 0)
s = s.substr(4, s.size()-4);
return s;
}
std::string system(std::string filename) {
return system::join(systemDir, bundlePath.empty() ? filename : trim(filename));
}
// ignored, returns the same as `system`
std::string user(std::string filename) {
return system(filename);
}
// get system resource, trimming "res/" prefix if we are loaded as a plugin bundle
std::string system(std::string filename) {
return system::join(systemDir, bundlePath.empty() ? filename : trim(filename));
}
// get plugin resource, also trims "res/" as needed
std::string plugin(plugin::Plugin* plugin, std::string filename) {
DISTRHO_SAFE_ASSERT_RETURN(plugin != nullptr, {});
return system::join(systemDir, plugin->path, bundlePath.empty() ? filename : trim(filename));
return system::join(plugin->path, bundlePath.empty() ? filename : trim(filename));
}
std::string pluginManifest(std::string dirname) {
// path to plugin manifest
std::string pluginManifest(const std::string& dirname) {
if (bundlePath.empty())
return system::join(systemDir, dirname, "plugin.json");
{
if (dirname == "Core")
return system::join(systemDir, "Core.json");
return system::join(systemDir, "..", "..", "plugins", dirname, "plugin.json");
}
return system::join(bundlePath, dirname + ".json");
}
// path to plugin files
std::string pluginPath(const std::string& dirname) {
if (bundlePath.empty())
{
if (dirname == "Core")
return systemDir;
return system::join(systemDir, "..", "..", "plugins", dirname);
}
return system::join(systemDir, dirname);
}
}
}