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.

100 lines
5.2KB

  1. #include "plugin.hpp"
  2. struct Split : Module {
  3. enum ParamIds {
  4. NUM_PARAMS
  5. };
  6. enum InputIds {
  7. POLY_INPUT,
  8. NUM_INPUTS
  9. };
  10. enum OutputIds {
  11. ENUMS(MONO_OUTPUTS, 16),
  12. NUM_OUTPUTS
  13. };
  14. enum LightIds {
  15. ENUMS(CHANNEL_LIGHTS, 16),
  16. NUM_LIGHTS
  17. };
  18. dsp::ClockDivider lightDivider;
  19. Split() {
  20. config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
  21. configInput(POLY_INPUT, "Polyphonic");
  22. for (int i = 0; i < 8; i++)
  23. configOutput(MONO_OUTPUTS + i, string::f("Channel %d", i + 1));
  24. lightDivider.setDivision(512);
  25. }
  26. void process(const ProcessArgs& args) override {
  27. for (int c = 0; c < 16; c++) {
  28. float v = inputs[POLY_INPUT].getVoltage(c);
  29. // To allow users to debug buggy modules, don't assume that undefined channel voltages are 0V.
  30. outputs[MONO_OUTPUTS + c].setVoltage(v);
  31. }
  32. // Set channel lights infrequently
  33. if (lightDivider.process()) {
  34. for (int c = 0; c < 16; c++) {
  35. bool active = (c < inputs[POLY_INPUT].getChannels());
  36. lights[CHANNEL_LIGHTS + c].setBrightness(active);
  37. }
  38. }
  39. }
  40. };
  41. struct SplitWidget : ModuleWidget {
  42. SplitWidget(Split* module) {
  43. setModule(module);
  44. setPanel(createPanel(asset::plugin(pluginInstance, "res/Split.svg")));
  45. addChild(createWidget<ScrewSilver>(Vec(RACK_GRID_WIDTH, 0)));
  46. addChild(createWidget<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0)));
  47. addChild(createWidget<ScrewSilver>(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  48. addChild(createWidget<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  49. addInput(createInputCentered<PJ301MPort>(mm2px(Vec(6.77, 21.347)), module, Split::POLY_INPUT));
  50. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(6.771, 37.02)), module, Split::MONO_OUTPUTS + 0));
  51. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(6.771, 48.02)), module, Split::MONO_OUTPUTS + 1));
  52. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(6.77, 59.02)), module, Split::MONO_OUTPUTS + 2));
  53. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(6.77, 70.02)), module, Split::MONO_OUTPUTS + 3));
  54. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(6.77, 81.02)), module, Split::MONO_OUTPUTS + 4));
  55. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(6.77, 92.02)), module, Split::MONO_OUTPUTS + 5));
  56. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(6.771, 103.02)), module, Split::MONO_OUTPUTS + 6));
  57. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(6.771, 114.02)), module, Split::MONO_OUTPUTS + 7));
  58. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(18.275, 37.02)), module, Split::MONO_OUTPUTS + 8));
  59. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(18.275, 48.02)), module, Split::MONO_OUTPUTS + 9));
  60. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(18.274, 59.02)), module, Split::MONO_OUTPUTS + 10));
  61. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(18.274, 70.02)), module, Split::MONO_OUTPUTS + 11));
  62. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(18.274, 81.02)), module, Split::MONO_OUTPUTS + 12));
  63. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(18.274, 92.02)), module, Split::MONO_OUTPUTS + 13));
  64. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(18.275, 103.02)), module, Split::MONO_OUTPUTS + 14));
  65. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(18.275, 114.02)), module, Split::MONO_OUTPUTS + 15));
  66. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(15.276, 17.775)), module, Split::CHANNEL_LIGHTS + 0));
  67. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(17.275, 17.775)), module, Split::CHANNEL_LIGHTS + 1));
  68. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(19.275, 17.775)), module, Split::CHANNEL_LIGHTS + 2));
  69. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(21.275, 17.775)), module, Split::CHANNEL_LIGHTS + 3));
  70. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(15.276, 19.775)), module, Split::CHANNEL_LIGHTS + 4));
  71. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(17.275, 19.775)), module, Split::CHANNEL_LIGHTS + 5));
  72. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(19.275, 19.775)), module, Split::CHANNEL_LIGHTS + 6));
  73. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(21.275, 19.775)), module, Split::CHANNEL_LIGHTS + 7));
  74. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(15.276, 21.775)), module, Split::CHANNEL_LIGHTS + 8));
  75. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(17.275, 21.775)), module, Split::CHANNEL_LIGHTS + 9));
  76. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(19.275, 21.775)), module, Split::CHANNEL_LIGHTS + 10));
  77. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(21.276, 21.775)), module, Split::CHANNEL_LIGHTS + 11));
  78. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(15.276, 23.775)), module, Split::CHANNEL_LIGHTS + 12));
  79. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(17.275, 23.775)), module, Split::CHANNEL_LIGHTS + 13));
  80. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(19.275, 23.775)), module, Split::CHANNEL_LIGHTS + 14));
  81. addChild(createLightCentered<TinyLight<BlueLight>>(mm2px(Vec(21.276, 23.775)), module, Split::CHANNEL_LIGHTS + 15));
  82. }
  83. };
  84. Model* modelSplit = createModel<Split, SplitWidget>("Split");