reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

commit 9de88e3817fc901780708b52f99a9104bb699fb9
parent 7e07ce80fc7fd879be8f6a7cdf6f86f0b4513e65
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Wed, 13 Jan 2016 20:52:43 -0500

register scripts in REAPER using the new API!

Diffstat:
Msrc/registry.cpp | 21+++++++++++++++++++++
Msrc/registry.hpp | 3+++
Msrc/transaction.cpp | 7+++++++
Msrc/version.cpp | 5++++-
Msrc/version.hpp | 2++
Mtest/version.cpp | 10++++++++++
6 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/src/registry.cpp b/src/registry.cpp @@ -21,6 +21,8 @@ #include "package.hpp" #include "path.hpp" +#include <reaper_plugin_functions.h> + using namespace std; void Registry::push(Version *ver) @@ -63,3 +65,22 @@ Registry::QueryResult Registry::query(Package *pkg) const return {status, versionCode}; } + +bool Registry::addToREAPER(Version *ver, const Path &root) +{ + if(ver->package()->type() != Package::ScriptType) + return false; + + Source *src = ver->mainSource(); + + if(!src) + return false; + + const int section = 0; // 0 = main section + const string &path = (root + src->targetPath()).join(); + + custom_action_register_t ca{section, nullptr, path.c_str()}; + const int id = plugin_register("custom_action", (void *)&ca); + + return id > 0; +} diff --git a/src/registry.hpp b/src/registry.hpp @@ -23,6 +23,7 @@ #include <string> class Package; +class Path; class Version; class Registry { @@ -43,6 +44,8 @@ public: void push(Version *); void push(const std::string &key, const std::string &value); + bool addToREAPER(Version *ver, const Path &root); + size_t size() const { return m_map.size(); } QueryResult query(Package *) const; diff --git a/src/transaction.cpp b/src/transaction.cpp @@ -121,6 +121,13 @@ void Transaction::run() m_new.push_back(entry); m_registry->push(ver); + + if(!m_registry->addToREAPER(ver, m_root)) { + addError( + "Cannot register the package in REAPER. " + "Are you using REAPER v5.12 or more recent?", ver->fullName() + ); + } }); task->onFinish(bind(&Transaction::finish, this)); diff --git a/src/version.cpp b/src/version.cpp @@ -27,7 +27,7 @@ using namespace std; Version::Version(const std::string &str, Package *pkg) - : m_name(str), m_code(0), m_package(pkg) + : m_name(str), m_code(0), m_package(pkg), m_mainSource(nullptr) { static const regex pattern("(\\d+)"); @@ -99,6 +99,9 @@ void Version::addSource(Source *source) const Path path = source->targetPath(); m_files.insert(path); m_sources.insert({path, source}); + + if(source->isMain()) + m_mainSource = source; } void Version::setChangelog(const std::string &changelog) diff --git a/src/version.hpp b/src/version.hpp @@ -43,6 +43,7 @@ public: void addSource(Source *source); const std::multimap<Path, Source *> &sources() const { return m_sources; } Source *source(const size_t) const; + Source *mainSource() const { return m_mainSource; } const std::set<Path> &files() const { return m_files; } @@ -53,6 +54,7 @@ private: uint64_t m_code; Package *m_package; + Source *m_mainSource; std::string m_changelog; std::multimap<Path, Source *> m_sources; diff --git a/test/version.cpp b/test/version.cpp @@ -122,6 +122,7 @@ TEST_CASE("add source", M) { Source *src = new Source(Source::GenericPlatform, "a", "b", &ver); ver.addSource(src); + CHECK(ver.mainSource() == nullptr); CHECK(ver.sources().size() == 1); REQUIRE(src->version() == &ver); @@ -144,6 +145,15 @@ TEST_CASE("add owned source", M) { } } +TEST_CASE("add main source", M) { + MAKE_VERSION + + Source *src = new Source(Source::GenericPlatform, string(), "b", &ver); + ver.addSource(src); + + REQUIRE(ver.mainSource() == src); +} + TEST_CASE("list files", M) { MAKE_VERSION