| 252 | } |
| 253 | |
| 254 | void process(const ProcessArgs& args) override { |
| 255 | |
| 256 | |
| 257 | if (cvDivider.process()) { |
| 258 | shape = params[SHAPE_PARAM].getValue(); |
| 259 | envelope.decayShape = 1.f + shape; |
| 260 | envelope.attackShape = 1.f - shape / 2.f; |
| 261 | envelope.releaseShape = 1.f + shape; |
| 262 | |
| 263 | const float attackCV = clamp(params[ATTACK_PARAM].getValue() + inputs[CV_ATTACK_INPUT].getVoltage() / 10.f, 0.f, 1.f); |
| 264 | envelope.attackTime = convertCVToTimeInSeconds(attackCV); |
| 265 | |
| 266 | const float decayCV = clamp(params[DECAY_PARAM].getValue() + inputs[CV_DECAY_INPUT].getVoltage() / 10.f, 0.f, 1.f); |
| 267 | envelope.decayTime = convertCVToTimeInSeconds(decayCV); |
| 268 | |
| 269 | const float sustainCV = clamp(params[SUSTAIN_PARAM].getValue() + inputs[CV_SUSTAIN_INPUT].getVoltage() / 10.f, 0.f, 1.f); |
| 270 | envelope.sustainLevel = sustainCV; |
| 271 | |
| 272 | const float releaseCV = clamp(params[RELEASE_PARAM].getValue() + inputs[CV_RELEASE_INPUT].getVoltage() / 10.f, 0.f, 1.f); |
| 273 | envelope.releaseTime = convertCVToTimeInSeconds(releaseCV); |
| 274 | } |
| 275 | |
| 276 | const bool triggered = gateTrigger.process(rescale(params[MANUAL_TRIGGER_PARAM].getValue() * 10.f + inputs[TRIGGER_INPUT].getVoltage(), 0.1f, 2.f, 0.f, 1.f)); |
| 277 | const bool gateOn = gateTrigger.isHigh() || params[MANUAL_TRIGGER_PARAM].getValue(); |
| 278 | const bool triggerMode = params[TRIGG_GATE_TOGGLE_PARAM].getValue() == 1; |
| 279 | |
| 280 | if (triggerMode) { |
| 281 | if (triggered) { |
| 282 | envelope.retrigger(); |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | envelope.process(args.sampleTime, gateOn, triggerMode); |
| 287 | |
| 288 | outputs[OUT_OUTPUT].setVoltage(envelope.env * 10.f); |
| 289 | |
| 290 | outputs[STAGE_ATTACK_OUTPUT].setVoltage(10.f * (envelope.stage == BefacoADSREnvelope::STAGE_ATTACK)); |
| 291 | outputs[STAGE_DECAY_OUTPUT].setVoltage(10.f * (envelope.stage == BefacoADSREnvelope::STAGE_DECAY)); |
| 292 | outputs[STAGE_SUSTAIN_OUTPUT].setVoltage(10.f * (envelope.stage == BefacoADSREnvelope::STAGE_SUSTAIN)); |
| 293 | outputs[STAGE_RELEASE_OUTPUT].setVoltage(10.f * (envelope.stage == BefacoADSREnvelope::STAGE_RELEASE)); |
| 294 | |
| 295 | lights[LED_ATTACK_LIGHT].setBrightness((envelope.stage == BefacoADSREnvelope::STAGE_ATTACK)); |
| 296 | lights[LED_DECAY_LIGHT].setBrightness((envelope.stage == BefacoADSREnvelope::STAGE_DECAY)); |
| 297 | lights[LED_SUSTAIN_LIGHT].setBrightness((envelope.stage == BefacoADSREnvelope::STAGE_SUSTAIN)); |
| 298 | lights[LED_RELEASE_LIGHT].setBrightness((envelope.stage == BefacoADSREnvelope::STAGE_RELEASE)); |
| 299 | lights[LED_LIGHT].setBrightness((float) gateOn); |
| 300 | } |
| 301 | }; |
| 302 | |
| 303 | |