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.

219 lines
7.6KB

  1. #include "RJModules.hpp"
  2. #include "dsp/digital.hpp"
  3. #include <iostream>
  4. #include <cmath>
  5. struct Buttons: Module {
  6. enum ParamIds {
  7. RESET_PARAM,
  8. RESET_PARAM2,
  9. RESET_PARAM3,
  10. RESET_PARAM4,
  11. RESET_PARAM5,
  12. RESET_PARAM6,
  13. RESET_PARAM7,
  14. RESET_PARAM8,
  15. RESET_PARAM9,
  16. NUM_PARAMS
  17. };
  18. enum InputIds {
  19. NUM_INPUTS
  20. };
  21. enum OutputIds {
  22. CH1_OUTPUT,
  23. CH2_OUTPUT,
  24. CH3_OUTPUT,
  25. CH4_OUTPUT,
  26. CH5_OUTPUT,
  27. CH6_OUTPUT,
  28. CH7_OUTPUT,
  29. CH8_OUTPUT,
  30. CH9_OUTPUT,
  31. NUM_OUTPUTS
  32. };
  33. enum LightIds {
  34. RESET_LIGHT,
  35. RESET_LIGHT2,
  36. RESET_LIGHT3,
  37. RESET_LIGHT4,
  38. RESET_LIGHT5,
  39. RESET_LIGHT6,
  40. RESET_LIGHT7,
  41. RESET_LIGHT8,
  42. RESET_LIGHT9,
  43. NUM_LIGHTS
  44. };
  45. float resetLight = 0.0;
  46. float resetLight2 = 0.0;
  47. float resetLight3 = 0.0;
  48. float resetLight4 = 0.0;
  49. float resetLight5 = 0.0;
  50. float resetLight6 = 0.0;
  51. float resetLight7 = 0.0;
  52. float resetLight8 = 0.0;
  53. float resetLight9 = 0.0;
  54. Buttons() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  55. void step() override;
  56. };
  57. struct MedLEDButton : SVGSwitch, MomentarySwitch {
  58. MedLEDButton() {
  59. addFrame(SVG::load(assetPlugin(plugin, "res/MedLEDButton.svg")));
  60. }
  61. };
  62. template <typename BASE>
  63. struct MedLight : BASE {
  64. MedLight() {
  65. this->box.size = mm2px(Vec(10, 10));
  66. }
  67. };
  68. void Buttons::step() {
  69. const float lightLambda = 0.075;
  70. float output = 0.0;
  71. float output2 = 0.0;
  72. float output3 = 0.0;
  73. float output4 = 0.0;
  74. float output5 = 0.0;
  75. float output6 = 0.0;
  76. float output7 = 0.0;
  77. float output8 = 0.0;
  78. float output9 = 0.0;
  79. // Reset
  80. if (params[RESET_PARAM].value > 0) {
  81. resetLight = 1.0;
  82. output = 12.0;
  83. }
  84. if (params[RESET_PARAM2].value > 0) {
  85. resetLight2 = 1.0;
  86. output2 = 12.0;
  87. }
  88. if (params[RESET_PARAM3].value > 0) {
  89. resetLight3 = 1.0;
  90. output3 = 12.0;
  91. }
  92. if (params[RESET_PARAM4].value > 0) {
  93. resetLight4 = 1.0;
  94. output4 = 12.0;
  95. }
  96. if (params[RESET_PARAM5].value > 0) {
  97. resetLight5 = 1.0;
  98. output5 = 12.0;
  99. }
  100. if (params[RESET_PARAM6].value > 0) {
  101. resetLight6 = 1.0;
  102. output6 = 12.0;
  103. }
  104. if (params[RESET_PARAM7].value > 0) {
  105. resetLight7 = 1.0;
  106. output7 = 12.0;
  107. }
  108. if (params[RESET_PARAM8].value > 0) {
  109. resetLight8 = 1.0;
  110. output8 = 12.0;
  111. }
  112. if (params[RESET_PARAM9].value > 0) {
  113. resetLight9 = 1.0;
  114. output9 = 12.0;
  115. }
  116. resetLight -= resetLight / lightLambda / engineGetSampleRate();
  117. resetLight2 -= resetLight2 / lightLambda / engineGetSampleRate();
  118. resetLight3 -= resetLight3 / lightLambda / engineGetSampleRate();
  119. resetLight4 -= resetLight4 / lightLambda / engineGetSampleRate();
  120. resetLight5 -= resetLight5 / lightLambda / engineGetSampleRate();
  121. resetLight6 -= resetLight6 / lightLambda / engineGetSampleRate();
  122. resetLight7 -= resetLight7 / lightLambda / engineGetSampleRate();
  123. resetLight8 -= resetLight8 / lightLambda / engineGetSampleRate();
  124. resetLight9 -= resetLight9 / lightLambda / engineGetSampleRate();
  125. outputs[CH1_OUTPUT].value = output;
  126. outputs[CH2_OUTPUT].value = output2;
  127. outputs[CH3_OUTPUT].value = output3;
  128. outputs[CH4_OUTPUT].value = output4;
  129. outputs[CH5_OUTPUT].value = output5;
  130. outputs[CH6_OUTPUT].value = output6;
  131. outputs[CH7_OUTPUT].value = output7;
  132. outputs[CH8_OUTPUT].value = output8;
  133. outputs[CH9_OUTPUT].value = output9;
  134. lights[RESET_LIGHT].value = resetLight;
  135. lights[RESET_LIGHT2].value = resetLight2;
  136. lights[RESET_LIGHT3].value = resetLight3;
  137. lights[RESET_LIGHT4].value = resetLight4;
  138. lights[RESET_LIGHT5].value = resetLight5;
  139. lights[RESET_LIGHT6].value = resetLight6;
  140. lights[RESET_LIGHT7].value = resetLight7;
  141. lights[RESET_LIGHT8].value = resetLight8;
  142. lights[RESET_LIGHT9].value = resetLight9;
  143. }
  144. struct ButtonsWidget: ModuleWidget {
  145. ButtonsWidget(Buttons *module);
  146. };
  147. ButtonsWidget::ButtonsWidget(Buttons *module) : ModuleWidget(module) {
  148. box.size = Vec(15*10, 380);
  149. {
  150. SVGPanel *panel = new SVGPanel();
  151. panel->box.size = box.size;
  152. panel->setBackground(SVG::load(assetPlugin(plugin, "res/Buttons.svg")));
  153. addChild(panel);
  154. }
  155. addChild(Widget::create<ScrewSilver>(Vec(15, 0)));
  156. addChild(Widget::create<ScrewSilver>(Vec(box.size.x-30, 0)));
  157. addChild(Widget::create<ScrewSilver>(Vec(15, 365)));
  158. addChild(Widget::create<ScrewSilver>(Vec(box.size.x-30, 365)));
  159. addOutput(Port::create<PJ301MPort>(Vec(24, 223), Port::OUTPUT, module, Buttons::CH1_OUTPUT));
  160. addOutput(Port::create<PJ301MPort>(Vec(65, 223), Port::OUTPUT, module, Buttons::CH2_OUTPUT));
  161. addOutput(Port::create<PJ301MPort>(Vec(105, 223), Port::OUTPUT, module, Buttons::CH3_OUTPUT));
  162. addOutput(Port::create<PJ301MPort>(Vec(24, 274), Port::OUTPUT, module, Buttons::CH4_OUTPUT));
  163. addOutput(Port::create<PJ301MPort>(Vec(65, 274), Port::OUTPUT, module, Buttons::CH5_OUTPUT));
  164. addOutput(Port::create<PJ301MPort>(Vec(106, 274), Port::OUTPUT, module, Buttons::CH6_OUTPUT));
  165. addOutput(Port::create<PJ301MPort>(Vec(24, 324), Port::OUTPUT, module, Buttons::CH7_OUTPUT));
  166. addOutput(Port::create<PJ301MPort>(Vec(65, 324), Port::OUTPUT, module, Buttons::CH8_OUTPUT));
  167. addOutput(Port::create<PJ301MPort>(Vec(106, 324), Port::OUTPUT, module, Buttons::CH9_OUTPUT));
  168. addParam(ParamWidget::create<MedLEDButton>(Vec(15, 60), module, Buttons::RESET_PARAM, 0.0, 1.0, 0.0));
  169. addChild(ModuleLightWidget::create<MedLight<GreenLight>>(Vec(20, 65), module, Buttons::RESET_LIGHT));
  170. addParam(ParamWidget::create<MedLEDButton>(Vec(55, 60), module, Buttons::RESET_PARAM2, 0.0, 1.0, 0.0));
  171. addChild(ModuleLightWidget::create<MedLight<GreenLight>>(Vec(60, 65), module, Buttons::RESET_LIGHT2));
  172. addParam(ParamWidget::create<MedLEDButton>(Vec(95, 60), module, Buttons::RESET_PARAM3, 0.0, 1.0, 0.0));
  173. addChild(ModuleLightWidget::create<MedLight<GreenLight>>(Vec(100, 65), module, Buttons::RESET_LIGHT3));
  174. addParam(ParamWidget::create<MedLEDButton>(Vec(15, 100), module, Buttons::RESET_PARAM4, 0.0, 1.0, 0.0));
  175. addChild(ModuleLightWidget::create<MedLight<GreenLight>>(Vec(20, 105), module, Buttons::RESET_LIGHT4));
  176. addParam(ParamWidget::create<MedLEDButton>(Vec(55, 100), module, Buttons::RESET_PARAM5, 0.0, 1.0, 0.0));
  177. addChild(ModuleLightWidget::create<MedLight<GreenLight>>(Vec(60, 105), module, Buttons::RESET_LIGHT5));
  178. addParam(ParamWidget::create<MedLEDButton>(Vec(95, 100), module, Buttons::RESET_PARAM6, 0.0, 1.0, 0.0));
  179. addChild(ModuleLightWidget::create<MedLight<GreenLight>>(Vec(100, 105), module, Buttons::RESET_LIGHT6));
  180. addParam(ParamWidget::create<MedLEDButton>(Vec(15, 140), module, Buttons::RESET_PARAM7, 0.0, 1.0, 0.0));
  181. addChild(ModuleLightWidget::create<MedLight<GreenLight>>(Vec(20, 145), module, Buttons::RESET_LIGHT7));
  182. addParam(ParamWidget::create<MedLEDButton>(Vec(55, 140), module, Buttons::RESET_PARAM8, 0.0, 1.0, 0.0));
  183. addChild(ModuleLightWidget::create<MedLight<GreenLight>>(Vec(60, 145), module, Buttons::RESET_LIGHT8));
  184. addParam(ParamWidget::create<MedLEDButton>(Vec(95, 140), module, Buttons::RESET_PARAM9, 0.0, 1.0, 0.0));
  185. addChild(ModuleLightWidget::create<MedLight<GreenLight>>(Vec(100, 145), module, Buttons::RESET_LIGHT9));
  186. }
  187. Model *modelButtons = Model::create<Buttons, ButtonsWidget>("RJModules", "Buttons", "[LIVE] Buttons", UTILITY_TAG);