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.

103 lines
3.0KB

  1. #include "RJModules.hpp"
  2. #include "dsp/digital.hpp"
  3. #include <iostream>
  4. #include <cmath>
  5. struct BigButton: Module {
  6. enum ParamIds {
  7. RESET_PARAM,
  8. NUM_PARAMS
  9. };
  10. enum InputIds {
  11. NUM_INPUTS
  12. };
  13. enum OutputIds {
  14. CH1_OUTPUT,
  15. CH2_OUTPUT,
  16. CH3_OUTPUT,
  17. CH4_OUTPUT,
  18. CH5_OUTPUT,
  19. CH6_OUTPUT,
  20. NUM_OUTPUTS
  21. };
  22. enum LightIds {
  23. RESET_LIGHT,
  24. NUM_LIGHTS
  25. };
  26. float resetLight = 0.0;
  27. BigButton() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  28. void step() override;
  29. };
  30. struct BigLEDButton : SVGSwitch, MomentarySwitch {
  31. BigLEDButton() {
  32. addFrame(SVG::load(assetPlugin(plugin, "res/BigLEDButton.svg")));
  33. }
  34. };
  35. template <typename BASE>
  36. struct GiantLight : BASE {
  37. GiantLight() {
  38. this->box.size = mm2px(Vec(34, 34));
  39. }
  40. };
  41. void BigButton::step() {
  42. const float lightLambda = 0.075;
  43. float output = 0.0;
  44. SchmittTrigger resetTrigger;
  45. // Reset
  46. if (params[RESET_PARAM].value > 0) {
  47. resetLight = 1.0;
  48. output = 12.0;
  49. }
  50. resetLight -= resetLight / lightLambda / engineGetSampleRate();
  51. outputs[CH1_OUTPUT].value = output;
  52. outputs[CH2_OUTPUT].value = output;
  53. outputs[CH3_OUTPUT].value = output;
  54. outputs[CH4_OUTPUT].value = output;
  55. outputs[CH5_OUTPUT].value = output;
  56. outputs[CH6_OUTPUT].value = output;
  57. lights[RESET_LIGHT].value = resetLight;
  58. }
  59. struct ButtonWidget: ModuleWidget {
  60. ButtonWidget(BigButton *module);
  61. };
  62. ButtonWidget::ButtonWidget(BigButton *module) : ModuleWidget(module) {
  63. box.size = Vec(15*10, 380);
  64. {
  65. SVGPanel *panel = new SVGPanel();
  66. panel->box.size = box.size;
  67. panel->setBackground(SVG::load(assetPlugin(plugin, "res/Button.svg")));
  68. addChild(panel);
  69. }
  70. addChild(Widget::create<ScrewSilver>(Vec(15, 0)));
  71. addChild(Widget::create<ScrewSilver>(Vec(box.size.x-30, 0)));
  72. addChild(Widget::create<ScrewSilver>(Vec(15, 365)));
  73. addChild(Widget::create<ScrewSilver>(Vec(box.size.x-30, 365)));
  74. addOutput(Port::create<PJ301MPort>(Vec(24, 223), Port::OUTPUT, module, BigButton::CH1_OUTPUT));
  75. addOutput(Port::create<PJ301MPort>(Vec(65, 223), Port::OUTPUT, module, BigButton::CH2_OUTPUT));
  76. addOutput(Port::create<PJ301MPort>(Vec(105, 223), Port::OUTPUT, module, BigButton::CH3_OUTPUT));
  77. addOutput(Port::create<PJ301MPort>(Vec(24, 274), Port::OUTPUT, module, BigButton::CH4_OUTPUT));
  78. addOutput(Port::create<PJ301MPort>(Vec(65, 274), Port::OUTPUT, module, BigButton::CH5_OUTPUT));
  79. addOutput(Port::create<PJ301MPort>(Vec(106, 274), Port::OUTPUT, module, BigButton::CH6_OUTPUT));
  80. addParam(ParamWidget::create<BigLEDButton>(Vec(15, 60), module, BigButton::RESET_PARAM, 0.0, 1.0, 0.0));
  81. addChild(ModuleLightWidget::create<GiantLight<GreenLight>>(Vec(25, 70), module, BigButton::RESET_LIGHT));
  82. }
  83. Model *modelButton = Model::create<BigButton, ButtonWidget>("RJModules", "Button", "[LIVE] Button", UTILITY_TAG);