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

@ -68,4 +68,20 @@ clean:
# --------------------------------------------------------------
install:
install -d $(DESTDIR)$(PREFIX)/bin
install -d $(DESTDIR)$(PREFIX)/lib/lv2
install -d $(DESTDIR)$(PREFIX)/lib/vst
install -d $(DESTDIR)$(PREFIX)/lib/vst3
install -d $(DESTDIR)$(PREFIX)/share/Cardinal
cp -rL bin/Cardinal.lv2 $(DESTDIR)$(PREFIX)/lib/lv2/
cp -rL bin/Cardinal.vst $(DESTDIR)$(PREFIX)/lib/vst/
cp -rL bin/Cardinal.vst3 $(DESTDIR)$(PREFIX)/lib/vst3/
install -m 755 bin/Cardinal$(APP_EXT) $(DESTDIR)$(PREFIX)/bin/
cp -rL bin/Cardinal.lv2/resources/* $(DESTDIR)$(PREFIX)/share/Cardinal/
# --------------------------------------------------------------
.PHONY: deps plugins

2
dpf

@ -1 +1 @@
Subproject commit 1da1c811c765689790c8bf4290b2f6939f8046f3
Subproject commit a88514b734f01bf4eed68e6e2097712ff01a60fe

View file

@ -234,13 +234,6 @@ PLUGIN_FILES += $(filter-out rackwindows/src/plugin.cpp,$(wildcard rackwindows/s
PLUGIN_FILES += $(filter-out ZetaCarinaeModules/src/plugin.cpp,$(wildcard ZetaCarinaeModules/src/*.cpp))
# --------------------------------------------------------------
# Resources to symlink
# TODO
# PLUGIN_RESOURCES = res/Befaco/res
# PLUGIN_RESOURCES = res/Befaco/res
# --------------------------------------------------------------
# Build setup
@ -296,17 +289,6 @@ BASE_FLAGS += -Wno-unused-variable
# also lots of plugins not updated to v2 yet
BASE_FLAGS += -Wno-deprecated-declarations
# --------------------------------------------------------------
# temporary macro just to get the ball rolling
ifeq ($(EXE_WRAPPER),wine)
PLUGINS_DIR = Z:$(subst /,\\,$(CURDIR))
else
PLUGINS_DIR = $(CURDIR)
endif
BUILD_CXX_FLAGS += -DCARDINAL_PLUGINS_DIR='"$(PLUGINS_DIR)"'
# --------------------------------------------------------------
# Build targets
@ -321,20 +303,28 @@ clean:
# --------------------------------------------------------------
PLUGIN_LIST = $(subst /plugin.json,,$(wildcard */plugin.json))
PLUGIN_RESOURCES = ../bin/Cardinal.lv2/resources/PluginManifests/Core.json
PLUGIN_RESOURCES += $(PLUGIN_LIST:%=../bin/Cardinal.lv2/resources/%)
PLUGIN_RESOURCES += $(PLUGIN_LIST:%=../bin/Cardinal.lv2/resources/PluginManifests/%.json)
ifeq ($(MACOS),true)
PLUGIN_RESOURCES += ../bin/Cardinal.vst/Contents/Resources/PluginManifests/Core.json
PLUGIN_RESOURCES += $(PLUGIN_LIST:%=../bin/Cardinal.vst/Contents/Resources/%)
PLUGIN_RESOURCES += $(PLUGIN_LIST:%=../bin/Cardinal.vst/Contents/Resources/PluginManifests/%.json)
else
PLUGIN_RESOURCES += ../bin/Cardinal.vst/resources/PluginManifests/Core.json
PLUGIN_RESOURCES += $(PLUGIN_LIST:%=../bin/Cardinal.vst/resources/%)
PLUGIN_RESOURCES += $(PLUGIN_LIST:%=../bin/Cardinal.vst/resources/PluginManifests/%.json)
endif
PLUGIN_RESOURCES += ../bin/Cardinal.vst3/Contents/Resources/PluginManifests/Core.json
PLUGIN_RESOURCES += $(PLUGIN_LIST:%=../bin/Cardinal.vst3/Contents/Resources/%)
PLUGIN_RESOURCES += $(PLUGIN_LIST:%=../bin/Cardinal.vst3/Contents/Resources/PluginManifests/%.json)
resources: $(PLUGIN_RESOURCES)
../bin/Cardinal.%/Core.json: Core.json
-@mkdir -p "$(shell dirname $@)"
ln -sf $(abspath $<) $@
../bin/Cardinal.lv2/resources/%: %/res
-@mkdir -p "$(shell dirname $@)"
ln -sf $(abspath $<) $@

View file

@ -256,6 +256,11 @@ Plugin* pluginInstance__ZetaCarinaeModules;
namespace rack {
namespace asset {
std::string pluginManifest(const std::string& dirname);
std::string pluginPath(const std::string& dirname);
}
// core plugins
namespace core {
extern Model* modelAudioInterface;
@ -280,42 +285,14 @@ struct StaticPluginLoader {
FILE* file;
json_t* rootJ;
// core
StaticPluginLoader(Plugin* const p)
: plugin(p),
file(nullptr),
rootJ(nullptr)
{
p->path = system::join(CARDINAL_PLUGINS_DIR, "Core.json");
if ((file = std::fopen(p->path.c_str(), "r")) == nullptr)
{
d_stderr2("Manifest file %s does not exist", p->path.c_str());
return;
}
json_error_t error;
if ((rootJ = json_loadf(file, 0, &error)) == nullptr)
{
d_stderr2("JSON parsing error at %s %d:%d %s", p->path.c_str(), error.line, error.column, error.text);
return;
}
// force ABI, we use static plugins so this doesnt matter as long as it builds
json_t* const version = json_string((APP_VERSION_MAJOR + ".0").c_str());
json_object_set(rootJ, "version", version);
json_decref(version);
}
// regular plugins
StaticPluginLoader(Plugin* const p, const char* const name)
: plugin(p),
file(nullptr),
rootJ(nullptr)
{
p->path = system::join(CARDINAL_PLUGINS_DIR, name);
p->path = asset::pluginPath(name);
const std::string manifestFilename = system::join(p->path, "plugin.json");
const std::string manifestFilename = asset::pluginManifest(name);
if ((file = std::fopen(manifestFilename.c_str(), "r")) == nullptr)
{
@ -359,7 +336,7 @@ static void initStatic__Core()
{
Plugin* const p = new Plugin;
const StaticPluginLoader spl(p);
const StaticPluginLoader spl(p, "Core");
if (spl.ok())
{
p->addModel(rack::core::modelAudioInterface);

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