From 0c6746fdcee061f30ece379e675df127b4624b4c Mon Sep 17 00:00:00 2001 From: falkTX Date: Thu, 21 Oct 2021 03:10:14 +0100 Subject: [PATCH] Start of custom asset location handling, WIP --- dpf | 2 +- src/CardinalPlugin.cpp | 34 +++++++++++++++++++++++++++------- src/CardinalUI.cpp | 7 ++++++- src/Makefile | 2 +- src/dep.cpp | 28 ++++++++++++++++++++++++++++ 5 files changed, 63 insertions(+), 10 deletions(-) diff --git a/dpf b/dpf index eca8056..1af66e4 160000 --- a/dpf +++ b/dpf @@ -1 +1 @@ -Subproject commit eca8056dc29865bbcbcab0dc6494b20dd459c7ad +Subproject commit 1af66e49db01b5e2a5f90e85fe748c162bb83a48 diff --git a/src/CardinalPlugin.cpp b/src/CardinalPlugin.cpp index 8433586..689e513 100644 --- a/src/CardinalPlugin.cpp +++ b/src/CardinalPlugin.cpp @@ -31,6 +31,11 @@ #include +#ifdef NDEBUG +# undef DEBUG +#endif + +#include "DistrhoPluginUtils.hpp" #include "PluginContext.hpp" #include "WindowParameters.hpp" #include "extra/Base64.hpp" @@ -63,26 +68,41 @@ struct Initializer { settings::threadCount = 1; system::init(); - asset::init(); logger::init(); random::init(); ui::init(); - // Make system dir point to source code location. It is good enough for now - asset::systemDir = CARDINAL_PLUGIN_SOURCE_DIR DISTRHO_OS_SEP_STR "Rack"; + std::string resDir; + + if (const char* const bundlePath = plugin->getBundlePath()) + { + asset::systemDir = bundlePath; +#ifdef DISTRHO_OS_MAC + asset::systemDir += "/Contents/Resources"; +#endif + } + else + { + // 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" DISTRHO_OS_SEP_STR "res"; + } + + asset::userDir = asset::systemDir; // Log environment INFO("%s %s v%s", APP_NAME.c_str(), APP_EDITION.c_str(), APP_VERSION.c_str()); INFO("%s", system::getOperatingSystemInfo().c_str()); + INFO("Binary filename: %s", getBinaryFilename()); + INFO("Bundle path: %s", plugin->getBundlePath()); INFO("System directory: %s", asset::systemDir.c_str()); INFO("User directory: %s", asset::userDir.c_str()); // Check existence of the system res/ directory - const std::string resDir = asset::system("res"); - if (! system::isDirectory(resDir)) + if (! system::isDirectory(asset::systemDir)) { - d_stderr2("Resource directory \"%s\" does not exist.\n" - "Make sure Cardinal was downloaded and installed correctly.", resDir.c_str()); + d_stderr2("System directory \"%s\" does not exist.\n" + "Make sure Cardinal was downloaded and installed correctly.", asset::systemDir.c_str()); } INFO("Initializing audio driver"); diff --git a/src/CardinalUI.cpp b/src/CardinalUI.cpp index 76ddc40..0fc9dec 100644 --- a/src/CardinalUI.cpp +++ b/src/CardinalUI.cpp @@ -88,13 +88,18 @@ class CardinalUI : public UI, public: CardinalUI() - : UI(1280, 720), + : UI(1228, 666), fContext(getRackContextFromPlugin(getPluginInstancePointer())), fResizeHandle(this) { if (isResizable()) fResizeHandle.hide(); + const double scaleFactor = getScaleFactor(); + + if (scaleFactor != 1) + setSize(1228 * scaleFactor, 666 * scaleFactor); + fContext->window = new rack::window::Window; { diff --git a/src/Makefile b/src/Makefile index c0fd180..8acc1cb 100644 --- a/src/Makefile +++ b/src/Makefile @@ -47,7 +47,7 @@ endif FILES_DSP += $(wildcard Rack/src/*.c) FILES_DSP += $(wildcard Rack/src/*/*.c) -FILES_DSP += $(filter-out Rack/src/common.cpp Rack/src/dep.cpp Rack/src/discord.cpp Rack/src/gamepad.cpp Rack/src/keyboard.cpp Rack/src/library.cpp Rack/src/network.cpp Rack/src/rtaudio.cpp Rack/src/rtmidi.cpp, $(wildcard Rack/src/*.cpp)) +FILES_DSP += $(filter-out Rack/src/asset.cpp Rack/src/common.cpp Rack/src/dep.cpp Rack/src/discord.cpp Rack/src/gamepad.cpp Rack/src/keyboard.cpp Rack/src/library.cpp Rack/src/network.cpp Rack/src/rtaudio.cpp Rack/src/rtmidi.cpp, $(wildcard Rack/src/*.cpp)) FILES_DSP += $(filter-out Rack/src/window/Window.cpp, $(wildcard Rack/src/*/*.cpp)) # -------------------------------------------------------------- diff --git a/src/dep.cpp b/src/dep.cpp index 1b1b7ae..25b2d76 100644 --- a/src/dep.cpp +++ b/src/dep.cpp @@ -71,6 +71,34 @@ Exception::Exception(const char* format, ...) } } +// Custom assets location +#include +#include +#include +#include +namespace rack { +namespace asset { +std::string systemDir; +std::string userDir; +std::string bundlePath; +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, trim(filename)); +} +std::string user(std::string filename) { + return system::join(userDir, trim(filename)); +} +std::string plugin(plugin::Plugin* plugin, std::string filename) { + DISTRHO_SAFE_ASSERT_RETURN(plugin != nullptr, {}); + return system::join(systemDir, plugin->path, trim(filename)); +} +} +} + // Define the stuff needed for VCVRack but unused for Cardinal #include #include