From cd5338e4eea07e4f04c520051cb1781c75a28311 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Mon, 7 Jan 2019 15:53:08 -0500 Subject: [PATCH] Update VCO to Rack v1 API --- src/VCO.cpp | 80 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 32 deletions(-) diff --git a/src/VCO.cpp b/src/VCO.cpp index 1f46fe2..fd73373 100644 --- a/src/VCO.cpp +++ b/src/VCO.cpp @@ -60,7 +60,7 @@ struct VoltageControlledOscillator { // Adjust pitch slew if (++pitchSlewIndex > 32) { const float pitchSlewTau = 100.0f; // Time constant for leaky integrator in seconds - pitchSlew += (randomNormal() - pitchSlew / pitchSlewTau) * engineGetSampleTime(); + pitchSlew += (random::normal() - pitchSlew / pitchSlewTau) * context()->engine->getSampleTime(); pitchSlewIndex = 0; } } @@ -140,7 +140,7 @@ struct VoltageControlledOscillator { // Advance phase phase += deltaPhase / OVERSAMPLE; - phase = eucmod(phase, 1.0f); + phase = eucMod(phase, 1.0f); } } @@ -195,7 +195,16 @@ struct VCO : Module { VoltageControlledOscillator<16, 16> oscillator; - VCO() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {} + VCO() { + setup(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); + params[MODE_PARAM].setup(0.f, 1.f, 1.f); + params[SYNC_PARAM].setup(0.f, 1.f, 1.f); + params[FREQ_PARAM].setup(-54.0f, 54.0f, 0.0f, "Frequency", " Hz", std::pow(2, 1/12.f), 261.626f); + params[FINE_PARAM].setup(-1.0f, 1.0f, 0.0f, "Fine frequency"); + params[FM_PARAM].setup(0.0f, 1.0f, 0.0f, "Frequency modulation"); + params[PW_PARAM].setup(0.0f, 1.0f, 0.5f, "Pulse width", "%", 0.f, 100.f); + params[PWM_PARAM].setup(0.0f, 1.0f, 0.0f, "Pulse width modulation", "%", 0.f, 100.f); + } void step() override; }; @@ -213,7 +222,7 @@ void VCO::step() { oscillator.setPulseWidth(params[PW_PARAM].value + params[PWM_PARAM].value * inputs[PW_INPUT].value / 10.0f); oscillator.syncEnabled = inputs[SYNC_INPUT].active; - oscillator.process(engineGetSampleTime(), inputs[SYNC_INPUT].value); + oscillator.process(context()->engine->getSampleTime(), inputs[SYNC_INPUT].value); // Set output if (outputs[SIN_OUTPUT].active) @@ -235,31 +244,31 @@ struct VCOWidget : ModuleWidget { }; VCOWidget::VCOWidget(VCO *module) : ModuleWidget(module) { - setPanel(SVG::load(assetPlugin(plugin, "res/VCO-1.svg"))); + setPanel(SVG::load(asset::plugin(plugin, "res/VCO-1.svg"))); addChild(createWidget(Vec(15, 0))); addChild(createWidget(Vec(box.size.x-30, 0))); addChild(createWidget(Vec(15, 365))); addChild(createWidget(Vec(box.size.x-30, 365))); - addParam(createParam(Vec(15, 77), module, VCO::MODE_PARAM, 0.0f, 1.0f, 1.0f)); - addParam(createParam(Vec(119, 77), module, VCO::SYNC_PARAM, 0.0f, 1.0f, 1.0f)); + addParam(createParam(Vec(15, 77), module, VCO::MODE_PARAM)); + addParam(createParam(Vec(119, 77), module, VCO::SYNC_PARAM)); - addParam(createParam(Vec(47, 61), module, VCO::FREQ_PARAM, -54.0f, 54.0f, 0.0f)); - addParam(createParam(Vec(23, 143), module, VCO::FINE_PARAM, -1.0f, 1.0f, 0.0f)); - addParam(createParam(Vec(91, 143), module, VCO::PW_PARAM, 0.0f, 1.0f, 0.5f)); - addParam(createParam(Vec(23, 208), module, VCO::FM_PARAM, 0.0f, 1.0f, 0.0f)); - addParam(createParam(Vec(91, 208), module, VCO::PWM_PARAM, 0.0f, 1.0f, 0.0f)); + addParam(createParam(Vec(47, 61), module, VCO::FREQ_PARAM)); + addParam(createParam(Vec(23, 143), module, VCO::FINE_PARAM)); + addParam(createParam(Vec(91, 143), module, VCO::PW_PARAM)); + addParam(createParam(Vec(23, 208), module, VCO::FM_PARAM)); + addParam(createParam(Vec(91, 208), module, VCO::PWM_PARAM)); - addInput(createPort(Vec(11, 276), PortWidget::INPUT, module, VCO::PITCH_INPUT)); - addInput(createPort(Vec(45, 276), PortWidget::INPUT, module, VCO::FM_INPUT)); - addInput(createPort(Vec(80, 276), PortWidget::INPUT, module, VCO::SYNC_INPUT)); - addInput(createPort(Vec(114, 276), PortWidget::INPUT, module, VCO::PW_INPUT)); + addInput(createInput(Vec(11, 276), module, VCO::PITCH_INPUT)); + addInput(createInput(Vec(45, 276), module, VCO::FM_INPUT)); + addInput(createInput(Vec(80, 276), module, VCO::SYNC_INPUT)); + addInput(createInput(Vec(114, 276), module, VCO::PW_INPUT)); - addOutput(createPort(Vec(11, 320), PortWidget::OUTPUT, module, VCO::SIN_OUTPUT)); - addOutput(createPort(Vec(45, 320), PortWidget::OUTPUT, module, VCO::TRI_OUTPUT)); - addOutput(createPort(Vec(80, 320), PortWidget::OUTPUT, module, VCO::SAW_OUTPUT)); - addOutput(createPort(Vec(114, 320), PortWidget::OUTPUT, module, VCO::SQR_OUTPUT)); + addOutput(createOutput(Vec(11, 320), module, VCO::SIN_OUTPUT)); + addOutput(createOutput(Vec(45, 320), module, VCO::TRI_OUTPUT)); + addOutput(createOutput(Vec(80, 320), module, VCO::SAW_OUTPUT)); + addOutput(createOutput(Vec(114, 320), module, VCO::SQR_OUTPUT)); addChild(createLight>(Vec(99, 42.5f), module, VCO::PHASE_POS_LIGHT)); } @@ -295,7 +304,14 @@ struct VCO2 : Module { VoltageControlledOscillator<8, 8> oscillator; - VCO2() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {} + VCO2() { + setup(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); + params[MODE_PARAM].setup(0.f, 1.f, 1.f); + params[SYNC_PARAM].setup(0.f, 1.f, 1.f); + params[FREQ_PARAM].setup(-54.0f, 54.0f, 0.0f, "Frequency", " Hz", std::pow(2, 1/12.f), 261.626f); + params[WAVE_PARAM].setup(0.0f, 3.0f, 1.5f, "Wave"); + params[FM_PARAM].setup(0.0f, 1.0f, 0.0f, "Frequency modulation"); + } void step() override; }; @@ -308,7 +324,7 @@ void VCO2::step() { oscillator.setPitch(0.0f, pitchCv); oscillator.syncEnabled = inputs[SYNC_INPUT].active; - oscillator.process(engineGetSampleTime(), inputs[SYNC_INPUT].value); + oscillator.process(context()->engine->getSampleTime(), inputs[SYNC_INPUT].value); // Set output float wave = clamp(params[WAVE_PARAM].value + inputs[WAVE_INPUT].value, 0.0f, 3.0f); @@ -331,25 +347,25 @@ struct VCO2Widget : ModuleWidget { }; VCO2Widget::VCO2Widget(VCO2 *module) : ModuleWidget(module) { - setPanel(SVG::load(assetPlugin(plugin, "res/VCO-2.svg"))); + setPanel(SVG::load(asset::plugin(plugin, "res/VCO-2.svg"))); addChild(createWidget(Vec(15, 0))); addChild(createWidget(Vec(box.size.x-30, 0))); addChild(createWidget(Vec(15, 365))); addChild(createWidget(Vec(box.size.x-30, 365))); - addParam(createParam(Vec(62, 150), module, VCO2::MODE_PARAM, 0.0f, 1.0f, 1.0f)); - addParam(createParam(Vec(62, 215), module, VCO2::SYNC_PARAM, 0.0f, 1.0f, 1.0f)); + addParam(createParam(Vec(62, 150), module, VCO2::MODE_PARAM)); + addParam(createParam(Vec(62, 215), module, VCO2::SYNC_PARAM)); - addParam(createParam(Vec(17, 60), module, VCO2::FREQ_PARAM, -54.0f, 54.0f, 0.0f)); - addParam(createParam(Vec(12, 143), module, VCO2::WAVE_PARAM, 0.0f, 3.0f, 1.5f)); - addParam(createParam(Vec(12, 208), module, VCO2::FM_PARAM, 0.0f, 1.0f, 0.0f)); + addParam(createParam(Vec(17, 60), module, VCO2::FREQ_PARAM)); + addParam(createParam(Vec(12, 143), module, VCO2::WAVE_PARAM)); + addParam(createParam(Vec(12, 208), module, VCO2::FM_PARAM)); - addInput(createPort(Vec(11, 276), PortWidget::INPUT, module, VCO2::FM_INPUT)); - addInput(createPort(Vec(54, 276), PortWidget::INPUT, module, VCO2::SYNC_INPUT)); - addInput(createPort(Vec(11, 320), PortWidget::INPUT, module, VCO2::WAVE_INPUT)); + addInput(createInput(Vec(11, 276), module, VCO2::FM_INPUT)); + addInput(createInput(Vec(54, 276), module, VCO2::SYNC_INPUT)); + addInput(createInput(Vec(11, 320), module, VCO2::WAVE_INPUT)); - addOutput(createPort(Vec(54, 320), PortWidget::OUTPUT, module, VCO2::OUT_OUTPUT)); + addOutput(createOutput(Vec(54, 320), module, VCO2::OUT_OUTPUT)); addChild(createLight>(Vec(68, 42.5f), module, VCO2::PHASE_POS_LIGHT)); }