AD.hpp (2419B)
1 #pragma once 2 3 #include "bogaudio.hpp" 4 #include "dsp/envelope.hpp" 5 #include "dsp/signal.hpp" 6 7 using namespace bogaudio::dsp; 8 9 extern Model* modelAD; 10 11 namespace bogaudio { 12 13 struct AD : BGModule { 14 enum ParamsIds { 15 ATTACK_PARAM, 16 DECAY_PARAM, 17 LOOP_PARAM, 18 LINEAR_PARAM, 19 RETRIGGER_PARAM, 20 NUM_PARAMS 21 }; 22 23 enum InputsIds { 24 TRIGGER_INPUT, 25 ATTACK_INPUT, 26 DECAY_INPUT, 27 NUM_INPUTS 28 }; 29 30 enum OutputsIds { 31 ENV_OUTPUT, 32 EOC_OUTPUT, 33 NUM_OUTPUTS 34 }; 35 36 enum LightsIds { 37 ATTACK_LIGHT, 38 DECAY_LIGHT, 39 NUM_LIGHTS 40 }; 41 42 struct Engine { 43 int modulationSteps; 44 Trigger trigger; 45 rack::dsp::PulseGenerator eocPulseGen; 46 bool on = false; 47 bogaudio::dsp::ADSR envelope; 48 bogaudio::dsp::SlewLimiter attackSL; 49 bogaudio::dsp::SlewLimiter decaySL; 50 51 Engine(int ms) : modulationSteps(ms) { 52 reset(); 53 sampleRateChange(); 54 envelope.setSustain(0.0f); 55 envelope.setRelease(0.0f); 56 } 57 void reset(); 58 void sampleRateChange(); 59 }; 60 Engine* _engines[maxChannels] {}; 61 bool _retriggerMode = true; 62 bool _loopMode = false; 63 bool _linearMode = false; 64 int _attackLightSum; 65 int _decayLightSum; 66 float _invert = 1.0f; 67 68 AD() { 69 config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); 70 configParam<EnvelopeSegmentParamQuantity>(ATTACK_PARAM, 0.0f, 1.0f, 0.141421f, "Attack", " s"); 71 configParam<EnvelopeSegmentParamQuantity>(DECAY_PARAM, 0.0f, 1.0f, SQUARE_ROOT_ONE_TENTH, "Decay", " s"); 72 configSwitch(LOOP_PARAM, 0.0f, 1.0f, 0.0f, "Loop", {"Disabled (stop)", "Enabled"}); 73 configSwitch(LINEAR_PARAM, 0.0f, 1.0f, 0.0f, "Linear", {"Disabled (logarithmic)", "Enabled"}); 74 configSwitch(RETRIGGER_PARAM, 0.0f, 1.0f, 1.0f, "Retrigger", {"Disabled (finish cycle)", "Enabled"}); 75 76 configInput(TRIGGER_INPUT, "Trigger"); 77 configInput(ATTACK_INPUT, "Attack CV"); 78 configInput(DECAY_INPUT, "Decay CV"); 79 80 configOutput(ENV_OUTPUT, "Envelope"); 81 configOutput(EOC_OUTPUT, "End-of-cycle trigger"); 82 } 83 84 void reset() override; 85 void sampleRateChange() override; 86 json_t* saveToJson(json_t* root) override; 87 void loadFromJson(json_t* root) override; 88 bool active() override; 89 int channels() override; 90 void addChannel(int c) override; 91 void removeChannel(int c) override; 92 void modulateChannel(int c) override; 93 void processAlways(const ProcessArgs& args) override; 94 void processChannel(const ProcessArgs& args, int c) override; 95 void postProcessAlways(const ProcessArgs& args) override; 96 }; 97 98 } // namespace bogaudio