From 2e77c034640c56130c6dabdb6bc3a1d2f0ab7829 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Wed, 22 Jul 2020 13:55:29 +0200 Subject: [PATCH] Move the configuration object to src/common/ --- meson.build | 3 ++- src/{plugin => common}/configuration.cpp | 14 ----------- src/{plugin => common}/configuration.h | 31 ++++++------------------ src/plugin/plugin-bridge.cpp | 3 ++- src/plugin/plugin-bridge.h | 4 +-- src/plugin/utils.cpp | 14 ++++++++++- src/plugin/utils.h | 25 +++++++++++++++++++ 7 files changed, 52 insertions(+), 42 deletions(-) rename src/{plugin => common}/configuration.cpp (82%) rename src/{plugin => common}/configuration.h (72%) diff --git a/meson.build b/meson.build index 16f9431d..6d18f3b7 100644 --- a/meson.build +++ b/meson.build @@ -89,9 +89,9 @@ include_dir = include_directories('src/include') shared_library( 'yabridge', [ + 'src/common/configuration.cpp', 'src/common/logging.cpp', 'src/common/serialization.cpp', - 'src/plugin/configuration.cpp', 'src/plugin/host-process.cpp', 'src/plugin/plugin.cpp', 'src/plugin/plugin-bridge.cpp', @@ -112,6 +112,7 @@ shared_library( ) host_sources = [ + 'src/common/configuration.cpp', 'src/common/logging.cpp', 'src/common/serialization.cpp', 'src/wine-host/bridges/vst2.cpp', diff --git a/src/plugin/configuration.cpp b/src/common/configuration.cpp similarity index 82% rename from src/plugin/configuration.cpp rename to src/common/configuration.cpp index cacecc73..9b15b7f5 100644 --- a/src/plugin/configuration.cpp +++ b/src/common/configuration.cpp @@ -20,8 +20,6 @@ #include #include -#include "utils.h" - namespace fs = boost::filesystem; Configuration::Configuration() {} @@ -57,15 +55,3 @@ Configuration::Configuration(const fs::path& config_path, break; } } - -Configuration Configuration::load_for(const fs::path& yabridge_path) { - // First find the closest `yabridge.tmol` file for the plugin, falling back - // to default configuration settings if it doesn't exist - const std::optional config_file = - find_dominating_file("yabridge.toml", yabridge_path); - if (!config_file) { - return Configuration(); - } - - return Configuration(*config_file, yabridge_path); -} diff --git a/src/plugin/configuration.h b/src/common/configuration.h similarity index 72% rename from src/plugin/configuration.h rename to src/common/configuration.h index f3e51bb1..128cddaf 100644 --- a/src/plugin/configuration.h +++ b/src/common/configuration.h @@ -16,7 +16,11 @@ #pragma once +#ifdef __WINE__ +#include "../wine-host/boost-fix.h" +#endif #include + #include /** @@ -25,8 +29,9 @@ * plugins that will be hosted in the same process rather than individually so * they can share resources. Configuration file loading works as follows: * - * 1. `Configuration::load_for(path)` gets called with a path to the copy of or - * symlink to `libyabridge.so` that the plugin host has tried to load. + * 1. `load_config_for(path)` from `src/plugin/utils.h` gets called with a path + * to the copy of or symlink to `libyabridge.so` that the plugin host has + * tried to load. * 2. We start looking for a file named `yabridge.toml` in the same directory as * that `.so` file, iteratively continuing to search one directory higher * until we either find the file or we reach the filesystem root. @@ -60,31 +65,11 @@ class Configuration { * * @throw toml::parsing_error If the file could not be parsed. * - * @see Configuration::load_for + * @see ../plugin/utils.h:load_config_for */ Configuration(const boost::filesystem::path& config_path, const boost::filesystem::path& yabridge_path); - /** - * Load the configuration that belongs to a copy of or symlink to - * `libyabridge.so`. If no configuration file could be found then this will - * return an empty configuration object with default settings. - * - * This function will take any optional compile-time features that have not - * been enabled into account. - * - * @param yabridge_path The path to the .so file that's being loaded.by the - * VST host. This will be used both for the starting location of the - * search and to determine which section in the config file to use. - * - * @return Either a configuration object populated with values from matched - * glob pattern within the found configuration file, or an empty - * configuration object if no configuration file could be found or if the - * plugin could not be matched to any of the glob patterns in the - * configuration file. - */ - static Configuration load_for(const boost::filesystem::path& yabridge_path); - /** * The name of the plugin group that should be used for the plugin this * configuration object was created for. If not set, then the plugin should diff --git a/src/plugin/plugin-bridge.cpp b/src/plugin/plugin-bridge.cpp index 822820c6..48128fac 100644 --- a/src/plugin/plugin-bridge.cpp +++ b/src/plugin/plugin-bridge.cpp @@ -22,6 +22,7 @@ #include "../common/communication.h" #include "../common/events.h" +#include "utils.h" namespace bp = boost::process; // I'd rather use std::filesystem instead, but Boost.Process depends on @@ -44,7 +45,7 @@ PluginBridge& get_bridge_instance(const AEffect& plugin) { } PluginBridge::PluginBridge(audioMasterCallback host_callback) - : config(Configuration::load_for(get_this_file_location())), + : config(load_config_for(get_this_file_location())), vst_plugin_path(find_vst_plugin()), // All the fields should be zero initialized because // `Vst2PluginInstance::vstAudioMasterCallback` from Bitwig's plugin diff --git a/src/plugin/plugin-bridge.h b/src/plugin/plugin-bridge.h index 59383e40..ed908f4e 100644 --- a/src/plugin/plugin-bridge.h +++ b/src/plugin/plugin-bridge.h @@ -23,8 +23,8 @@ #include #include +#include "../common/configuration.h" #include "../common/logging.h" -#include "configuration.h" #include "host-process.h" /** @@ -76,7 +76,7 @@ class PluginBridge { * The configuration for this instance of yabridge. Set based on the values * from a `yabridge.toml`, if it exists. * - * @see Configuration::load_for + * @see ./utils.h:load_config_for */ Configuration config; diff --git a/src/plugin/utils.cpp b/src/plugin/utils.cpp index a2f5b931..614cb2de 100644 --- a/src/plugin/utils.cpp +++ b/src/plugin/utils.cpp @@ -28,7 +28,7 @@ // Generated inside of build directory #include -#include "configuration.h" +#include "../common/configuration.h" namespace bp = boost::process; namespace fs = boost::filesystem; @@ -269,6 +269,18 @@ std::string get_wine_version() { return version_string; } +Configuration load_config_for(const fs::path& yabridge_path) { + // First find the closest `yabridge.tmol` file for the plugin, falling back + // to default configuration settings if it doesn't exist + const std::optional config_file = + find_dominating_file("yabridge.toml", yabridge_path); + if (!config_file) { + return Configuration(); + } + + return Configuration(*config_file, yabridge_path); +} + bp::environment set_wineprefix() { bp::environment env = boost::this_process::environment(); diff --git a/src/plugin/utils.h b/src/plugin/utils.h index 9cd721b4..0deb1cd3 100644 --- a/src/plugin/utils.h +++ b/src/plugin/utils.h @@ -20,6 +20,8 @@ #include #include +#include "../common/configuration.h" + /** * Boost 1.72 was released with a known breaking bug caused by a missing * typedef: https://github.com/boostorg/process/issues/116. @@ -164,6 +166,29 @@ boost::filesystem::path get_this_file_location(); */ std::string get_wine_version(); +/** + * Load the configuration that belongs to a copy of or symlink to + * `libyabridge.so`. If no configuration file could be found then this will + * return an empty configuration object with default settings. See the docstrong + * on the `Configuration` class for more details on how to choose the config + * file to load. + * + * This function will take any optional compile-time features that have not been + * enabled into account. + * + * @param yabridge_path The path to the .so file that's being loaded.by the VST + * host. This will be used both for the starting location of the search and to + * determine which section in the config file to use. + * + * @return Either a configuration object populated with values from matched glob + * pattern within the found configuration file, or an empty configuration + * object if no configuration file could be found or if the plugin could not + * be matched to any of the glob patterns in the configuration file. + * + * @see Configuration + */ +Configuration load_config_for(const boost::filesystem::path& yabridge_path); + /** * Locate the Wine prefix and set the `WINEPREFIX` environment variable if * found. This way it's also possible to run .dll files outside of a Wine prefix