BogaudioModules

BogaudioModules for VCV Rack
Log | Files | Refs | README | LICENSE

commit 8e6137f3bec6c719fb390e899c00c57662941a90
parent 9747048ee56c90c04b45d99c9cdc1b88e6908317
Author: Matt Demanett <matt@demanett.net>
Date:   Tue, 10 Sep 2019 23:02:57 -0400

Poly: CVD.

Diffstat:
Msrc/CVD.cpp | 74+++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------
Msrc/CVD.hpp | 25+++++++++++++++++++------
2 files changed, 72 insertions(+), 27 deletions(-)

diff --git a/src/CVD.cpp b/src/CVD.cpp @@ -2,35 +2,67 @@ #include "CVD.hpp" void CVD::sampleRateChange() { - _delay.setSampleRate(APP->engine->getSampleRate()); + for (int i = 0; i < _channels; ++i) { + if (_engines[i]) { + _engines[i]->delay.setSampleRate(APP->engine->getSampleRate()); + } + } } -void CVD::processChannel(const ProcessArgs& args, int _c) { - float time = params[TIME_PARAM].getValue(); - if (inputs[TIME_INPUT].isConnected()) { - time *= clamp(inputs[TIME_INPUT].getVoltage() / 10.0f, 0.0f, 1.0f); - } - switch ((int)roundf(params[TIME_SCALE_PARAM].getValue())) { - case 0: { - time /= 100.f; - break; +int CVD::channels() { + return inputs[IN_INPUT].getChannels(); +} + +void CVD::channelsChanged(int before, int after) { + if (before < after) { + while (before < after) { + _engines[before] = new Engine(); + _engines[before]->delay.setSampleRate(APP->engine->getSampleRate()); + ++before; } - case 1: { - time /= 10.f; - break; + } + else { + while (after > before) { + delete _engines[after - 1]; + _engines[after - 1] = NULL; + ++after; } } - _delay.setTime(time); +} - float mix = params[MIX_PARAM].getValue(); - if (inputs[MIX_INPUT].isConnected()) { - mix = clamp(mix + inputs[MIX_INPUT].getVoltage() / 5.0f, -1.0f, 1.0f); +void CVD::modulateChannel(int c) { + if (_engines[c]) { + float time = params[TIME_PARAM].getValue(); + if (inputs[TIME_INPUT].isConnected()) { + time *= clamp(inputs[TIME_INPUT].getPolyVoltage(c) / 10.0f, 0.0f, 1.0f); + } + switch ((int)roundf(params[TIME_SCALE_PARAM].getValue())) { + case 0: { + time /= 100.f; + break; + } + case 1: { + time /= 10.f; + break; + } + } + _engines[c]->delay.setTime(time); + + float mix = params[MIX_PARAM].getValue(); + if (inputs[MIX_INPUT].isConnected()) { + mix = clamp(mix + inputs[MIX_INPUT].getPolyVoltage(c) / 5.0f, -1.0f, 1.0f); + } + _engines[c]->mix.setParams(mix); } - _mix.setParams(mix); +} - float in = inputs[IN_INPUT].getVoltage(); - float delayed = _delay.next(in); - outputs[OUT_OUTPUT].setVoltage(_mix.next(in, delayed)); +void CVD::processChannel(const ProcessArgs& args, int c) { + if (_engines[c]) { + float in = inputs[IN_INPUT].getPolyVoltage(c); + float delayed = _engines[c]->delay.next(in); + outputs[OUT_OUTPUT].setChannels(_channels); + outputs[OUT_OUTPUT].setVoltage(_engines[c]->mix.next(in, delayed), c); + } } struct CVDWidget : ModuleWidget { diff --git a/src/CVD.hpp b/src/CVD.hpp @@ -33,12 +33,15 @@ struct CVD : BGModule { NUM_LIGHTS }; - DelayLine _delay; - CrossFader _mix; + struct Engine { + DelayLine delay; + CrossFader mix; - CVD() - : _delay(1000.0f, 10000.0f) - { + Engine() : delay(1000.0f, 10000.0f) {} + }; + Engine* _engines[maxChannels] {}; + + CVD() { config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); configParam(TIME_PARAM, 0.0f, 1.0f, 0.5f, "Time base"); configParam(TIME_SCALE_PARAM, 0.0f, 2.0f, 1.0f, "Time scale", "", 10.0f, 0.1f); @@ -46,9 +49,19 @@ struct CVD : BGModule { sampleRateChange(); } + virtual ~CVD() { + for (int i = 0; i < maxChannels; ++i) { + if (_engines[i]) { + delete _engines[i]; + } + } + } void sampleRateChange() override; - void processChannel(const ProcessArgs& args, int _c) override; + int channels() override; + void channelsChanged(int before, int after) override; + void modulateChannel(int c) override; + void processChannel(const ProcessArgs& args, int c) override; }; } // namespace bogaudio