From 03a434ba1a168bbf9c2dd32e89ca9115f4fd3e1e Mon Sep 17 00:00:00 2001 From: Antoine Villeret Date: Sun, 19 Nov 2017 21:45:35 +0100 Subject: [PATCH] change createParam fingerprint to add human readeable name --- include/engine.hpp | 9 ++++++--- include/rack.hpp | 18 ++++++++++++------ src/app.cpp | 9 +++++++++ src/engine.cpp | 18 ------------------ 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/include/engine.hpp b/include/engine.hpp index c0ca4ae3..e5883a51 100644 --- a/include/engine.hpp +++ b/include/engine.hpp @@ -3,11 +3,12 @@ #include "util.hpp" #include -#include +#include #include namespace rack { +extern ossia::net::generic_device& root_dev(); struct Param { float value = 0.0; @@ -45,8 +46,6 @@ struct Output { Light plugLights[2]; }; -static ossia::net::generic_device& root_dev(); - struct Module { std::vector params; std::vector inputs; @@ -54,6 +53,8 @@ struct Module { std::vector lights; /** For CPU usage meter */ float cpuTime = 0.0; + + ossia::net::node_base* node{}; /** Deprecated, use constructor below this one */ Module() DEPRECATED {} @@ -63,6 +64,8 @@ struct Module { inputs.resize(numInputs); outputs.resize(numOutputs); lights.resize(numLights); + + node = &ossia::net::create_node(rack::root_dev(),"module"); } virtual ~Module() {} diff --git a/include/rack.hpp b/include/rack.hpp index e29fe85e..d1f658df 100644 --- a/include/rack.hpp +++ b/include/rack.hpp @@ -9,6 +9,7 @@ #include "app.hpp" #include "components.hpp" #include +#include namespace rack { @@ -24,10 +25,8 @@ Model *createModel(std::string manufacturer, std::string slug, std::string name, ModuleWidget *createModuleWidget() override { ModuleWidget *moduleWidget = new TModuleWidget(); moduleWidget->model = this; - - // TODO move node creation here - - node = &ossia::net::create_node(rack::root_dev(),name); + + moduleWidget->module->node->set_name(name); return moduleWidget; } }; @@ -47,14 +46,21 @@ Widget *createScrew(Vec pos) { } template -ParamWidget *createParam(Vec pos, Module *module, int paramId, float minValue, float maxValue, float defaultValue) { +ParamWidget *createParam(Vec pos, Module *module, int paramId, float minValue, float maxValue, float defaultValue, std::string name = std::string("")) { ParamWidget *param = new TParamWidget(); param->box.pos = pos; param->module = module; param->paramId = paramId; auto& p = module->params[paramId]; - auto& p_node = ossia::net::create_node(*module->node,p.name); + + if (name == "") + { + std::stringstream ss; + ss << "param." << paramId; + name = ss.str(); + } + auto& p_node = ossia::net::create_node(*module->node, name); p.ossia_param = p_node.create_parameter(ossia::val_type::FLOAT); p.ossia_param->set_domain(ossia::make_domain(minValue,maxValue)); p.ossia_param->set_bounding(ossia::bounding_mode::CLIP); diff --git a/src/app.cpp b/src/app.cpp index 8b8bade6..7d930a97 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -1,5 +1,7 @@ #include "app.hpp" +#include +#include namespace rack { @@ -27,5 +29,12 @@ void sceneDestroy() { gScene = NULL; } +ossia::net::generic_device& root_dev(){ + static ossia::net::generic_device dev{ + std::make_unique(1234, 5678), + "VCV-Rack"}; + + return dev; +} } // namespace rack diff --git a/src/engine.cpp b/src/engine.cpp index c0b9c84c..c3171995 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -276,22 +276,4 @@ float engineGetSampleTime() { return sampleTime; } -Module::Module(){} - -Module::Module(int numParams, int numInputs, int numOutputs, int numLights) { - params.resize(numParams); - inputs.resize(numInputs); - outputs.resize(numOutputs); - lights.resize(numLights); -} - -ossia::net::generic_device& root_dev(){ - static ossia::net::generic_device dev{ - std::make_unique(1234, 5678), - "VCV-Rack"}; - - return dev; -} - - } // namespace rack