@@ -3,12 +3,15 @@ | |||
#include "util.hpp" | |||
#include <jansson.h> | |||
#include <ossia/ossia.hpp> | |||
#include <ossia/network/oscquery/oscquery_server.hpp> | |||
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<Param> params; | |||
@@ -47,17 +51,19 @@ struct Module { | |||
std::vector<Light> 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() {} | |||
@@ -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<float>(); | |||
p.value = param->value; | |||
if ( auto fbw = dynamic_cast<FramebufferWidget*>(param)) | |||
fbw->dirty = true; | |||
}); | |||
param->setLimits(minValue, maxValue); | |||
param->setDefaultValue(defaultValue); | |||
return param; | |||
} | |||
@@ -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<ossia::oscquery::oscquery_server_protocol>(1234, 5678), | |||
"VCV-Rack"}; | |||
return dev; | |||
} | |||
} // namespace rack |