From 2dcd259250f2a7118e1d672800d681908a616299 Mon Sep 17 00:00:00 2001 From: Antoine Villeret Date: Fri, 17 Nov 2017 12:26:00 +0100 Subject: [PATCH 1/4] automatically expose all module's parameters with libossia --- include/engine.hpp | 24 +++++++++++++++--------- include/rack.hpp | 20 +++++++++++++++++++- src/engine.cpp | 30 ++++++++++++++++++++++++++++-- 3 files changed, 62 insertions(+), 12 deletions(-) diff --git a/include/engine.hpp b/include/engine.hpp index 2f0bc546..2907deaf 100644 --- a/include/engine.hpp +++ b/include/engine.hpp @@ -3,12 +3,15 @@ #include "util.hpp" #include +#include +#include namespace rack { - struct Param { float value = 0.0; + std::string name = "param.1"; + ossia::net::parameter_base* ossia_param; }; struct Input { @@ -39,6 +42,7 @@ struct Light { void setBrightnessSmooth(float brightness); }; +static ossia::net::generic_device& root_dev(); struct Module { std::vector params; @@ -47,17 +51,19 @@ 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() {} + Module(); + /** Constructs Module with a fixed number of params, inputs, and outputs */ - Module(int numParams, int numInputs, int numOutputs, int numLights = 0) { - params.resize(numParams); - inputs.resize(numInputs); - outputs.resize(numOutputs); - lights.resize(numLights); - } - virtual ~Module() {} + Module(int numParams, int numInputs, int numOutputs, int numLights = 0); + ~Module() + { + if (node) + node->get_parent()->remove_child(*node); + } /** Advances the module by 1 audio frame with duration 1.0 / gSampleRate */ virtual void step() {} diff --git a/include/rack.hpp b/include/rack.hpp index 5d45a5e5..a4ce387c 100644 --- a/include/rack.hpp +++ b/include/rack.hpp @@ -48,8 +48,26 @@ ParamWidget *createParam(Vec pos, Module *module, int paramId, float minValue, f param->box.pos = pos; param->module = module; param->paramId = paramId; - param->setLimits(minValue, maxValue); + + auto& p = module->params[paramId]; + auto& p_node = ossia::net::create_node(*module->node,p.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); + p.ossia_param->push_value(defaultValue); + p.ossia_param->set_default_value(defaultValue); + + p.ossia_param->add_callback([param] (const ossia::value& v) { + auto& p = param->module->params[param->paramId]; + param->value = v.get(); + p.value = param->value; + if ( auto fbw = dynamic_cast(param)) + fbw->dirty = true; + }); + + param->setLimits(minValue, maxValue); param->setDefaultValue(defaultValue); + return param; } diff --git a/src/engine.cpp b/src/engine.cpp index 2e8f984e..b2f1f95b 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -11,7 +11,6 @@ #include "engine.hpp" #include "util.hpp" - namespace rack { float sampleRate; @@ -33,7 +32,6 @@ static Module *smoothModule = NULL; static int smoothParamId; static float smoothValue; - float Light::getBrightness() { return sqrtf(fmaxf(0.0, value)); } @@ -76,11 +74,13 @@ static void engineStep() { float delta = smoothValue - value; if (fabsf(delta) < snap) { smoothModule->params[smoothParamId].value = smoothValue; + smoothModule->params[smoothParamId].ossia_param->push_value(smoothValue); smoothModule = NULL; } else { value += delta * lambda * sampleTime; smoothModule->params[smoothParamId].value = value; + smoothModule->params[smoothParamId].ossia_param->push_value(value); } } @@ -223,6 +223,7 @@ void engineRemoveWire(Wire *wire) { void engineSetParam(Module *module, int paramId, float value) { module->params[paramId].value = value; + module->params[paramId].ossia_param->push_value(value); } void engineSetParamSmooth(Module *module, int paramId, float value) { @@ -231,10 +232,12 @@ void engineSetParamSmooth(Module *module, int paramId, float value) { // Since only one param can be smoothed at a time, if another param is currently being smoothed, skip to its final state if (smoothModule && !(smoothModule == module && smoothParamId == paramId)) { smoothModule->params[smoothParamId].value = smoothValue; + smoothModule->params[smoothParamId].ossia_param->push_value(smoothValue); } smoothModule = module; smoothParamId = paramId; smoothValue = value; + module->params[paramId].ossia_param->push_value(smoothValue); } void engineSetSampleRate(float newSampleRate) { @@ -256,4 +259,27 @@ float engineGetSampleTime() { return sampleTime; } +Module::Module(){ + node = &ossia::net::create_node(rack::root_dev(),"module"); +} + +Module::Module(int numParams, int numInputs, int numOutputs, int numLights) { + params.resize(numParams); + inputs.resize(numInputs); + outputs.resize(numOutputs); + lights.resize(numLights); + + std::cout << "create node" << std::endl; + node = &ossia::net::create_node(rack::root_dev(),"module"); +} + +ossia::net::generic_device& root_dev(){ + static ossia::net::generic_device dev{ + std::make_unique(1234, 5678), + "VCV-Rack"}; + + return dev; +} + + } // namespace rack From 03a434ba1a168bbf9c2dd32e89ca9115f4fd3e1e Mon Sep 17 00:00:00 2001 From: Antoine Villeret Date: Sun, 19 Nov 2017 21:45:35 +0100 Subject: [PATCH 2/4] 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 From 2b315e6af3639c23d467736cbfd8b304695fe3b4 Mon Sep 17 00:00:00 2001 From: Antoine Villeret Date: Sat, 23 Dec 2017 12:57:58 +0100 Subject: [PATCH 3/4] fix libossia dep building --- Makefile | 4 ++-- dep/Makefile | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index c4b43369..c5b9d45a 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ ifeq ($(ARCH), mac) CXXFLAGS += -DAPPLE -stdlib=libc++ LDFLAGS += -stdlib=libc++ -lpthread -ldl \ -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo \ - -Ldep/lib -lGLEW -lglfw -ljansson -lsamplerate -lcurl -lzip -lportaudio -lrtmidi + -Ldep/lib -lGLEW -lglfw -ljansson -lsamplerate -lcurl -lzip -lportaudio -lrtmidi -lossia TARGET = Rack BUNDLE = dist/$(TARGET).app endif @@ -34,7 +34,7 @@ ifeq ($(ARCH), win) -Wl,--export-all-symbols,--out-implib,libRack.a -mwindows \ -lgdi32 -lopengl32 -lcomdlg32 -lole32 \ -Ldep/lib -lglew32 -lglfw3dll -lcurl -lzip -lportaudio_x64 -lrtmidi \ - -Wl,-Bstatic -ljansson -lsamplerate + -Wl,-Bstatic -ljansson -lsamplerate -lossia TARGET = Rack.exe OBJECTS = Rack.res endif diff --git a/dep/Makefile b/dep/Makefile index 1271b3e5..e414a00f 100755 --- a/dep/Makefile +++ b/dep/Makefile @@ -131,12 +131,13 @@ $(rtaudio): $(MAKE) -C rtaudio-5.0.0 install $(ossia): - # TODO use release tarball instead of building it locally - git clone https://github.com/OSSIA/libossia --recursive - cd libossia && $(CMAKE) . \ - -DCMAKE_INSTALL_PREFIX="$(LOCAL)" -DOSSIA_PD=OFF \ - -DOSSIA_COTIRE=OFF -DOSSIA_PROTOCOL_MIDI=OFF . - $(MAKE) -j4 + # TODO use release tarball instead of building it locally + git clone https://github.com/OSSIA/libossia --depth=1 + mkdir -p build-libossia && cd build-libossia && $(CMAKE) \ + -DCMAKE_INSTALL_PREFIX="$(LOCAL)" -DOSSIA_PD=OFF \ + -DOSSIA_COTIRE=OFF -DOSSIA_PROTOCOL_MIDI=OFF \ + -DOSSIA_EDITOR=OFF -DBUILD_TYPE=Release ../libossia && \ + $(MAKE) -j4 && \ $(MAKE) install clean: From bfea9d763ae322df3b4d3adbdc4c1cde9671cc7f Mon Sep 17 00:00:00 2001 From: Antoine Villeret Date: Mon, 1 Jan 2018 14:17:29 +0100 Subject: [PATCH 4/4] fix ossia dependency --- dep/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dep/Makefile b/dep/Makefile index 394a07d1..5a4c3e20 100755 --- a/dep/Makefile +++ b/dep/Makefile @@ -58,6 +58,7 @@ ifeq ($(ARCH),win) rtmidi = bin/librtmidi-4.dll rtaudio = bin/librtaudio.dll openssl = bin/libssl-1_1-x64.dll + ossia = bin/ossia.dll endif # Library configuration @@ -76,7 +77,7 @@ endif .NOTPARALLEL: -all: $(glew) $(glfw) $(jansson) $(libspeexdsp) $(libcurl) $(libzip) $(rtmidi) $(rtaudio) +all: $(glew) $(glfw) $(jansson) $(libspeexdsp) $(libcurl) $(libzip) $(rtmidi) $(rtaudio) $(ossia) @echo "" @echo "#######################################" @echo "# Built all dependencies successfully #" @@ -146,8 +147,8 @@ $(rtaudio): cd rtaudio/cmakebuild && cmake -G 'Unix Makefiles' -DCMAKE_INSTALL_PREFIX="$(LOCAL)" $(RTAUDIO_FLAGS) .. $(MAKE) -C rtaudio/cmakebuild $(MAKE) -C rtaudio/cmakebuild install + $(ossia): - # TODO use release tarball instead of building it locally git clone https://github.com/OSSIA/libossia --depth=1 mkdir -p build-libossia && cd build-libossia && $(CMAKE) \ -DCMAKE_INSTALL_PREFIX="$(LOCAL)" -DOSSIA_PD=OFF \