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.

112 lines
3.2KB

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