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.

144 lines
5.4KB

  1. #include "Core.hpp"
  2. #include "midi.hpp"
  3. #include "dsp/filter.hpp"
  4. struct CcChoice : LedDisplayChoice {
  5. CcChoice() {
  6. box.size.y = mm2px(6.666);
  7. textOffset.y -= 4;
  8. }
  9. };
  10. struct CcMidiWidget : MidiWidget {
  11. LedDisplaySeparator *hSeparators[4];
  12. LedDisplaySeparator *vSeparators[4];
  13. LedDisplayChoice *ccChoices[4][4];
  14. CcMidiWidget() {
  15. Vec pos = channelChoice->box.getBottomLeft();
  16. for (int x = 1; x < 4; x++) {
  17. vSeparators[x] = Widget::create<LedDisplaySeparator>(pos);
  18. addChild(vSeparators[x]);
  19. }
  20. for (int y = 0; y < 4; y++) {
  21. hSeparators[y] = Widget::create<LedDisplaySeparator>(pos);
  22. addChild(hSeparators[y]);
  23. for (int x = 0; x < 4; x++) {
  24. CcChoice *ccChoice = Widget::create<CcChoice>(pos);
  25. ccChoice->text = stringf("%d", x*4+y);
  26. ccChoices[x][y] = ccChoice;
  27. addChild(ccChoice);
  28. }
  29. pos = ccChoices[0][y]->box.getBottomLeft();
  30. }
  31. for (int x = 1; x < 4; x++) {
  32. vSeparators[x]->box.size.y = pos.y - vSeparators[x]->box.pos.y;
  33. }
  34. }
  35. void step() override {
  36. MidiWidget::step();
  37. for (int x = 1; x < 4; x++) {
  38. vSeparators[x]->box.pos.x = box.size.x / 4 * x;
  39. }
  40. for (int y = 0; y < 4; y++) {
  41. hSeparators[y]->box.size.x = box.size.x;
  42. for (int x = 0; x < 4; x++) {
  43. ccChoices[x][y]->box.size.x = box.size.x / 4;
  44. ccChoices[x][y]->box.pos.x = box.size.x / 4 * x;
  45. }
  46. }
  47. }
  48. };
  49. struct MIDITriggerToCVInterface : Module {
  50. enum ParamIds {
  51. NUM_PARAMS
  52. };
  53. enum InputIds {
  54. NUM_INPUTS
  55. };
  56. enum OutputIds {
  57. ENUMS(TRIG_OUTPUT, 16),
  58. NUM_OUTPUTS
  59. };
  60. enum LightIds {
  61. NUM_LIGHTS
  62. };
  63. MidiInputQueue midiInput;
  64. MIDITriggerToCVInterface() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  65. void step() override {
  66. MidiMessage msg;
  67. while (midiInput.shift(&msg)) {
  68. processMessage(msg);
  69. }
  70. for (int i = 0; i < 16; i++) {
  71. outputs[TRIG_OUTPUT + i].value = 0.f;
  72. }
  73. }
  74. void processMessage(MidiMessage msg) {
  75. // debug("MIDI: %01x %01x %02x %02x", msg.status(), msg.channel(), msg.data1, msg.data2);
  76. switch (msg.status()) {
  77. default: break;
  78. }
  79. }
  80. json_t *toJson() override {
  81. json_t *rootJ = json_object();
  82. json_object_set_new(rootJ, "midi", midiInput.toJson());
  83. return rootJ;
  84. }
  85. void fromJson(json_t *rootJ) override {
  86. json_t *midiJ = json_object_get(rootJ, "midi");
  87. midiInput.fromJson(midiJ);
  88. }
  89. };
  90. struct MIDITriggerToCVInterfaceWidget : ModuleWidget {
  91. MIDITriggerToCVInterfaceWidget(MIDITriggerToCVInterface *module) : ModuleWidget(module) {
  92. setPanel(SVG::load(assetGlobal("res/Core/MIDICCToCVInterface.svg")));
  93. addChild(Widget::create<ScrewSilver>(Vec(RACK_GRID_WIDTH, 0)));
  94. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0)));
  95. addChild(Widget::create<ScrewSilver>(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  96. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  97. addOutput(Port::create<PJ301MPort>(mm2px(Vec(3.894335, 73.344704)), Port::OUTPUT, module, MIDITriggerToCVInterface::TRIG_OUTPUT + 0));
  98. addOutput(Port::create<PJ301MPort>(mm2px(Vec(15.494659, 73.344704)), Port::OUTPUT, module, MIDITriggerToCVInterface::TRIG_OUTPUT + 1));
  99. addOutput(Port::create<PJ301MPort>(mm2px(Vec(27.094982, 73.344704)), Port::OUTPUT, module, MIDITriggerToCVInterface::TRIG_OUTPUT + 2));
  100. addOutput(Port::create<PJ301MPort>(mm2px(Vec(38.693932, 73.344704)), Port::OUTPUT, module, MIDITriggerToCVInterface::TRIG_OUTPUT + 3));
  101. addOutput(Port::create<PJ301MPort>(mm2px(Vec(3.8943355, 84.945023)), Port::OUTPUT, module, MIDITriggerToCVInterface::TRIG_OUTPUT + 4));
  102. addOutput(Port::create<PJ301MPort>(mm2px(Vec(15.49466, 84.945023)), Port::OUTPUT, module, MIDITriggerToCVInterface::TRIG_OUTPUT + 5));
  103. addOutput(Port::create<PJ301MPort>(mm2px(Vec(27.094982, 84.945023)), Port::OUTPUT, module, MIDITriggerToCVInterface::TRIG_OUTPUT + 6));
  104. addOutput(Port::create<PJ301MPort>(mm2px(Vec(38.693932, 84.945023)), Port::OUTPUT, module, MIDITriggerToCVInterface::TRIG_OUTPUT + 7));
  105. addOutput(Port::create<PJ301MPort>(mm2px(Vec(3.8943343, 96.543976)), Port::OUTPUT, module, MIDITriggerToCVInterface::TRIG_OUTPUT + 8));
  106. addOutput(Port::create<PJ301MPort>(mm2px(Vec(15.494659, 96.543976)), Port::OUTPUT, module, MIDITriggerToCVInterface::TRIG_OUTPUT + 9));
  107. addOutput(Port::create<PJ301MPort>(mm2px(Vec(27.09498, 96.543976)), Port::OUTPUT, module, MIDITriggerToCVInterface::TRIG_OUTPUT + 10));
  108. addOutput(Port::create<PJ301MPort>(mm2px(Vec(38.693932, 96.543976)), Port::OUTPUT, module, MIDITriggerToCVInterface::TRIG_OUTPUT + 11));
  109. addOutput(Port::create<PJ301MPort>(mm2px(Vec(3.894335, 108.14429)), Port::OUTPUT, module, MIDITriggerToCVInterface::TRIG_OUTPUT + 12));
  110. addOutput(Port::create<PJ301MPort>(mm2px(Vec(15.49466, 108.14429)), Port::OUTPUT, module, MIDITriggerToCVInterface::TRIG_OUTPUT + 13));
  111. addOutput(Port::create<PJ301MPort>(mm2px(Vec(27.09498, 108.14429)), Port::OUTPUT, module, MIDITriggerToCVInterface::TRIG_OUTPUT + 14));
  112. addOutput(Port::create<PJ301MPort>(mm2px(Vec(38.693932, 108.14429)), Port::OUTPUT, module, MIDITriggerToCVInterface::TRIG_OUTPUT + 15));
  113. MidiWidget *midiWidget = Widget::create<CcMidiWidget>(mm2px(Vec(3.399621, 14.837339)));
  114. midiWidget->box.size = mm2px(Vec(44, 54.667));
  115. midiWidget->midiIO = &module->midiInput;
  116. addChild(midiWidget);
  117. }
  118. };
  119. Model *modelMIDITriggerToCVInterface = Model::create<MIDITriggerToCVInterface, MIDITriggerToCVInterfaceWidget>("Core", "MIDITriggerToCVInterface", "MIDI-TRIG", MIDI_TAG, EXTERNAL_TAG);