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.

103 lines
3.3KB

  1. #include "Stack.hpp"
  2. void Stack::step() {
  3. lights[QUANTIZE_LIGHT].value = params[QUANTIZE_PARAM].value > 0.5;
  4. if (!(outputs[OUT_OUTPUT].active || outputs[THRU_OUTPUT].active)) {
  5. return;
  6. }
  7. float semitones = params[OCTAVE_PARAM].value * 12.0;
  8. semitones += params[SEMIS_PARAM].value;
  9. if (inputs[CV_INPUT].active) {
  10. semitones += clamp(inputs[CV_INPUT].value, -5.0f, 5.0f) * 10.0;
  11. }
  12. if (params[QUANTIZE_PARAM].value > 0.5) {
  13. semitones = roundf(semitones);
  14. }
  15. float inCV = 0.0f;
  16. if (inputs[IN_INPUT].active) {
  17. inCV = clamp(inputs[IN_INPUT].value, _minCVOut, _maxCVOut);
  18. }
  19. float fine = params[FINE_PARAM].value;
  20. if (_semitones != semitones || _inCV != inCV || _fine != fine) {
  21. _semitones = semitones;
  22. _inCV = inCV;
  23. _fine = fine;
  24. _outCV = clamp(semitoneToCV((_inCV != 0.0f ? cvToSemitone(_inCV) : referenceSemitone) + _semitones + _fine), _minCVOut, _maxCVOut);
  25. }
  26. if (inputs[IN_INPUT].active) {
  27. outputs[THRU_OUTPUT].value = _inCV;
  28. }
  29. else {
  30. outputs[THRU_OUTPUT].value = _semitones / 10.0;
  31. }
  32. outputs[OUT_OUTPUT].value = _outCV;
  33. }
  34. struct StackWidget : ModuleWidget {
  35. static constexpr int hp = 3;
  36. StackWidget(Stack* module) : ModuleWidget(module) {
  37. box.size = Vec(RACK_GRID_WIDTH * hp, RACK_GRID_HEIGHT);
  38. {
  39. SVGPanel *panel = new SVGPanel();
  40. panel->box.size = box.size;
  41. panel->setBackground(SVG::load(assetPlugin(plugin, "res/Stack.svg")));
  42. addChild(panel);
  43. }
  44. addChild(Widget::create<ScrewSilver>(Vec(0, 0)));
  45. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 15, 365)));
  46. // generated by svg_widgets.rb
  47. auto semisParamPosition = Vec(9.5, 32.5);
  48. auto octaveParamPosition = Vec(14.5, 86.5);
  49. auto fineParamPosition = Vec(14.5, 126.5);
  50. auto quantizeParamPosition = Vec(28.4, 191.9);
  51. auto cvInputPosition = Vec(10.5, 157.0);
  52. auto inInputPosition = Vec(10.5, 215.0);
  53. auto thruOutputPosition = Vec(10.5, 253.0);
  54. auto outOutputPosition = Vec(10.5, 289.0);
  55. auto quantizeLightPosition = Vec(8.5, 193.5);
  56. // end generated by svg_widgets.rb
  57. {
  58. auto w = ParamWidget::create<Knob26>(semisParamPosition, module, Stack::SEMIS_PARAM, 0.0, 11.0, 0.0);
  59. dynamic_cast<Knob*>(w)->snap = true;
  60. addParam(w);
  61. }
  62. {
  63. auto w = ParamWidget::create<Knob16>(octaveParamPosition, module, Stack::OCTAVE_PARAM, -3.0, 3.0, 0.0);
  64. auto k = dynamic_cast<SVGKnob*>(w);
  65. k->snap = true;
  66. k->minAngle = -0.5 * M_PI;
  67. k->maxAngle = 0.5 * M_PI;
  68. addParam(w);
  69. }
  70. addParam(ParamWidget::create<Knob16>(fineParamPosition, module, Stack::FINE_PARAM, -0.99, 0.99, 0.0));
  71. addParam(ParamWidget::create<StatefulButton9>(quantizeParamPosition, module, Stack::QUANTIZE_PARAM, 0.0, 1.0, 1.0));
  72. addInput(Port::create<Port24>(cvInputPosition, Port::INPUT, module, Stack::CV_INPUT));
  73. addInput(Port::create<Port24>(inInputPosition, Port::INPUT, module, Stack::IN_INPUT));
  74. addOutput(Port::create<Port24>(thruOutputPosition, Port::OUTPUT, module, Stack::THRU_OUTPUT));
  75. addOutput(Port::create<Port24>(outOutputPosition, Port::OUTPUT, module, Stack::OUT_OUTPUT));
  76. addChild(ModuleLightWidget::create<SmallLight<GreenLight>>(quantizeLightPosition, module, Stack::QUANTIZE_LIGHT));
  77. }
  78. };
  79. RACK_PLUGIN_MODEL_INIT(Bogaudio, Stack) {
  80. Model *modelStack = createModel<Stack, StackWidget>("Bogaudio-Stack", "Stack", "pitch CV processor", TUNER_TAG);
  81. return modelStack;
  82. }