DGate.hpp (1609B)
1 #pragma once 2 3 #include "bogaudio.hpp" 4 #include "trigger_on_load.hpp" 5 6 extern Model* modelDGate; 7 8 namespace bogaudio { 9 10 struct DGate : TriggerOnLoadModule { 11 enum ParamsIds { 12 DELAY_PARAM, 13 GATE_PARAM, 14 LOOP_PARAM, 15 TRIGGER_PARAM, 16 NUM_PARAMS 17 }; 18 19 enum InputsIds { 20 TRIGGER_INPUT, 21 NUM_INPUTS 22 }; 23 24 enum OutputsIds { 25 GATE_OUTPUT, 26 END_OUTPUT, 27 NUM_OUTPUTS 28 }; 29 30 enum LightsIds { 31 DELAY_LIGHT, 32 GATE_LIGHT, 33 NUM_LIGHTS 34 }; 35 36 enum Stage { 37 STOPPED_STAGE, 38 DELAY_STAGE, 39 GATE_STAGE 40 }; 41 42 struct Engine { 43 bool firstStep = true; 44 Trigger trigger; 45 rack::dsp::PulseGenerator triggerOuptutPulseGen; 46 Stage stage; 47 float stageProgress; 48 float delayLight; 49 float gateLight; 50 51 void reset(); 52 }; 53 54 Engine *_engines[maxChannels] {}; 55 56 DGate() { 57 config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); 58 configParam<EnvelopeSegmentParamQuantity>(DELAY_PARAM, 0.0f, 1.0f, 0.0f, "Delay", " s"); 59 configParam<EnvelopeSegmentParamQuantity>(GATE_PARAM, 0.0f, 1.0f, SQUARE_ROOT_ONE_TENTH, "Gate", " s"); 60 configSwitch(LOOP_PARAM, 0.0f, 1.0f, 1.0f, "Loop", {"Loop", "Stop"}); 61 configButton(TRIGGER_PARAM, "Trigger"); 62 63 configInput(TRIGGER_INPUT, "Trigger"); 64 65 configOutput(GATE_OUTPUT, "Gate"); 66 configOutput(END_OUTPUT, "End-of-cycle trigger"); 67 } 68 69 void reset() override; 70 int channels() override; 71 void addChannel(int c) override; 72 void removeChannel(int c) override; 73 void processChannel(const ProcessArgs& args, int c) override; 74 void postProcess(const ProcessArgs& args) override; 75 bool stepStage(int c, Param& knob); 76 bool shouldTriggerOnNextLoad() override; 77 }; 78 79 } // namespace bogaudio