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.

117 lines
3.7KB

  1. #include "JWModules.hpp"
  2. #include "dsp/digital.hpp"
  3. namespace rack_plugin_JW_Modules {
  4. struct Quantizer : Module,QuantizeUtils {
  5. enum ParamIds {
  6. ROOT_NOTE_PARAM,
  7. SCALE_PARAM,
  8. NUM_PARAMS
  9. };
  10. enum InputIds {
  11. NOTE_INPUT,
  12. SCALE_INPUT,
  13. VOLT_INPUT,
  14. NUM_INPUTS
  15. };
  16. enum OutputIds {
  17. VOLT_OUTPUT,
  18. NUM_OUTPUTS
  19. };
  20. enum LightIds {
  21. NUM_LIGHTS
  22. };
  23. Quantizer() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  24. void step() override;
  25. json_t *toJson() override {
  26. json_t *rootJ = json_object();
  27. return rootJ;
  28. }
  29. };
  30. ///////////////////////////////////////////////////////////////////////////////////////////////////
  31. // STEP
  32. ///////////////////////////////////////////////////////////////////////////////////////////////////
  33. void Quantizer::step() {
  34. int rootNote = params[ROOT_NOTE_PARAM].value + rescalefjw(inputs[NOTE_INPUT].value, 0, 10, 0, QuantizeUtils::NUM_NOTES-1);
  35. int scale = params[SCALE_PARAM].value + rescalefjw(inputs[SCALE_INPUT].value, 0, 10, 0, QuantizeUtils::NUM_SCALES-1);
  36. outputs[VOLT_OUTPUT].value = closestVoltageInScale(inputs[VOLT_INPUT].value, rootNote, scale);
  37. }
  38. struct QuantizerWidget : ModuleWidget {
  39. QuantizerWidget(Quantizer *module);
  40. };
  41. QuantizerWidget::QuantizerWidget(Quantizer *module) : ModuleWidget(module) {
  42. box.size = Vec(RACK_GRID_WIDTH*4, RACK_GRID_HEIGHT);
  43. {
  44. SVGPanel *panel = new SVGPanel();
  45. panel->box.size = box.size;
  46. panel->setBackground(SVG::load(assetPlugin(plugin, "res/WavHeadPanel.svg")));
  47. addChild(panel);
  48. }
  49. addChild(Widget::create<Screw_J>(Vec(16, 1)));
  50. addChild(Widget::create<Screw_J>(Vec(16, 365)));
  51. addChild(Widget::create<Screw_W>(Vec(box.size.x-29, 1)));
  52. addChild(Widget::create<Screw_W>(Vec(box.size.x-29, 365)));
  53. CenteredLabel* const titleLabel = new CenteredLabel;
  54. titleLabel->box.pos = Vec(15, 15);
  55. titleLabel->text = "Quantizer";
  56. addChild(titleLabel);
  57. ///// NOTE AND SCALE CONTROLS /////
  58. NoteKnob *noteKnob = dynamic_cast<NoteKnob*>(ParamWidget::create<NoteKnob>(Vec(17, 78), module, Quantizer::ROOT_NOTE_PARAM, 0.0, QuantizeUtils::NUM_NOTES-1, QuantizeUtils::NOTE_C));
  59. CenteredLabel* const noteLabel = new CenteredLabel;
  60. noteLabel->box.pos = Vec(15, 35);
  61. noteLabel->text = "note here";
  62. noteKnob->connectLabel(noteLabel);
  63. addChild(noteLabel);
  64. addParam(noteKnob);
  65. addInput(Port::create<TinyPJ301MPort>(Vec(23, 110), Port::INPUT, module, Quantizer::NOTE_INPUT));
  66. ScaleKnob *scaleKnob = dynamic_cast<ScaleKnob*>(ParamWidget::create<ScaleKnob>(Vec(17, 188), module, Quantizer::SCALE_PARAM, 0.0, QuantizeUtils::NUM_SCALES-1, QuantizeUtils::MINOR));
  67. CenteredLabel* const scaleLabel = new CenteredLabel;
  68. scaleLabel->box.pos = Vec(15, 90);
  69. scaleLabel->text = "scale here";
  70. scaleKnob->connectLabel(scaleLabel);
  71. addChild(scaleLabel);
  72. addParam(scaleKnob);
  73. addInput(Port::create<TinyPJ301MPort>(Vec(23, 220), Port::INPUT, module, Quantizer::SCALE_INPUT));
  74. addInput(Port::create<TinyPJ301MPort>(Vec(10, 290), Port::INPUT, module, Quantizer::VOLT_INPUT));
  75. addOutput(Port::create<TinyPJ301MPort>(Vec(35, 290), Port::OUTPUT, module, Quantizer::VOLT_OUTPUT));
  76. CenteredLabel* const voctLabel = new CenteredLabel;
  77. voctLabel->box.pos = Vec(15, 140);
  78. voctLabel->text = "V/OCT";
  79. addChild(voctLabel);
  80. CenteredLabel* const inLabel = new CenteredLabel;
  81. inLabel->box.pos = Vec(8, 160);
  82. inLabel->text = "In";
  83. addChild(inLabel);
  84. CenteredLabel* const outLabel = new CenteredLabel;
  85. outLabel->box.pos = Vec(22, 160);
  86. outLabel->text = "Out";
  87. addChild(outLabel);
  88. }
  89. } // namespace rack_plugin_JW_Modules
  90. using namespace rack_plugin_JW_Modules;
  91. RACK_PLUGIN_MODEL_INIT(JW_Modules, Quantizer) {
  92. Model *modelQuantizer = Model::create<Quantizer, QuantizerWidget>("JW-Modules", "Quantizer", "Quantizer", QUANTIZER_TAG);
  93. return modelQuantizer;
  94. }