BogaudioModules

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

commit 408973946167b5c8d8a61ef1a184afb2fd5cefd7
parent 8e6137f3bec6c719fb390e899c00c57662941a90
Author: Matt Demanett <matt@demanett.net>
Date:   Tue, 10 Sep 2019 23:24:48 -0400

Poly: SLEW.

Diffstat:
Msrc/Slew.cpp | 48++++++++++++++++++++++++++++--------------------
Msrc/Slew.hpp | 20++++++++++++++------
2 files changed, 42 insertions(+), 26 deletions(-)

diff --git a/src/Slew.cpp b/src/Slew.cpp @@ -5,38 +5,46 @@ bool Slew::active() { return inputs[IN_INPUT].isConnected() && outputs[OUT_OUTPUT].isConnected(); } +int Slew::channels() { + return inputs[IN_INPUT].getChannels(); +} + void Slew::modulate() { - float riseTime = time(params[RISE_PARAM], inputs[RISE_INPUT]); - float riseShape = shape(params[RISE_SHAPE_PARAM]); - float fallTime = time(params[FALL_PARAM], inputs[FALL_INPUT]); - float fallShape = shape(params[FALL_SHAPE_PARAM]); + _riseShape = shape(params[RISE_SHAPE_PARAM]); + _fallShape = shape(params[FALL_SHAPE_PARAM]); +} - _rise.setParams(APP->engine->getSampleRate(), riseTime, riseShape); - _fall.setParams(APP->engine->getSampleRate(), fallTime, fallShape); +void Slew::modulateChannel(int c) { + float riseTime = time(params[RISE_PARAM], inputs[RISE_INPUT], c); + float fallTime = time(params[FALL_PARAM], inputs[FALL_INPUT], c); + _rise[c].setParams(APP->engine->getSampleRate(), riseTime, _riseShape); + _fall[c].setParams(APP->engine->getSampleRate(), fallTime, _fallShape); } -void Slew::processChannel(const ProcessArgs& args, int _c) { - float sample = inputs[IN_INPUT].getVoltageSum(); - if (sample > _last) { - if (!_rising) { - _rising = true; - _rise._last = _last; +void Slew::processChannel(const ProcessArgs& args, int c) { + float sample = inputs[IN_INPUT].getPolyVoltage(c); + + outputs[OUT_OUTPUT].setChannels(_channels); + if (sample > _last[c]) { + if (!_rising[c]) { + _rising[c] = true; + _rise[c]._last = _last[c]; } - outputs[OUT_OUTPUT].setVoltage(_last = _rise.next(sample)); + outputs[OUT_OUTPUT].setVoltage(_last[c] = _rise[c].next(sample), c); } else { - if (_rising) { - _rising = false; - _fall._last = _last; + if (_rising[c]) { + _rising[c] = false; + _fall[c]._last = _last[c]; } - outputs[OUT_OUTPUT].setVoltage(_last = _fall.next(sample)); + outputs[OUT_OUTPUT].setVoltage(_last[c] = _fall[c].next(sample), c); } } -float Slew::time(Param& param, Input& input) { +float Slew::time(Param& param, Input& input, int c) { float time = param.getValue(); if (input.isConnected()) { - time *= clamp(input.getVoltage() / 10.0f, 0.0f, 1.0f); + time *= clamp(input.getPolyVoltage(c) / 10.0f, 0.0f, 1.0f); } return time * time * 10000.0f; } @@ -45,7 +53,7 @@ float Slew::shape(Param& param) { float shape = param.getValue(); if (shape < 0.0) { shape = 1.0f + shape; - shape = _rise.minShape + shape * (1.0f - _rise.minShape); + shape = _rise[0].minShape + shape * (1.0f - _rise[0].minShape); } else { shape += 1.0f; diff --git a/src/Slew.hpp b/src/Slew.hpp @@ -34,10 +34,12 @@ struct Slew : BGModule { NUM_LIGHTS }; - bool _rising = true; - float _last = 0.0f; - ShapedSlewLimiter _rise; - ShapedSlewLimiter _fall; + float _riseShape = 0.0f; + float _fallShape = 0.0f; + bool _rising[maxChannels]; + float _last[maxChannels] {}; + ShapedSlewLimiter _rise[maxChannels]; + ShapedSlewLimiter _fall[maxChannels]; Slew() { config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); @@ -45,12 +47,18 @@ struct Slew : BGModule { configParam(RISE_SHAPE_PARAM, -1.0f, 1.0f, 0.0f, "Rise shape"); configParam<EnvelopeSegmentParamQuantity>(FALL_PARAM, 0.0f, 1.0f, 0.31623f, "Fall", " s"); configParam(FALL_SHAPE_PARAM, -1.0f, 1.0f, 0.0f, "Fall shape"); + + for (int i = 0; i < maxChannels; ++i) { + _rising[i] = true; + } } bool active() override; + int channels() override; void modulate() override; - void processChannel(const ProcessArgs& args, int _c) override; - float time(Param& param, Input& input); + void modulateChannel(int c) override; + void processChannel(const ProcessArgs& args, int c) override; + float time(Param& param, Input& input, int c); float shape(Param& param); };