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.

226 lines
7.7KB

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