BogaudioModules

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

commit 5e0d39c205a97068fb668330091d2a71f7be547a
parent 48d03247a04906c61b303497b768f8b3b9b47846
Author: Matt Demanett <matt@demanett.net>
Date:   Sun,  9 Jan 2022 21:39:49 -0500

S&H: fix glide for poly channels. #197

Diffstat:
Msrc/SampleHold.cpp | 62++++++++++++++++++++++++++++++++++++++++++++++----------------
Msrc/SampleHold.hpp | 15+++++++++++++--
2 files changed, 59 insertions(+), 18 deletions(-)

diff --git a/src/SampleHold.cpp b/src/SampleHold.cpp @@ -52,13 +52,23 @@ void SampleHold::loadFromJson(json_t* root) { } } -void SampleHold::modulateChannel(int c) { - _outputSL1[c].setParams(APP->engine->getSampleRate(), _smoothMS, 10.0f); - _outputSL2[c].setParams(APP->engine->getSampleRate(), _smoothMS, 10.0f); +void SampleHold::modulate() { + modulateSection( + inputs[TRIGGER1_INPUT], + NULL, + inputs[IN1_INPUT], + _outputSL1 + ); + modulateSection( + inputs[TRIGGER2_INPUT], + &inputs[TRIGGER1_INPUT], + inputs[IN2_INPUT], + _outputSL2 + ); } void SampleHold::processAll(const ProcessArgs& args) { - handleChannel( + processSection( params[TRACK1_PARAM], params[INVERT1_PARAM], _trigger1, @@ -70,7 +80,7 @@ void SampleHold::processAll(const ProcessArgs& args) { _outputSL1, outputs[OUT1_OUTPUT] ); - handleChannel( + processSection( params[TRACK2_PARAM], params[INVERT2_PARAM], _trigger2, @@ -84,19 +94,12 @@ void SampleHold::processAll(const ProcessArgs& args) { ); } -void SampleHold::handleChannel( - Param& trackParam, - Param& invertParam, - Trigger* trigger, - Param& triggerParam, +int SampleHold::sectionChannels( Input& triggerInput, Input* altTriggerInput, - Input& in, - float* value, - SlewLimiter* outputSL, - Output& out + Input& in ) { - int n = 0; + int n = 1; if (_polyInputID == IN1_INPUT) { n = in.getChannels(); } @@ -105,7 +108,34 @@ void SampleHold::handleChannel( } else if (altTriggerInput) { n = altTriggerInput->getChannels(); } - n = std::max(1, n); + return n; +} + +void SampleHold::modulateSection( + Input& triggerInput, + Input* altTriggerInput, + Input& in, + SlewLimiter* outputSL +) { + int n = sectionChannels(triggerInput, altTriggerInput, in); + for (int i = 0; i < n; ++i) { + outputSL[i].setParams(APP->engine->getSampleRate(), _smoothMS, 10.0f); + } +} + +void SampleHold::processSection( + Param& trackParam, + Param& invertParam, + Trigger* trigger, + Param& triggerParam, + Input& triggerInput, + Input* altTriggerInput, + Input& in, + float* value, + SlewLimiter* outputSL, + Output& out +) { + int n = sectionChannels(triggerInput, altTriggerInput, in); out.setChannels(n); for (int i = 0; i < n; ++i) { diff --git a/src/SampleHold.hpp b/src/SampleHold.hpp @@ -77,9 +77,20 @@ struct SampleHold : BGModule { void reset() override; json_t* saveToJson(json_t* root) override; void loadFromJson(json_t* root) override; - void modulateChannel(int c) override; + void modulate() override; void processAll(const ProcessArgs& args) override; - void handleChannel( + int sectionChannels( + Input& triggerInput, + Input* altTriggerInput, + Input& in + ); + void modulateSection( + Input& triggerInput, + Input* altTriggerInput, + Input& in, + SlewLimiter* _outputSL + ); + void processSection( Param& trackParam, Param& invertParam, Trigger* trigger,