|
-
- #include "Slew.hpp"
-
- void Slew::onReset() {
- _modulationStep = modulationSteps;
- }
-
- void Slew::step() {
- if (!(inputs[IN_INPUT].active && outputs[OUT_OUTPUT].active)) {
- return;
- }
-
- ++_modulationStep;
- if (_modulationStep >= modulationSteps) {
- _modulationStep = 0;
-
- float riseTime = time(params[RISE_PARAM], inputs[RISE_INPUT]);
- float riseShape = shape(params[RISE_SHAPE_PARAM]);
- float fallTime = time(params[FALL_PARAM], inputs[FALL_INPUT]);
- float fallShape = shape(params[FALL_SHAPE_PARAM]);
-
- _rise.setParams(engineGetSampleRate(), riseTime, riseShape);
- _fall.setParams(engineGetSampleRate(), fallTime, fallShape);
- }
-
- float sample = inputs[IN_INPUT].value;
- if (sample > _last) {
- if (!_rising) {
- _rising = true;
- _rise._last = _last;
- }
- outputs[OUT_OUTPUT].value = _last = _rise.next(sample);
- }
- else {
- if (_rising) {
- _rising = false;
- _fall._last = _last;
- }
- outputs[OUT_OUTPUT].value = _last = _fall.next(sample);
- }
- }
-
- float Slew::time(Param& param, Input& input) {
- float time = param.value;
- if (input.active) {
- time *= clamp(input.value / 10.0f, 0.0f, 1.0f);
- }
- return time * time * 10000.0f;
- }
-
- float Slew::shape(Param& param) {
- float shape = param.value;
- if (shape < 0.0) {
- shape = 1.0f + shape;
- shape = _rise.minShape + shape * (1.0f - _rise.minShape);
- }
- else {
- shape += 1.0f;
- }
- return shape;
- }
-
- struct SlewWidget : ModuleWidget {
- static constexpr int hp = 3;
-
- SlewWidget(Slew* module) : ModuleWidget(module) {
- box.size = Vec(RACK_GRID_WIDTH * hp, RACK_GRID_HEIGHT);
-
- {
- SVGPanel *panel = new SVGPanel();
- panel->box.size = box.size;
- panel->setBackground(SVG::load(assetPlugin(plugin, "res/Slew.svg")));
- addChild(panel);
- }
-
- addChild(Widget::create<ScrewSilver>(Vec(0, 0)));
- addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 15, 365)));
-
- // generated by svg_widgets.rb
- auto riseParamPosition = Vec(9.5, 34.0);
- auto riseShapeParamPosition = Vec(14.5, 76.0);
- auto fallParamPosition = Vec(9.5, 155.0);
- auto fallShapeParamPosition = Vec(14.5, 197.0);
-
- auto riseInputPosition = Vec(10.5, 105.0);
- auto fallInputPosition = Vec(10.5, 226.0);
- auto inInputPosition = Vec(10.5, 263.0);
-
- auto outOutputPosition = Vec(10.5, 301.0);
- // end generated by svg_widgets.rb
-
- addParam(ParamWidget::create<Knob26>(riseParamPosition, module, Slew::RISE_PARAM, 0.0, 1.0, 0.316));
- addParam(ParamWidget::create<Knob16>(riseShapeParamPosition, module, Slew::RISE_SHAPE_PARAM, -1.0, 1.0, 0.0));
- addParam(ParamWidget::create<Knob26>(fallParamPosition, module, Slew::FALL_PARAM, 0.0, 1.0, 0.316));
- addParam(ParamWidget::create<Knob16>(fallShapeParamPosition, module, Slew::FALL_SHAPE_PARAM, -1.0, 1.0, 0.0));
-
- addInput(Port::create<Port24>(riseInputPosition, Port::INPUT, module, Slew::RISE_INPUT));
- addInput(Port::create<Port24>(fallInputPosition, Port::INPUT, module, Slew::FALL_INPUT));
- addInput(Port::create<Port24>(inInputPosition, Port::INPUT, module, Slew::IN_INPUT));
-
- addOutput(Port::create<Port24>(outOutputPosition, Port::OUTPUT, module, Slew::OUT_OUTPUT));
- }
- };
-
- RACK_PLUGIN_MODEL_INIT(Bogaudio, Slew) {
- Model *modelSlew = createModel<Slew, SlewWidget>("Bogaudio-Slew", "Slew", "slew / lag / glide", SLEW_LIMITER_TAG);
- return modelSlew;
- }
|