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.

109 lines
3.2KB

  1. #include "Slew.hpp"
  2. void Slew::onReset() {
  3. _modulationStep = modulationSteps;
  4. }
  5. void Slew::step() {
  6. if (!(inputs[IN_INPUT].active && outputs[OUT_OUTPUT].active)) {
  7. return;
  8. }
  9. ++_modulationStep;
  10. if (_modulationStep >= modulationSteps) {
  11. _modulationStep = 0;
  12. float riseTime = time(params[RISE_PARAM], inputs[RISE_INPUT]);
  13. float riseShape = shape(params[RISE_SHAPE_PARAM]);
  14. float fallTime = time(params[FALL_PARAM], inputs[FALL_INPUT]);
  15. float fallShape = shape(params[FALL_SHAPE_PARAM]);
  16. _rise.setParams(engineGetSampleRate(), riseTime, riseShape);
  17. _fall.setParams(engineGetSampleRate(), fallTime, fallShape);
  18. }
  19. float sample = inputs[IN_INPUT].value;
  20. if (sample > _last) {
  21. if (!_rising) {
  22. _rising = true;
  23. _rise._last = _last;
  24. }
  25. outputs[OUT_OUTPUT].value = _last = _rise.next(sample);
  26. }
  27. else {
  28. if (_rising) {
  29. _rising = false;
  30. _fall._last = _last;
  31. }
  32. outputs[OUT_OUTPUT].value = _last = _fall.next(sample);
  33. }
  34. }
  35. float Slew::time(Param& param, Input& input) {
  36. float time = param.value;
  37. if (input.active) {
  38. time *= clamp(input.value / 10.0f, 0.0f, 1.0f);
  39. }
  40. return time * time * 10000.0f;
  41. }
  42. float Slew::shape(Param& param) {
  43. float shape = param.value;
  44. if (shape < 0.0) {
  45. shape = 1.0f + shape;
  46. shape = _rise.minShape + shape * (1.0f - _rise.minShape);
  47. }
  48. else {
  49. shape += 1.0f;
  50. }
  51. return shape;
  52. }
  53. struct SlewWidget : ModuleWidget {
  54. static constexpr int hp = 3;
  55. SlewWidget(Slew* module) : ModuleWidget(module) {
  56. box.size = Vec(RACK_GRID_WIDTH * hp, RACK_GRID_HEIGHT);
  57. {
  58. SVGPanel *panel = new SVGPanel();
  59. panel->box.size = box.size;
  60. panel->setBackground(SVG::load(assetPlugin(plugin, "res/Slew.svg")));
  61. addChild(panel);
  62. }
  63. addChild(Widget::create<ScrewSilver>(Vec(0, 0)));
  64. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 15, 365)));
  65. // generated by svg_widgets.rb
  66. auto riseParamPosition = Vec(9.5, 34.0);
  67. auto riseShapeParamPosition = Vec(14.5, 76.0);
  68. auto fallParamPosition = Vec(9.5, 155.0);
  69. auto fallShapeParamPosition = Vec(14.5, 197.0);
  70. auto riseInputPosition = Vec(10.5, 105.0);
  71. auto fallInputPosition = Vec(10.5, 226.0);
  72. auto inInputPosition = Vec(10.5, 263.0);
  73. auto outOutputPosition = Vec(10.5, 301.0);
  74. // end generated by svg_widgets.rb
  75. addParam(ParamWidget::create<Knob26>(riseParamPosition, module, Slew::RISE_PARAM, 0.0, 1.0, 0.316));
  76. addParam(ParamWidget::create<Knob16>(riseShapeParamPosition, module, Slew::RISE_SHAPE_PARAM, -1.0, 1.0, 0.0));
  77. addParam(ParamWidget::create<Knob26>(fallParamPosition, module, Slew::FALL_PARAM, 0.0, 1.0, 0.316));
  78. addParam(ParamWidget::create<Knob16>(fallShapeParamPosition, module, Slew::FALL_SHAPE_PARAM, -1.0, 1.0, 0.0));
  79. addInput(Port::create<Port24>(riseInputPosition, Port::INPUT, module, Slew::RISE_INPUT));
  80. addInput(Port::create<Port24>(fallInputPosition, Port::INPUT, module, Slew::FALL_INPUT));
  81. addInput(Port::create<Port24>(inInputPosition, Port::INPUT, module, Slew::IN_INPUT));
  82. addOutput(Port::create<Port24>(outOutputPosition, Port::OUTPUT, module, Slew::OUT_OUTPUT));
  83. }
  84. };
  85. RACK_PLUGIN_MODEL_INIT(Bogaudio, Slew) {
  86. Model *modelSlew = createModel<Slew, SlewWidget>("Bogaudio-Slew", "Slew", "slew / lag / glide", SLEW_LIMITER_TAG);
  87. return modelSlew;
  88. }