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.

102 lines
5.9KB

  1. #include "plugin.hpp"
  2. struct Pulses : Module {
  3. enum ParamIds {
  4. ENUMS(TAP_PARAMS, 10),
  5. NUM_PARAMS
  6. };
  7. enum InputIds {
  8. NUM_INPUTS
  9. };
  10. enum OutputIds {
  11. ENUMS(TRIG_OUTPUTS, 10),
  12. ENUMS(GATE_OUTPUTS, 10),
  13. NUM_OUTPUTS
  14. };
  15. enum LightIds {
  16. ENUMS(TAP_LIGHTS, 10),
  17. NUM_LIGHTS
  18. };
  19. dsp::BooleanTrigger tapTriggers[10];
  20. dsp::PulseGenerator pulseGenerators[10];
  21. Pulses() {
  22. config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
  23. for (int i = 0; i < 10; i++)
  24. configParam(TAP_PARAMS + i, 0.f, 1.f, 0.f, string::f("Tap %d", i + 1));
  25. }
  26. void process(const ProcessArgs& args) override {
  27. for (int i = 0; i < 10; i++) {
  28. bool tap = params[TAP_PARAMS + i].getValue() > 0.f;
  29. if (tapTriggers[i].process(tap)) {
  30. pulseGenerators[i].trigger(1e-3f);
  31. }
  32. bool pulse = pulseGenerators[i].process(args.sampleTime);
  33. outputs[TRIG_OUTPUTS + i].setVoltage(pulse ? 10.f : 0.f);
  34. outputs[GATE_OUTPUTS + i].setVoltage(tap ? 10.f : 0.f);
  35. lights[TAP_LIGHTS + i].setBrightness(tap);
  36. }
  37. }
  38. };
  39. struct PulsesWidget : ModuleWidget {
  40. PulsesWidget(Pulses* module) {
  41. setModule(module);
  42. setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/Pulses.svg")));
  43. addChild(createWidget<ScrewSilver>(Vec(RACK_GRID_WIDTH, 0)));
  44. addChild(createWidget<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0)));
  45. addChild(createWidget<ScrewSilver>(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  46. addChild(createWidget<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  47. addParam(createParamCentered<LEDBezel>(mm2px(Vec(8.32, 21.505)), module, Pulses::TAP_PARAMS + 0));
  48. addParam(createParamCentered<LEDBezel>(mm2px(Vec(8.32, 31.504)), module, Pulses::TAP_PARAMS + 1));
  49. addParam(createParamCentered<LEDBezel>(mm2px(Vec(8.32, 41.505)), module, Pulses::TAP_PARAMS + 2));
  50. addParam(createParamCentered<LEDBezel>(mm2px(Vec(8.32, 51.505)), module, Pulses::TAP_PARAMS + 3));
  51. addParam(createParamCentered<LEDBezel>(mm2px(Vec(8.32, 61.505)), module, Pulses::TAP_PARAMS + 4));
  52. addParam(createParamCentered<LEDBezel>(mm2px(Vec(8.32, 71.505)), module, Pulses::TAP_PARAMS + 5));
  53. addParam(createParamCentered<LEDBezel>(mm2px(Vec(8.32, 81.505)), module, Pulses::TAP_PARAMS + 6));
  54. addParam(createParamCentered<LEDBezel>(mm2px(Vec(8.32, 91.504)), module, Pulses::TAP_PARAMS + 7));
  55. addParam(createParamCentered<LEDBezel>(mm2px(Vec(8.32, 101.505)), module, Pulses::TAP_PARAMS + 8));
  56. addParam(createParamCentered<LEDBezel>(mm2px(Vec(8.32, 111.505)), module, Pulses::TAP_PARAMS + 9));
  57. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(20.319, 21.504)), module, Pulses::TRIG_OUTPUTS + 0));
  58. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(32.319, 21.504)), module, Pulses::GATE_OUTPUTS + 0));
  59. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(20.319, 31.504)), module, Pulses::TRIG_OUTPUTS + 1));
  60. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(32.319, 31.504)), module, Pulses::GATE_OUTPUTS + 1));
  61. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(20.319, 41.505)), module, Pulses::TRIG_OUTPUTS + 2));
  62. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(32.319, 41.505)), module, Pulses::GATE_OUTPUTS + 2));
  63. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(20.319, 51.504)), module, Pulses::TRIG_OUTPUTS + 3));
  64. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(32.319, 51.504)), module, Pulses::GATE_OUTPUTS + 3));
  65. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(20.319, 61.504)), module, Pulses::TRIG_OUTPUTS + 4));
  66. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(32.319, 61.504)), module, Pulses::GATE_OUTPUTS + 4));
  67. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(20.319, 71.504)), module, Pulses::TRIG_OUTPUTS + 5));
  68. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(32.319, 71.504)), module, Pulses::GATE_OUTPUTS + 5));
  69. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(20.319, 81.505)), module, Pulses::TRIG_OUTPUTS + 6));
  70. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(32.319, 81.505)), module, Pulses::GATE_OUTPUTS + 6));
  71. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(20.319, 91.504)), module, Pulses::TRIG_OUTPUTS + 7));
  72. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(32.319, 91.504)), module, Pulses::GATE_OUTPUTS + 7));
  73. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(20.319, 101.504)), module, Pulses::TRIG_OUTPUTS + 8));
  74. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(32.319, 101.504)), module, Pulses::GATE_OUTPUTS + 8));
  75. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(20.319, 111.504)), module, Pulses::TRIG_OUTPUTS + 9));
  76. addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec(32.319, 111.504)), module, Pulses::GATE_OUTPUTS + 9));
  77. addChild(createLightCentered<LEDBezelLight<GreenLight>>(mm2px(Vec(8.32, 21.505)), module, Pulses::TAP_LIGHTS + 0));
  78. addChild(createLightCentered<LEDBezelLight<GreenLight>>(mm2px(Vec(8.32, 31.504)), module, Pulses::TAP_LIGHTS + 1));
  79. addChild(createLightCentered<LEDBezelLight<GreenLight>>(mm2px(Vec(8.32, 41.505)), module, Pulses::TAP_LIGHTS + 2));
  80. addChild(createLightCentered<LEDBezelLight<GreenLight>>(mm2px(Vec(8.32, 51.505)), module, Pulses::TAP_LIGHTS + 3));
  81. addChild(createLightCentered<LEDBezelLight<GreenLight>>(mm2px(Vec(8.32, 61.505)), module, Pulses::TAP_LIGHTS + 4));
  82. addChild(createLightCentered<LEDBezelLight<GreenLight>>(mm2px(Vec(8.32, 71.505)), module, Pulses::TAP_LIGHTS + 5));
  83. addChild(createLightCentered<LEDBezelLight<GreenLight>>(mm2px(Vec(8.32, 81.505)), module, Pulses::TAP_LIGHTS + 6));
  84. addChild(createLightCentered<LEDBezelLight<GreenLight>>(mm2px(Vec(8.32, 91.504)), module, Pulses::TAP_LIGHTS + 7));
  85. addChild(createLightCentered<LEDBezelLight<GreenLight>>(mm2px(Vec(8.32, 101.505)), module, Pulses::TAP_LIGHTS + 8));
  86. addChild(createLightCentered<LEDBezelLight<GreenLight>>(mm2px(Vec(8.32, 111.505)), module, Pulses::TAP_LIGHTS + 9));
  87. }
  88. };
  89. Model* modelPulses = createModel<Pulses, PulsesWidget>("Pulses");