BogaudioModules

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

commit 10ea5e8e4b3f72ffa5e132e2093526386fb36f54
parent efbc27a00ea4cd2166760dff6baf217e4444eb93
Author: Matt Demanett <matt@demanett.net>
Date:   Mon,  1 Jan 2018 15:56:43 -0500

DGate: implement internals and remove experimental flag.

Diffstat:
Msrc/BogaudioModules.cpp | 2--
Msrc/DGate.cpp | 67++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 64 insertions(+), 5 deletions(-)

diff --git a/src/BogaudioModules.cpp b/src/BogaudioModules.cpp @@ -18,9 +18,7 @@ void init(rack::Plugin *p) { p->addModel(createModel<AnalyzerWidget>("Bogaudio", "Bogaudio-Analyzer", "Analyzer", VISUAL_TAG)); -#ifdef EXPERIMENTAL p->addModel(createModel<DGateWidget>("Bogaudio", "Bogaudio-DGate", "DGate", UTILITY_TAG)); -#endif p->addModel(createModel<ManualWidget>("Bogaudio", "Bogaudio-Manual", "Manual", UTILITY_TAG)); p->addModel(createModel<NoiseWidget>("Bogaudio", "Bogaudio-Noise", "Noise", NOISE_TAG, UTILITY_TAG)); p->addModel(createModel<OffsetWidget>("Bogaudio", "Bogaudio-Offset", "Offset", ATTENUATOR_TAG, UTILITY_TAG)); diff --git a/src/DGate.cpp b/src/DGate.cpp @@ -31,10 +31,11 @@ struct DGate : Module { enum Stage { STOPPED_STAGE, DELAY_STAGE, - ON_STAGE + GATE_STAGE }; SchmittTrigger _trigger; + PulseGenerator _triggerOuptutPulseGen; Stage _stage; float _stageProgress; @@ -44,17 +45,77 @@ struct DGate : Module { virtual void reset() override; virtual void step() override; + bool stepStage(Param& knob); }; void DGate::reset() { _trigger.reset(); + _triggerOuptutPulseGen.process(10.0); _stage = STOPPED_STAGE; _stageProgress = 0.0; } void DGate::step() { - outputs[GATE_OUTPUT].value = 0.0; - outputs[END_OUTPUT].value = 0.0; + float envelope = 0.0; + bool complete = false; + if (_trigger.process(params[TRIGGER_PARAM].value + inputs[TRIGGER_INPUT].value)) { + _stage = DELAY_STAGE; + _stageProgress = 0.0; + } + else { + switch (_stage) { + case STOPPED_STAGE: { + break; + } + case DELAY_STAGE: { + if (stepStage(params[DELAY_PARAM])) { + _stage = GATE_STAGE; + _stageProgress = 0.0; + } + break; + } + case GATE_STAGE: { + if (stepStage(params[GATE_PARAM])) { + complete = true; + if (params[LOOP_PARAM].value <= 0.0 || _trigger.isHigh()) { + if (params[DELAY_PARAM].value > 0.0) { + _stage = DELAY_STAGE; + } + else { + // _stage = GATE_STAGE; + envelope = 1.0; + } + _stageProgress = 0.0; + } + else { + _stage = STOPPED_STAGE; + } + } + else { + envelope = 1.0; + } + break; + } + } + } + + outputs[GATE_OUTPUT].value = envelope * 10.0; + if (complete) { + _triggerOuptutPulseGen.trigger(0.1); + } + outputs[END_OUTPUT].value = _triggerOuptutPulseGen.process(engineGetSampleTime()) ? 5.0 : 0.0; + + lights[DELAY_LIGHT].value = _stage == DELAY_STAGE; + lights[GATE_LIGHT].value = _stage == GATE_STAGE; +} + +bool DGate::stepStage(Param& knob) { + float t = clampf(knob.value, 0.0, 1.0); + t = pow(t, 2); + t = fmaxf(t, 0.001); + t *= 10.0; + _stageProgress += engineGetSampleTime() / t; + return _stageProgress > 1.0; }