From c60339bcd35383b455a651a62b52fcaee6c6207e Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 29 Jan 2019 13:14:15 -0500 Subject: [PATCH] Create `plugin::` namespace --- include/app.hpp | 8 ++++---- include/app/ModuleWidget.hpp | 2 +- include/asset.hpp | 8 ++++++-- include/helpers.hpp | 6 +++--- include/history.hpp | 2 +- include/logger.hpp | 22 +++++++++++----------- include/plugin/Model.hpp | 5 +++++ include/plugin/Plugin.hpp | 2 ++ include/plugin/callbacks.hpp | 2 +- include/rack.hpp | 2 ++ plugin.mk | 1 - src/app/ModuleBrowser.cpp | 14 +++++++------- src/app/RackWidget.cpp | 2 +- src/asset.cpp | 2 +- src/plugin/Model.cpp | 2 ++ src/plugin/Plugin.cpp | 2 ++ 16 files changed, 49 insertions(+), 33 deletions(-) diff --git a/include/app.hpp b/include/app.hpp index ca2653e0..afae8f6e 100644 --- a/include/app.hpp +++ b/include/app.hpp @@ -2,6 +2,10 @@ #include "common.hpp" +/** Accesses the global App pointer */ +#define APP rack::app::get() + + namespace rack { @@ -45,9 +49,5 @@ void destroy(); App *get(); -/** Accesses the global App pointer */ -#define APP rack::app::get() - - } // namespace app } // namespace rack diff --git a/include/app/ModuleWidget.hpp b/include/app/ModuleWidget.hpp index c0e5e736..54ff9825 100644 --- a/include/app/ModuleWidget.hpp +++ b/include/app/ModuleWidget.hpp @@ -13,7 +13,7 @@ namespace app { struct ModuleWidget : widget::OpaqueWidget { - Model *model = NULL; + plugin::Model *model = NULL; /** Owns the module pointer */ Module *module = NULL; diff --git a/include/asset.hpp b/include/asset.hpp index 6d5b83b3..e394ba0a 100644 --- a/include/asset.hpp +++ b/include/asset.hpp @@ -4,7 +4,11 @@ namespace rack { -struct Plugin; + +namespace plugin { + struct Plugin; +} // namespace plugin + namespace asset { @@ -15,7 +19,7 @@ std::string system(std::string filename); /** Returns the path of a user resource. Can read and write files to this location. */ std::string user(std::string filename); /** Returns the path of a resource in the plugin's folder. Should only read files from this location. */ -std::string plugin(Plugin *plugin, std::string filename); +std::string plugin(plugin::Plugin *plugin, std::string filename); extern std::string systemDir; diff --git a/include/helpers.hpp b/include/helpers.hpp index a0cc2c69..58226be7 100644 --- a/include/helpers.hpp +++ b/include/helpers.hpp @@ -15,8 +15,8 @@ namespace rack { template -Model *createModel(std::string slug) { - struct TModel : Model { +plugin::Model *createModel(std::string slug) { + struct TModel : plugin::Model { Module *createModule() override { TModule *o = new TModule; return o; @@ -34,7 +34,7 @@ Model *createModel(std::string slug) { } }; - Model *o = new TModel; + plugin::Model *o = new TModel; o->slug = slug; return o; } diff --git a/include/history.hpp b/include/history.hpp index d3e9c8ba..ecfbd5ea 100644 --- a/include/history.hpp +++ b/include/history.hpp @@ -57,7 +57,7 @@ struct ModuleAction : Action { struct ModuleAdd : ModuleAction { - Model *model; + plugin::Model *model; math::Vec pos; json_t *moduleJ; ~ModuleAdd(); diff --git a/include/logger.hpp b/include/logger.hpp index 9af307aa..af717e91 100644 --- a/include/logger.hpp +++ b/include/logger.hpp @@ -1,6 +1,17 @@ #pragma once +/** Example usage: + DEBUG("error: %d", errno); +will print something like + [0.123 debug myfile.cpp:45] error: 67 +*/ +#define DEBUG(format, ...) rack::logger::log(rack::logger::DEBUG_LEVEL, __FILE__, __LINE__, format, ##__VA_ARGS__) +#define INFO(format, ...) rack::logger::log(rack::logger::INFO_LEVEL, __FILE__, __LINE__, format, ##__VA_ARGS__) +#define WARN(format, ...) rack::logger::log(rack::logger::WARN_LEVEL, __FILE__, __LINE__, format, ##__VA_ARGS__) +#define FATAL(format, ...) rack::logger::log(rack::logger::FATAL_LEVEL, __FILE__, __LINE__, format, ##__VA_ARGS__) + + namespace rack { namespace logger { @@ -18,16 +29,5 @@ void destroy(); void log(Level level, const char *filename, int line, const char *format, ...); -/** Example usage: - DEBUG("error: %d", errno); -will print something like - [0.123 debug myfile.cpp:45] error: 67 -*/ -#define DEBUG(format, ...) rack::logger::log(rack::logger::DEBUG_LEVEL, __FILE__, __LINE__, format, ##__VA_ARGS__) -#define INFO(format, ...) rack::logger::log(rack::logger::INFO_LEVEL, __FILE__, __LINE__, format, ##__VA_ARGS__) -#define WARN(format, ...) rack::logger::log(rack::logger::WARN_LEVEL, __FILE__, __LINE__, format, ##__VA_ARGS__) -#define FATAL(format, ...) rack::logger::log(rack::logger::FATAL_LEVEL, __FILE__, __LINE__, format, ##__VA_ARGS__) - - } // namespace logger } // namespace rack diff --git a/include/plugin/Model.hpp b/include/plugin/Model.hpp index 2933608f..640bd48f 100644 --- a/include/plugin/Model.hpp +++ b/include/plugin/Model.hpp @@ -12,9 +12,13 @@ namespace app { struct ModuleWidget; } // namespace app + struct Module; +namespace plugin { + + struct Model { Plugin *plugin = NULL; @@ -41,4 +45,5 @@ struct Model { }; +} // namespace plugin } // namespace rack diff --git a/include/plugin/Plugin.hpp b/include/plugin/Plugin.hpp index b1e0d57e..bd27a39a 100644 --- a/include/plugin/Plugin.hpp +++ b/include/plugin/Plugin.hpp @@ -5,6 +5,7 @@ namespace rack { +namespace plugin { struct Model; @@ -46,4 +47,5 @@ struct Plugin { }; +} // namespace plugin } // namespace rack diff --git a/include/plugin/callbacks.hpp b/include/plugin/callbacks.hpp index 4f53d75a..b04f3db4 100644 --- a/include/plugin/callbacks.hpp +++ b/include/plugin/callbacks.hpp @@ -6,4 +6,4 @@ You must implement this in your plugin */ extern "C" -void init(rack::Plugin *plugin); +void init(rack::plugin::Plugin *plugin); diff --git a/include/rack.hpp b/include/rack.hpp index e7f45bbe..551dca87 100644 --- a/include/rack.hpp +++ b/include/rack.hpp @@ -97,6 +97,8 @@ using namespace math; using namespace widget; using namespace ui; using namespace app; +using plugin::Plugin; +using plugin::Model; } // namespace rack diff --git a/plugin.mk b/plugin.mk index 6e1b4389..0e634e8c 100644 --- a/plugin.mk +++ b/plugin.mk @@ -10,7 +10,6 @@ DISTRIBUTABLES += plugin.json FLAGS += -fPIC FLAGS += -I$(RACK_DIR)/include -I$(RACK_DIR)/dep/include - include $(RACK_DIR)/arch.mk ifdef ARCH_LIN diff --git a/src/app/ModuleBrowser.cpp b/src/app/ModuleBrowser.cpp index 0ba8102e..7cad3178 100644 --- a/src/app/ModuleBrowser.cpp +++ b/src/app/ModuleBrowser.cpp @@ -21,7 +21,7 @@ namespace rack { namespace app { -static std::set sFavoriteModels; +static std::set sFavoriteModels; struct BrowserOverlay : widget::OpaqueWidget { @@ -57,13 +57,13 @@ struct BrowserOverlay : widget::OpaqueWidget { struct ModuleBox : widget::OpaqueWidget { - Model *model; + plugin::Model *model; /** Lazily created */ widget::Widget *previewWidget = NULL; /** Number of frames since draw() has been called */ int visibleFrames = 0; - void setModel(Model *model) { + void setModel(plugin::Model *model) { this->model = model; box.size.x = 70.f; @@ -173,8 +173,8 @@ struct ModuleBrowser : widget::OpaqueWidget { moduleLayout->spacing = math::Vec(10, 10); moduleScroll->container->addChild(moduleLayout); - for (Plugin *plugin : plugin::plugins) { - for (Model *model : plugin->models) { + for (plugin::Plugin *plugin : plugin::plugins) { + for (plugin::Model *model : plugin->models) { ModuleBox *moduleBox = new ModuleBox; moduleBox->setModel(model); moduleLayout->addChild(moduleBox); @@ -244,7 +244,7 @@ json_t *moduleBrowserToJson() { json_t *rootJ = json_object(); json_t *favoritesJ = json_array(); - for (Model *model : sFavoriteModels) { + for (plugin::Model *model : sFavoriteModels) { json_t *modelJ = json_object(); json_object_set_new(modelJ, "plugin", json_string(model->plugin->slug.c_str())); json_object_set_new(modelJ, "model", json_string(model->slug.c_str())); @@ -267,7 +267,7 @@ void moduleBrowserFromJson(json_t *rootJ) { continue; std::string pluginSlug = json_string_value(pluginJ); std::string modelSlug = json_string_value(modelJ); - Model *model = plugin::getModel(pluginSlug, modelSlug); + plugin::Model *model = plugin::getModel(pluginSlug, modelSlug); if (!model) continue; sFavoriteModels.insert(model); diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index 8ac21c08..3986c150 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -30,7 +30,7 @@ static ModuleWidget *moduleFromJson(json_t *moduleJ) { std::string modelSlug = json_string_value(modelSlugJ); // Get Model - Model *model = plugin::getModel(pluginSlug, modelSlug); + plugin::Model *model = plugin::getModel(pluginSlug, modelSlug); if (!model) return NULL; diff --git a/src/asset.cpp b/src/asset.cpp index 6034889d..e9084a94 100644 --- a/src/asset.cpp +++ b/src/asset.cpp @@ -105,7 +105,7 @@ std::string user(std::string filename) { } -std::string plugin(Plugin *plugin, std::string filename) { +std::string plugin(plugin::Plugin *plugin, std::string filename) { assert(plugin); return plugin->path + "/" + filename; } diff --git a/src/plugin/Model.cpp b/src/plugin/Model.cpp index c03550f9..912987ee 100644 --- a/src/plugin/Model.cpp +++ b/src/plugin/Model.cpp @@ -2,6 +2,7 @@ namespace rack { +namespace plugin { void Model::fromJson(json_t *rootJ) { @@ -25,4 +26,5 @@ void Model::fromJson(json_t *rootJ) { } +} // namespace plugin } // namespace rack diff --git a/src/plugin/Plugin.cpp b/src/plugin/Plugin.cpp index dac5e5db..12833ed8 100644 --- a/src/plugin/Plugin.cpp +++ b/src/plugin/Plugin.cpp @@ -3,6 +3,7 @@ namespace rack { +namespace plugin { Plugin::~Plugin() { @@ -88,4 +89,5 @@ void Plugin::fromJson(json_t *rootJ) { } +} // namespace plugin } // namespace rack