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.

104 lines
2.9KB

  1. #include "Lag.hpp"
  2. void Lag::onReset() {
  3. _modulationStep = modulationSteps;
  4. }
  5. void Lag::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 time = params[TIME_PARAM].value;
  13. if (inputs[TIME_INPUT].active) {
  14. time *= clamp(inputs[TIME_INPUT].value / 10.0f, 0.0f, 1.0f);
  15. }
  16. switch ((int)params[TIME_SCALE_PARAM].value) {
  17. case 0: {
  18. time /= 10.f;
  19. break;
  20. }
  21. case 2: {
  22. time *= 10.f;
  23. break;
  24. }
  25. }
  26. time *= 1000.0f;
  27. float shape = params[SHAPE_PARAM].value;
  28. if (inputs[SHAPE_INPUT].active) {
  29. shape *= clamp(inputs[SHAPE_INPUT].value / 5.0f, -1.0f, 1.0f);
  30. }
  31. if (shape < 0.0) {
  32. shape = 1.0f + shape;
  33. shape = _slew.minShape + shape * (1.0f - _slew.minShape);
  34. }
  35. else {
  36. shape *= _slew.maxShape - 1.0f;
  37. shape += 1.0f;
  38. }
  39. _slew.setParams(engineGetSampleRate(), time, shape);
  40. }
  41. outputs[OUT_OUTPUT].value = _slew.next(inputs[IN_INPUT].value);
  42. }
  43. struct LagWidget : ModuleWidget {
  44. static constexpr int hp = 3;
  45. LagWidget(Lag* module) : ModuleWidget(module) {
  46. box.size = Vec(RACK_GRID_WIDTH * hp, RACK_GRID_HEIGHT);
  47. {
  48. SVGPanel *panel = new SVGPanel();
  49. panel->box.size = box.size;
  50. panel->setBackground(SVG::load(assetPlugin(plugin, "res/Lag.svg")));
  51. addChild(panel);
  52. }
  53. addChild(Widget::create<ScrewSilver>(Vec(0, 0)));
  54. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 15, 365)));
  55. // generated by svg_widgets.rb
  56. auto timeParamPosition = Vec(8.0, 36.0);
  57. auto timeScaleParamPosition = Vec(14.5, 84.0);
  58. auto shapeParamPosition = Vec(8.0, 176.0);
  59. auto timeInputPosition = Vec(10.5, 107.0);
  60. auto shapeInputPosition = Vec(10.5, 217.0);
  61. auto inInputPosition = Vec(10.5, 267.0);
  62. auto outOutputPosition = Vec(10.5, 305.0);
  63. // end generated by svg_widgets.rb
  64. addParam(ParamWidget::create<Knob29>(timeParamPosition, module, Lag::TIME_PARAM, 0.0, 1.0, 0.5));
  65. {
  66. auto w = ParamWidget::create<Knob16>(timeScaleParamPosition, module, Lag::TIME_SCALE_PARAM, 0.0, 2.0, 1.0);
  67. auto k = dynamic_cast<SVGKnob*>(w);
  68. k->snap = true;
  69. k->minAngle = -M_PI / 4.0f;
  70. k->maxAngle = M_PI / 4.0f;
  71. k->speed = 3.0;
  72. addParam(w);
  73. }
  74. addParam(ParamWidget::create<Knob29>(shapeParamPosition, module, Lag::SHAPE_PARAM, -1.0, 1.0, 0.0));
  75. addInput(Port::create<Port24>(timeInputPosition, Port::INPUT, module, Lag::TIME_INPUT));
  76. addInput(Port::create<Port24>(shapeInputPosition, Port::INPUT, module, Lag::SHAPE_INPUT));
  77. addInput(Port::create<Port24>(inInputPosition, Port::INPUT, module, Lag::IN_INPUT));
  78. addOutput(Port::create<Port24>(outOutputPosition, Port::OUTPUT, module, Lag::OUT_OUTPUT));
  79. }
  80. };
  81. RACK_PLUGIN_MODEL_INIT(Bogaudio, Lag) {
  82. Model *modelLag = createModel<Lag, LagWidget>("Bogaudio-Lag", "Lag", "slew limiter / lag processor", SLEW_LIMITER_TAG);
  83. return modelLag;
  84. }