You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.2KB

  1. #include "Follow.hpp"
  2. void Follow::onSampleRateChange() {
  3. _rms.setSampleRate(engineGetSampleRate());
  4. }
  5. void Follow::step() {
  6. if (inputs[IN_INPUT].active && outputs[OUT_OUTPUT].active) {
  7. float response = params[RESPONSE_PARAM].value;
  8. if (inputs[RESPONSE_INPUT].active) {
  9. response *= clamp(inputs[RESPONSE_INPUT].value / 10.f, 0.0f, 1.0f);
  10. }
  11. _rms.setSensitivity(response);
  12. float scale = params[SCALE_PARAM].value;
  13. if (inputs[SCALE_INPUT].active) {
  14. scale *= clamp(inputs[SCALE_INPUT].value / 5.0f, -1.0f, 1.0f);
  15. }
  16. outputs[OUT_OUTPUT].value = scale * 2.0f * _rms.next(inputs[IN_INPUT].value);
  17. }
  18. }
  19. struct FollowWidget : ModuleWidget {
  20. static constexpr int hp = 3;
  21. FollowWidget(Follow* module) : ModuleWidget(module) {
  22. box.size = Vec(RACK_GRID_WIDTH * hp, RACK_GRID_HEIGHT);
  23. {
  24. SVGPanel *panel = new SVGPanel();
  25. panel->box.size = box.size;
  26. panel->setBackground(SVG::load(assetPlugin(plugin, "res/Follow.svg")));
  27. addChild(panel);
  28. }
  29. addChild(Widget::create<ScrewSilver>(Vec(0, 0)));
  30. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 15, 365)));
  31. // generated by svg_widgets.rb
  32. auto responseParamPosition = Vec(8.0, 36.0);
  33. auto scaleParamPosition = Vec(8.0, 142.0);
  34. auto responseInputPosition = Vec(10.5, 77.0);
  35. auto scaleInputPosition = Vec(10.5, 183.0);
  36. auto inInputPosition = Vec(10.5, 233.0);
  37. auto outOutputPosition = Vec(10.5, 271.0);
  38. // end generated by svg_widgets.rb
  39. addParam(ParamWidget::create<Knob29>(responseParamPosition, module, Follow::RESPONSE_PARAM, 0.0, 1.0, 0.3));
  40. addParam(ParamWidget::create<Knob29>(scaleParamPosition, module, Follow::SCALE_PARAM, 0.0, 1.0, 1.0));
  41. addInput(Port::create<Port24>(responseInputPosition, Port::INPUT, module, Follow::RESPONSE_INPUT));
  42. addInput(Port::create<Port24>(scaleInputPosition, Port::INPUT, module, Follow::SCALE_INPUT));
  43. addInput(Port::create<Port24>(inInputPosition, Port::INPUT, module, Follow::IN_INPUT));
  44. addOutput(Port::create<Port24>(outOutputPosition, Port::OUTPUT, module, Follow::OUT_OUTPUT));
  45. }
  46. };
  47. RACK_PLUGIN_MODEL_INIT(Bogaudio, Follow) {
  48. Model *modelFollow = createModel<Follow, FollowWidget>("Bogaudio-Follow", "Follow", "envelope follower", ENVELOPE_FOLLOWER_TAG);
  49. return modelFollow;
  50. }