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.

86 lines
2.5KB

  1. #include "Detune.hpp"
  2. void Detune::step() {
  3. if (!(outputs[OUT_PLUS_OUTPUT].active || outputs[OUT_MINUS_OUTPUT].active || outputs[THRU_OUTPUT].active)) {
  4. return;
  5. }
  6. float cents = params[CENTS_PARAM].value;
  7. if (inputs[CV_INPUT].active) {
  8. cents *= clamp(inputs[CV_INPUT].value / 10.0f, 0.0f, 1.0f);
  9. cents = roundf(cents);
  10. }
  11. cents /= 100.0f;
  12. float inCV = 0.0f;
  13. if (inputs[IN_INPUT].active) {
  14. inCV = inputs[IN_INPUT].value;
  15. }
  16. if (_cents != cents || _inCV != inCV) {
  17. _cents = cents;
  18. _inCV = inCV;
  19. if (_cents < 0.001f) {
  20. _plusCV = _inCV;
  21. _minusCV = _inCV;
  22. }
  23. else {
  24. float semitone = cvToSemitone(_inCV);
  25. _plusCV = semitoneToCV(semitone + cents);
  26. _minusCV = semitoneToCV(semitone - cents);
  27. }
  28. }
  29. outputs[THRU_OUTPUT].value = _inCV;
  30. outputs[OUT_PLUS_OUTPUT].value = _plusCV;
  31. outputs[OUT_MINUS_OUTPUT].value = _minusCV;
  32. }
  33. struct DetuneWidget : ModuleWidget {
  34. static constexpr int hp = 3;
  35. DetuneWidget(Detune* module) : ModuleWidget(module) {
  36. box.size = Vec(RACK_GRID_WIDTH * hp, RACK_GRID_HEIGHT);
  37. {
  38. SVGPanel *panel = new SVGPanel();
  39. panel->box.size = box.size;
  40. panel->setBackground(SVG::load(assetPlugin(plugin, "res/Detune.svg")));
  41. addChild(panel);
  42. }
  43. addChild(Widget::create<ScrewSilver>(Vec(0, 0)));
  44. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 15, 365)));
  45. // generated by svg_widgets.rb
  46. auto centsParamPosition = Vec(9.5, 32.5);
  47. auto cvInputPosition = Vec(10.5, 77.0);
  48. auto inInputPosition = Vec(10.5, 126.0);
  49. auto thruOutputPosition = Vec(10.5, 164.0);
  50. auto outPlusOutputPosition = Vec(10.5, 200.0);
  51. auto outMinusOutputPosition = Vec(10.5, 236.0);
  52. // end generated by svg_widgets.rb
  53. {
  54. auto w = ParamWidget::create<Knob26>(centsParamPosition, module, Detune::CENTS_PARAM, 0.0, 50.0, 0.0);
  55. dynamic_cast<Knob*>(w)->snap = true;
  56. addParam(w);
  57. }
  58. addInput(Port::create<Port24>(cvInputPosition, Port::INPUT, module, Detune::CV_INPUT));
  59. addInput(Port::create<Port24>(inInputPosition, Port::INPUT, module, Detune::IN_INPUT));
  60. addOutput(Port::create<Port24>(thruOutputPosition, Port::OUTPUT, module, Detune::THRU_OUTPUT));
  61. addOutput(Port::create<Port24>(outPlusOutputPosition, Port::OUTPUT, module, Detune::OUT_PLUS_OUTPUT));
  62. addOutput(Port::create<Port24>(outMinusOutputPosition, Port::OUTPUT, module, Detune::OUT_MINUS_OUTPUT));
  63. }
  64. };
  65. RACK_PLUGIN_MODEL_INIT(Bogaudio, Detune) {
  66. Model *modelDetune = createModel<Detune, DetuneWidget>("Bogaudio-Detune", "Detune", "pitch CV processor", TUNER_TAG);
  67. return modelDetune;
  68. }