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.

153 lines
4.2KB

  1. #include <stdio.h>
  2. #include "alikins.hpp"
  3. namespace rack_plugin_Alikins {
  4. struct MomentaryOnButtons : Module {
  5. enum ParamIds {
  6. BUTTON1_PARAM,
  7. BUTTON2_PARAM,
  8. BUTTON3_PARAM,
  9. BUTTON4_PARAM,
  10. BUTTON5_PARAM,
  11. BUTTON6_PARAM,
  12. BUTTON7_PARAM,
  13. BUTTON8_PARAM,
  14. BUTTON9_PARAM,
  15. BUTTON10_PARAM,
  16. BUTTON11_PARAM,
  17. BUTTON12_PARAM,
  18. BUTTON13_PARAM,
  19. NUM_PARAMS
  20. };
  21. enum InputIds {
  22. BUTTON1_INPUT,
  23. BUTTON2_INPUT,
  24. BUTTON3_INPUT,
  25. BUTTON4_INPUT,
  26. BUTTON5_INPUT,
  27. BUTTON6_INPUT,
  28. BUTTON7_INPUT,
  29. BUTTON8_INPUT,
  30. BUTTON9_INPUT,
  31. BUTTON10_INPUT,
  32. BUTTON11_INPUT,
  33. BUTTON12_INPUT,
  34. BUTTON13_INPUT,
  35. NUM_INPUTS
  36. };
  37. enum OutputIds {
  38. BUTTON1_OUTPUT,
  39. BUTTON2_OUTPUT,
  40. BUTTON3_OUTPUT,
  41. BUTTON4_OUTPUT,
  42. BUTTON5_OUTPUT,
  43. BUTTON6_OUTPUT,
  44. BUTTON7_OUTPUT,
  45. BUTTON8_OUTPUT,
  46. BUTTON9_OUTPUT,
  47. BUTTON10_OUTPUT,
  48. BUTTON11_OUTPUT,
  49. BUTTON12_OUTPUT,
  50. BUTTON13_OUTPUT,
  51. NUM_OUTPUTS
  52. };
  53. enum LightIds {
  54. BLINK1_LIGHT,
  55. BLINK2_LIGHT,
  56. BLINK3_LIGHT,
  57. BLINK4_LIGHT,
  58. BLINK5_LIGHT,
  59. BLINK6_LIGHT,
  60. BLINK7_LIGHT,
  61. BLINK8_LIGHT,
  62. BLINK9_LIGHT,
  63. BLINK10_LIGHT,
  64. BLINK11_LIGHT,
  65. BLINK12_LIGHT,
  66. BLINK13_LIGHT,
  67. NUM_LIGHTS
  68. };
  69. MomentaryOnButtons() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  70. void step() override;
  71. // For more advanced Module features, read Rack's engine.hpp header file
  72. // - toJson, fromJson: serialization of internal data
  73. // - onSampleRateChange: event triggered by a change of sample rate
  74. // - reset, randomize: implements special behavior when user clicks these from the context menu
  75. };
  76. void MomentaryOnButtons::step() {
  77. for (int i = 0; i < MOMENTARY_BUTTONS; i++) {
  78. lights[BLINK1_LIGHT + i].setBrightness(0.0);
  79. outputs[BUTTON1_OUTPUT + i].value = 0.0;
  80. if (params[BUTTON1_PARAM + i].value) {
  81. outputs[BUTTON1_OUTPUT + i].value = 5.0;
  82. lights[BLINK1_LIGHT + i].setBrightness(1.0);
  83. }
  84. }
  85. }
  86. struct MomentaryOnButtonsWidget : ModuleWidget {
  87. MomentaryOnButtonsWidget(MomentaryOnButtons *module);
  88. };
  89. MomentaryOnButtonsWidget::MomentaryOnButtonsWidget(MomentaryOnButtons *module) : ModuleWidget(module) {
  90. box.size = Vec(4 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT);
  91. int x_offset = 0;
  92. int y_offset = 26;
  93. int x_start = 0;
  94. int y_start = 24;
  95. int x_pos = 0;
  96. int y_pos = 0;
  97. int light_radius = 7;
  98. {
  99. SVGPanel *panel = new SVGPanel();
  100. panel->box.size = box.size;
  101. panel->setBackground(SVG::load(assetPlugin(plugin, "res/MomentaryOnButtons.svg")));
  102. addChild(panel);
  103. }
  104. /*
  105. addChild(Widget::create<ScrewSilver>(Vec(RACK_GRID_WIDTH, 0)));
  106. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0)));
  107. addChild(Widget::create<ScrewSilver>(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  108. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  109. */
  110. for (int i = 0; i < MOMENTARY_BUTTONS; i++) {
  111. x_pos = x_start + x_offset;
  112. y_pos = y_start + (i * y_offset);
  113. addParam(ParamWidget::create<LEDButton>(Vec(x_pos + light_radius, y_pos + 3), module, MomentaryOnButtons::BUTTON1_PARAM + i, 0.0, 1.0, 0.0));
  114. addChild(ModuleLightWidget::create<MediumLight<RedLight>>(Vec(x_pos + 5 + light_radius, y_pos + light_radius), module, MomentaryOnButtons::BLINK1_LIGHT + i));
  115. addOutput(Port::create<PJ301MPort>(Vec(x_pos + 20 + light_radius, y_pos), Port::OUTPUT, module, MomentaryOnButtons::BUTTON1_OUTPUT + i));
  116. }
  117. }
  118. } // namespace rack_plugin_Alikins
  119. using namespace rack_plugin_Alikins;
  120. RACK_PLUGIN_MODEL_INIT(Alikins, MomentaryOnButtons) {
  121. Model *modelMomentaryOnButtons = Model::create<MomentaryOnButtons, MomentaryOnButtonsWidget>(
  122. "Alikins", "MomentaryOnButtons", "Momentary On Buttons", UTILITY_TAG);
  123. return modelMomentaryOnButtons;
  124. }