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.

158 lines
5.0KB

  1. #include "LLFO.hpp"
  2. #include "dsp/pitch.hpp"
  3. void LLFO::onReset() {
  4. _resetTrigger.reset();
  5. _modulationStep = modulationSteps;
  6. }
  7. void LLFO::onSampleRateChange() {
  8. _phasor.setSampleRate(engineGetSampleRate());
  9. _modulationStep = modulationSteps;
  10. }
  11. void LLFO::step() {
  12. lights[SLOW_LIGHT].value = _slowMode = params[SLOW_PARAM].value > 0.5f;
  13. lights[SINE_LIGHT].value = _wave == SINE_WAVE;
  14. lights[TRIANGLE_LIGHT].value = _wave == TRIANGLE_WAVE;
  15. lights[RAMP_UP_LIGHT].value = _wave == RAMP_UP_WAVE;
  16. lights[RAMP_DOWN_LIGHT].value = _wave == RAMP_DOWN_WAVE;
  17. lights[SQUARE_LIGHT].value = _wave == SQUARE_WAVE;
  18. lights[PULSE_LIGHT].value = _wave == PULSE_WAVE;
  19. if (!outputs[OUT_OUTPUT].active) {
  20. return;
  21. }
  22. ++_modulationStep;
  23. if (_modulationStep >= modulationSteps) {
  24. _modulationStep = 0;
  25. float frequency = params[FREQUENCY_PARAM].value;
  26. if (inputs[PITCH_INPUT].active) {
  27. frequency += inputs[PITCH_INPUT].value;
  28. }
  29. if (_slowMode) {
  30. frequency -= 8.0f;
  31. }
  32. else {
  33. frequency -= 4.0f;
  34. }
  35. frequency = cvToFrequency(frequency);
  36. if (frequency > 2000.0f) {
  37. frequency = 2000.0f;
  38. }
  39. _phasor.setFrequency(frequency);
  40. _wave = (Wave)int32_t(params[WAVE_PARAM].value);
  41. _invert = false;
  42. switch (_wave) {
  43. case SINE_WAVE: {
  44. _oscillator = &_sine;
  45. break;
  46. }
  47. case TRIANGLE_WAVE: {
  48. _oscillator = &_triangle;
  49. break;
  50. }
  51. case RAMP_UP_WAVE: {
  52. _oscillator = &_ramp;
  53. break;
  54. }
  55. case RAMP_DOWN_WAVE: {
  56. _oscillator = &_ramp;
  57. _invert = true;
  58. break;
  59. }
  60. case SQUARE_WAVE: {
  61. _oscillator = &_square;
  62. _square.setPulseWidth(0.5f);
  63. break;
  64. }
  65. case PULSE_WAVE: {
  66. _oscillator = &_square;
  67. _square.setPulseWidth(0.1f);
  68. break;
  69. }
  70. }
  71. _offset = params[OFFSET_PARAM].value * 5.0f;
  72. _scale = params[SCALE_PARAM].value;
  73. }
  74. if (_resetTrigger.next(inputs[RESET_INPUT].value)) {
  75. _phasor.resetPhase();
  76. }
  77. _phasor.advancePhase();
  78. float sample = _oscillator->nextFromPhasor(_phasor) * amplitude * _scale;
  79. if (_invert) {
  80. sample = -sample;
  81. }
  82. sample += _offset;
  83. outputs[OUT_OUTPUT].value = sample;
  84. }
  85. struct LLFOWidget : ModuleWidget {
  86. static constexpr int hp = 3;
  87. LLFOWidget(LLFO* module) : ModuleWidget(module) {
  88. box.size = Vec(RACK_GRID_WIDTH * hp, RACK_GRID_HEIGHT);
  89. {
  90. SVGPanel *panel = new SVGPanel();
  91. panel->box.size = box.size;
  92. panel->setBackground(SVG::load(assetPlugin(plugin, "res/LLFO.svg")));
  93. addChild(panel);
  94. }
  95. addChild(Widget::create<ScrewSilver>(Vec(0, 0)));
  96. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 15, 365)));
  97. // generated by svg_widgets.rb
  98. auto frequencyParamPosition = Vec(9.5, 27.0);
  99. auto slowParamPosition = Vec(34.0, 71.0);
  100. auto waveParamPosition = Vec(18.0, 126.0);
  101. auto offsetParamPosition = Vec(14.5, 158.5);
  102. auto scaleParamPosition = Vec(14.5, 199.5);
  103. auto pitchInputPosition = Vec(10.5, 231.0);
  104. auto resetInputPosition = Vec(10.5, 266.0);
  105. auto outOutputPosition = Vec(10.5, 304.0);
  106. auto slowLightPosition = Vec(2.0, 72.0);
  107. auto sineLightPosition = Vec(2.0, 89.0);
  108. auto rampUpLightPosition = Vec(2.0, 102.0);
  109. auto squareLightPosition = Vec(2.0, 115.0);
  110. auto triangleLightPosition = Vec(24.0, 89.0);
  111. auto rampDownLightPosition = Vec(24.0, 102.0);
  112. auto pulseLightPosition = Vec(24.0, 115.0);
  113. // end generated by svg_widgets.rb
  114. addParam(ParamWidget::create<Knob26>(frequencyParamPosition, module, LLFO::FREQUENCY_PARAM, -8.0, 5.0, 0.0));
  115. addParam(ParamWidget::create<StatefulButton9>(slowParamPosition, module, LLFO::SLOW_PARAM, 0.0, 1.0, 0.0));
  116. addParam(ParamWidget::create<StatefulButton9>(waveParamPosition, module, LLFO::WAVE_PARAM, 0.0, 5.0, 0.0));
  117. addParam(ParamWidget::create<Knob16>(offsetParamPosition, module, LLFO::OFFSET_PARAM, -1.0, 1.0, 0.0));
  118. addParam(ParamWidget::create<Knob16>(scaleParamPosition, module, LLFO::SCALE_PARAM, 0.0, 1.0, 1.0));
  119. addInput(Port::create<Port24>(pitchInputPosition, Port::INPUT, module, LLFO::PITCH_INPUT));
  120. addInput(Port::create<Port24>(resetInputPosition, Port::INPUT, module, LLFO::RESET_INPUT));
  121. addOutput(Port::create<Port24>(outOutputPosition, Port::OUTPUT, module, LLFO::OUT_OUTPUT));
  122. addChild(ModuleLightWidget::create<SmallLight<GreenLight>>(slowLightPosition, module, LLFO::SLOW_LIGHT));
  123. addChild(ModuleLightWidget::create<SmallLight<GreenLight>>(sineLightPosition, module, LLFO::SINE_LIGHT));
  124. addChild(ModuleLightWidget::create<SmallLight<GreenLight>>(rampUpLightPosition, module, LLFO::RAMP_UP_LIGHT));
  125. addChild(ModuleLightWidget::create<SmallLight<GreenLight>>(squareLightPosition, module, LLFO::SQUARE_LIGHT));
  126. addChild(ModuleLightWidget::create<SmallLight<GreenLight>>(triangleLightPosition, module, LLFO::TRIANGLE_LIGHT));
  127. addChild(ModuleLightWidget::create<SmallLight<GreenLight>>(rampDownLightPosition, module, LLFO::RAMP_DOWN_LIGHT));
  128. addChild(ModuleLightWidget::create<SmallLight<GreenLight>>(pulseLightPosition, module, LLFO::PULSE_LIGHT));
  129. }
  130. };
  131. RACK_PLUGIN_MODEL_INIT(Bogaudio, LLFO) {
  132. Model *modelLLFO = createModel<LLFO, LLFOWidget>("Bogaudio-LLFO", "LLFO", "compact LFO", LFO_TAG);
  133. return modelLLFO;
  134. }