Browse Source

Create `plugin::` namespace

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
c60339bcd3
16 changed files with 49 additions and 33 deletions
  1. +4
    -4
      include/app.hpp
  2. +1
    -1
      include/app/ModuleWidget.hpp
  3. +6
    -2
      include/asset.hpp
  4. +3
    -3
      include/helpers.hpp
  5. +1
    -1
      include/history.hpp
  6. +11
    -11
      include/logger.hpp
  7. +5
    -0
      include/plugin/Model.hpp
  8. +2
    -0
      include/plugin/Plugin.hpp
  9. +1
    -1
      include/plugin/callbacks.hpp
  10. +2
    -0
      include/rack.hpp
  11. +0
    -1
      plugin.mk
  12. +7
    -7
      src/app/ModuleBrowser.cpp
  13. +1
    -1
      src/app/RackWidget.cpp
  14. +1
    -1
      src/asset.cpp
  15. +2
    -0
      src/plugin/Model.cpp
  16. +2
    -0
      src/plugin/Plugin.cpp

+ 4
- 4
include/app.hpp View File

@@ -2,6 +2,10 @@
#include "common.hpp" #include "common.hpp"




/** Accesses the global App pointer */
#define APP rack::app::get()


namespace rack { namespace rack {




@@ -45,9 +49,5 @@ void destroy();
App *get(); App *get();




/** Accesses the global App pointer */
#define APP rack::app::get()


} // namespace app } // namespace app
} // namespace rack } // namespace rack

+ 1
- 1
include/app/ModuleWidget.hpp View File

