#include "Follow.hpp" void Follow::onSampleRateChange() { _rms.setSampleRate(engineGetSampleRate()); } void Follow::step() { if (inputs[IN_INPUT].active && outputs[OUT_OUTPUT].active) { float response = params[RESPONSE_PARAM].value; if (inputs[RESPONSE_INPUT].active) { response *= clamp(inputs[RESPONSE_INPUT].value / 10.f, 0.0f, 1.0f); } _rms.setSensitivity(response); float scale = params[SCALE_PARAM].value; if (inputs[SCALE_INPUT].active) { scale *= clamp(inputs[SCALE_INPUT].value / 5.0f, -1.0f, 1.0f); } outputs[OUT_OUTPUT].value = scale * 2.0f * _rms.next(inputs[IN_INPUT].value); } } struct FollowWidget : ModuleWidget { static constexpr int hp = 3; FollowWidget(Follow* 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/Follow.svg"))); addChild(panel); } addChild(Widget::create(Vec(0, 0))); addChild(Widget::create(Vec(box.size.x - 15, 365))); // generated by svg_widgets.rb auto responseParamPosition = Vec(8.0, 36.0); auto scaleParamPosition = Vec(8.0, 142.0); auto responseInputPosition = Vec(10.5, 77.0); auto scaleInputPosition = Vec(10.5, 183.0); auto inInputPosition = Vec(10.5, 233.0); auto outOutputPosition = Vec(10.5, 271.0); // end generated by svg_widgets.rb addParam(ParamWidget::create(responseParamPosition, module, Follow::RESPONSE_PARAM, 0.0, 1.0, 0.3)); addParam(ParamWidget::create(scaleParamPosition, module, Follow::SCALE_PARAM, 0.0, 1.0, 1.0)); addInput(Port::create(responseInputPosition, Port::INPUT, module, Follow::RESPONSE_INPUT)); addInput(Port::create(scaleInputPosition, Port::INPUT, module, Follow::SCALE_INPUT)); addInput(Port::create(inInputPosition, Port::INPUT, module, Follow::IN_INPUT)); addOutput(Port::create(outOutputPosition, Port::OUTPUT, module, Follow::OUT_OUTPUT)); } }; RACK_PLUGIN_MODEL_INIT(Bogaudio, Follow) { Model *modelFollow = createModel("Bogaudio-Follow", "Follow", "envelope follower", ENVELOPE_FOLLOWER_TAG); return modelFollow; }