clap

CLAP Audio Plugin API
Log | Files | Refs | README | LICENSE

commit a03904f0f019dc7d290629fe11404400f2a6cce2
parent bd46db5e6e7e1b53ca7dec5bb92460e61552ee2b
Author: Alexandre BIQUE <bique.alexandre@gmail.com>
Date:   Sun,  1 Aug 2021 19:30:35 +0200

Add a development path provider, for convenience

Diffstat:
Mexamples/plugins/path-provider.cc | 44++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 42 insertions(+), 2 deletions(-)

diff --git a/examples/plugins/path-provider.cc b/examples/plugins/path-provider.cc @@ -1,7 +1,7 @@ #include <cassert> #include <cstring> -#include <regex> #include <filesystem> +#include <regex> #include "path-provider.hh" @@ -26,13 +26,53 @@ namespace clap { const std::filesystem::path prefix_; }; + class LinuxDevelopmentPathProvider final : public PathProvider { + public: + LinuxDevelopmentPathProvider(const std::string &pluginPath) + : srcRoot_(computeSrcRoot(pluginPath)), buildRoot_(computeBuildRoot(pluginPath)) {} + + static std::string computeSrcRoot(const std::string &pluginPath) { + static const std::regex r("(/.*)/cmake-builds/.*$", std::regex::optimize); + + std::smatch m; + if (!std::regex_match(pluginPath, m, r)) + return ""; + return m[1]; + } + + static std::string computeBuildRoot(const std::string &pluginPath) { + static const std::regex r("(/.*/cmake-builds/.*)/examples/plugins/.*\\.clap$", + std::regex::optimize); + + std::smatch m; + if (!std::regex_match(pluginPath, m, r)) + return ""; + return m[1]; + } + + std::string getGuiExecutable() const override { + return buildRoot_ / "/examples/gui/clap-gui"; + } + + bool isValid() const noexcept { return !srcRoot_.empty() && !buildRoot_.empty(); } + + private: + const std::filesystem::path srcRoot_; + const std::filesystem::path buildRoot_; + }; + std::unique_ptr<PathProvider> PathProvider::instance_; const PathProvider *PathProvider::createInstance(const std::string &pluginPath) { assert(!instance_); #ifdef __linux__ - return new LinuxPathProvider(pluginPath); + { + auto ptr = std::make_unique<LinuxDevelopmentPathProvider>(pluginPath); + if (ptr->isValid()) + return ptr.release(); + return new LinuxPathProvider(pluginPath); + } #endif // TODO