@@ -13,7 +13,7 @@ namespace app {




struct ModuleWidget : widget::OpaqueWidget { struct ModuleWidget : widget::OpaqueWidget {
Model *model = NULL;
plugin::Model *model = NULL;
/** Owns the module pointer */ /** Owns the module pointer */
Module *module = NULL; Module *module = NULL;




+ 6
- 2
include/asset.hpp View File

@@ -4,7 +4,11 @@


namespace rack { namespace rack {


struct Plugin;

namespace plugin {
struct Plugin;
} // namespace plugin



namespace asset { 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. */ /** Returns the path of a user resource. Can read and write files to this location. */
std::string user(std::string filename); std::string user(std::string filename);
/** Returns the path of a resource in the plugin's folder. Should only read files from this location. */ /** 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; extern std::string systemDir;


+ 3
- 3
include/helpers.hpp View File

@@ -15,8 +15,8 @@ namespace rack {




template <class TModule, class TModuleWidget, typename... Tags> template <class TModule, class TModuleWidget, typename... Tags>
Model *createModel(std::string slug) {
struct TModel : Model {
plugin::Model *createModel(std::string slug) {
struct TModel : plugin::Model {
Module *createModule() override { Module *createModule() override {
TModule *o = new TModule; TModule *o = new TModule;
return o; return o;
@@ -34,7 +34,7 @@ Model *createModel(std::string slug) {
} }
}; };


Model *o = new TModel;
plugin::Model *o = new TModel;
o->slug = slug; o->slug = slug;
return o; return o;
} }


+ 1
- 1
include/history.hpp View File

@@ -57,7 +57,7 @@ struct ModuleAction : Action {




struct ModuleAdd : ModuleAction { struct ModuleAdd : ModuleAction {
Model *model;
plugin::Model *model;
math::Vec pos; math::Vec pos;
json_t *moduleJ; json_t *moduleJ;
~ModuleAdd(); ~ModuleAdd();


+ 11
- 11
include/logger.hpp View File

@@ -1,6 +1,17 @@
#pragma once #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 rack {
namespace logger { namespace logger {


@@ -18,16 +29,5 @@ void destroy();
void log(Level level, const char *filename, int line, const char *format, ...); 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 logger
} // namespace rack } // namespace rack

+ 5
- 0
include/plugin/Model.hpp View File

@@ -12,9 +12,13 @@ namespace app {
struct ModuleWidget; struct ModuleWidget;
} // namespace app } // namespace app



struct Module; struct Module;




namespace plugin {


struct Model { struct Model {
Plugin *plugin = NULL; Plugin *plugin = NULL;


@@ -41,4 +45,5 @@ struct Model {
}; };




} // namespace plugin
} // namespace rack } // namespace rack

+ 2
- 0
include/plugin/Plugin.hpp View File

@@ -5,6 +5,7 @@




namespace rack { namespace rack {
namespace plugin {




struct Model; struct Model;
@@ -46,4 +47,5 @@ struct Plugin {
}; };




} // namespace plugin
} // namespace rack } // namespace rack

+ 1
- 1
include/plugin/callbacks.hpp View File

@@ -6,4 +6,4 @@
You must implement this in your plugin You must implement this in your plugin
*/ */
extern "C" extern "C"
void init(rack::Plugin *plugin);
void init(rack::plugin::Plugin *plugin);

+ 2
- 0
include/rack.hpp View File

@@ -97,6 +97,8 @@ using namespace math;
using namespace widget; using namespace widget;
using namespace ui; using namespace ui;
using namespace app; using namespace app;
using plugin::Plugin;
using plugin::Model;




} // namespace rack } // namespace rack

+ 0
- 1
plugin.mk View File

@@ -10,7 +10,6 @@ DISTRIBUTABLES += plugin.json
FLAGS += -fPIC FLAGS += -fPIC
FLAGS += -I$(RACK_DIR)/include -I$(RACK_DIR)/dep/include FLAGS += -I$(RACK_DIR)/include -I$(RACK_DIR)/dep/include



include $(RACK_DIR)/arch.mk include $(RACK_DIR)/arch.mk


ifdef ARCH_LIN ifdef ARCH_LIN


+ 7
- 7
src/app/ModuleBrowser.cpp View File

@@ -21,7 +21,7 @@ namespace rack {
namespace app { namespace app {




static std::set<Model*> sFavoriteModels;
static std::set<plugin::Model*> sFavoriteModels;




struct BrowserOverlay : widget::OpaqueWidget { struct BrowserOverlay : widget::OpaqueWidget {
@@ -57,13 +57,13 @@ struct BrowserOverlay : widget::OpaqueWidget {




struct ModuleBox : widget::OpaqueWidget { struct ModuleBox : widget::OpaqueWidget {
Model *model;
plugin::Model *model;
/** Lazily created */ /** Lazily created */
widget::Widget *previewWidget = NULL; widget::Widget *previewWidget = NULL;
/** Number of frames since draw() has been called */ /** Number of frames since draw() has been called */
int visibleFrames = 0; int visibleFrames = 0;


void setModel(Model *model) {
void setModel(plugin::Model *model) {
this->model = model; this->model = model;


box.size.x = 70.f; box.size.x = 70.f;
@@ -173,8 +173,8 @@ struct ModuleBrowser : widget::OpaqueWidget {
moduleLayout->spacing = math::Vec(10, 10); moduleLayout->spacing = math::Vec(10, 10);
moduleScroll->container->addChild(moduleLayout); 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 *moduleBox = new ModuleBox;
moduleBox->setModel(model); moduleBox->setModel(model);
moduleLayout->addChild(moduleBox); moduleLayout->addChild(moduleBox);
@@ -244,7 +244,7 @@ json_t *moduleBrowserToJson() {
json_t *rootJ = json_object(); json_t *rootJ = json_object();


json_t *favoritesJ = json_array(); json_t *favoritesJ = json_array();
for (Model *model : sFavoriteModels) {
for (plugin::Model *model : sFavoriteModels) {
json_t *modelJ = json_object(); json_t *modelJ = json_object();
json_object_set_new(modelJ, "plugin", json_string(model->plugin->slug.c_str())); 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())); json_object_set_new(modelJ, "model", json_string(model->slug.c_str()));
@@ -267,7 +267,7 @@ void moduleBrowserFromJson(json_t *rootJ) {
continue; continue;
std::string pluginSlug = json_string_value(pluginJ); std::string pluginSlug = json_string_value(pluginJ);
std::string modelSlug = json_string_value(modelJ); std::string modelSlug = json_string_value(modelJ);
Model *model = plugin::getModel(pluginSlug, modelSlug);
plugin::Model *model = plugin::getModel(pluginSlug, modelSlug);
if (!model) if (!model)
continue; continue;
sFavoriteModels.insert(model); sFavoriteModels.insert(model);


+ 1
- 1
src/app/RackWidget.cpp View File

@@ -30,7 +30,7 @@ static ModuleWidget *moduleFromJson(json_t *moduleJ) {
std::string modelSlug = json_string_value(modelSlugJ); std::string modelSlug = json_string_value(modelSlugJ);


// Get Model // Get Model
Model *model = plugin::getModel(pluginSlug, modelSlug);
plugin::Model *model = plugin::getModel(pluginSlug, modelSlug);
if (!model) if (!model)
return NULL; return NULL;




+ 1
- 1
src/asset.cpp View File

@@ -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); assert(plugin);
return plugin->path + "/" + filename; return plugin->path + "/" + filename;
} }


+ 2
- 0
src/plugin/Model.cpp View File

@@ -2,6 +2,7 @@




namespace rack { namespace rack {
namespace plugin {




void Model::fromJson(json_t *rootJ) { void Model::fromJson(json_t *rootJ) {
@@ -25,4 +26,5 @@ void Model::fromJson(json_t *rootJ) {
} }




} // namespace plugin
} // namespace rack } // namespace rack

+ 2
- 0
src/plugin/Plugin.cpp View File

@@ -3,6 +3,7 @@




namespace rack { namespace rack {
namespace plugin {




Plugin::~Plugin() { Plugin::~Plugin() {
@@ -88,4 +89,5 @@ void Plugin::fromJson(json_t *rootJ) {
} }




} // namespace plugin
} // namespace rack } // namespace rack

Loading…
Cancel
Save