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.

194 lines
4.7KB

  1. #include "HetrickCV.hpp"
  2. #define NUM_PANELS 5
  3. namespace rack_plugin_HetrickCV {
  4. struct BlankPanel : Module
  5. {
  6. enum ParamIds
  7. {
  8. NUM_PARAMS
  9. };
  10. enum InputIds
  11. {
  12. NUM_INPUTS
  13. };
  14. enum OutputIds
  15. {
  16. NUM_OUTPUTS
  17. };
  18. enum LightIds
  19. {
  20. NUM_LIGHTS
  21. };
  22. int panel = 0;
  23. BlankPanel() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  24. void step() override {}
  25. void reset() override
  26. {
  27. panel = 0;
  28. }
  29. void randomize() override
  30. {
  31. panel = round(randomf() * (NUM_PANELS - 1.0f));
  32. }
  33. json_t *toJson() override
  34. {
  35. json_t *rootJ = json_object();
  36. json_object_set_new(rootJ, "panel", json_integer(panel));
  37. return rootJ;
  38. }
  39. void fromJson(json_t *rootJ) override
  40. {
  41. json_t *panelJ = json_object_get(rootJ, "panel");
  42. if (panelJ)
  43. panel = json_integer_value(panelJ);
  44. }
  45. };
  46. struct BlankPanelWidget : ModuleWidget
  47. {
  48. SVGPanel *panel1;
  49. SVGPanel *panel2;
  50. SVGPanel *panel3;
  51. SVGPanel *panel4;
  52. SVGPanel *panel5;
  53. BlankPanelWidget(BlankPanel *module);
  54. void step() override;
  55. Menu *createContextMenu() override;
  56. };
  57. BlankPanelWidget::BlankPanelWidget(BlankPanel *module) : ModuleWidget(module)
  58. {
  59. box.size = Vec(6 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT);
  60. panel1 = new SVGPanel();
  61. panel1->box.size = box.size;
  62. panel1->setBackground(SVG::load(assetPlugin(plugin, "res/Blanks/BlankPanel3.svg")));
  63. addChild(panel1);
  64. panel2 = new SVGPanel();
  65. panel2->box.size = box.size;
  66. panel2->setBackground(SVG::load(assetPlugin(plugin, "res/Blanks/BlankPanel7.svg")));
  67. addChild(panel2);
  68. panel3 = new SVGPanel();
  69. panel3->box.size = box.size;
  70. panel3->setBackground(SVG::load(assetPlugin(plugin, "res/Blanks/BlankPanel2.svg")));
  71. addChild(panel3);
  72. panel4 = new SVGPanel();
  73. panel4->box.size = box.size;
  74. panel4->setBackground(SVG::load(assetPlugin(plugin, "res/Blanks/BlankPanel8.svg")));
  75. addChild(panel4);
  76. panel5 = new SVGPanel();
  77. panel5->box.size = box.size;
  78. panel5->setBackground(SVG::load(assetPlugin(plugin, "res/Blanks/BlankPanel1.svg")));
  79. addChild(panel5);
  80. addChild(Widget::create<ScrewSilver>(Vec(15, 0)));
  81. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 30, 0)));
  82. addChild(Widget::create<ScrewSilver>(Vec(15, 365)));
  83. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 30, 365)));
  84. }
  85. void BlankPanelWidget::step()
  86. {
  87. BlankPanel *blank = dynamic_cast<BlankPanel*>(module);
  88. assert(blank);
  89. panel1->visible = (blank->panel == 0);
  90. panel2->visible = (blank->panel == 1);
  91. panel3->visible = (blank->panel == 2);
  92. panel4->visible = (blank->panel == 3);
  93. panel5->visible = (blank->panel == 4);
  94. ModuleWidget::step();
  95. }
  96. struct Panel1Item : MenuItem
  97. {
  98. BlankPanel *blank;
  99. void onAction(EventAction &e) override { blank->panel = 0; }
  100. void step() override {
  101. rightText = (blank->panel == 0) ? "✔" : "";
  102. MenuItem::step();
  103. }
  104. };
  105. struct Panel2Item : MenuItem
  106. {
  107. BlankPanel *blank;
  108. void onAction(EventAction &e) override { blank->panel = 1; }
  109. void step() override {
  110. rightText = (blank->panel == 1) ? "✔" : "";
  111. MenuItem::step();
  112. }
  113. };
  114. struct Panel3Item : MenuItem
  115. {
  116. BlankPanel *blank;
  117. void onAction(EventAction &e) override { blank->panel = 2; }
  118. void step() override {
  119. rightText = (blank->panel == 2) ? "✔" : "";
  120. MenuItem::step();
  121. }
  122. };
  123. struct Panel4Item : MenuItem
  124. {
  125. BlankPanel *blank;
  126. void onAction(EventAction &e) override { blank->panel = 3; }
  127. void step() override {
  128. rightText = (blank->panel == 3) ? "✔" : "";
  129. MenuItem::step();
  130. }
  131. };
  132. struct Panel5Item : MenuItem
  133. {
  134. BlankPanel *blank;
  135. void onAction(EventAction &e) override { blank->panel = 4; }
  136. void step() override {
  137. rightText = (blank->panel == 4) ? "✔" : "";
  138. MenuItem::step();
  139. }
  140. };
  141. Menu *BlankPanelWidget::createContextMenu()
  142. {
  143. Menu *menu = ModuleWidget::createContextMenu();
  144. BlankPanel *blank = dynamic_cast<BlankPanel*>(module);
  145. assert(blank);
  146. menu->addChild(construct<MenuEntry>());
  147. menu->addChild(construct<MenuLabel>(&MenuLabel::text, "Panel Art"));
  148. menu->addChild(construct<Panel1Item>(&Panel1Item::text, "Sideways Logo", &Panel1Item::blank, blank));
  149. menu->addChild(construct<Panel2Item>(&Panel2Item::text, "Bleeding Edge", &Panel2Item::blank, blank));
  150. menu->addChild(construct<Panel3Item>(&Panel3Item::text, "Hetrick Stack", &Panel3Item::blank, blank));
  151. menu->addChild(construct<Panel4Item>(&Panel4Item::text, "Simple CV", &Panel4Item::blank, blank));
  152. menu->addChild(construct<Panel5Item>(&Panel5Item::text, "Plain Jane", &Panel5Item::blank, blank));
  153. return menu;
  154. }
  155. } // namespace rack_plugin_HetrickCV
  156. using namespace rack_plugin_HetrickCV;
  157. RACK_PLUGIN_MODEL_INIT(HetrickCV, BlankPanel) {
  158. Model *modelBlankPanel = Model::create<BlankPanel, BlankPanelWidget>("HetrickCV", "BlankPanel", "Blank Panel");
  159. return modelBlankPanel;
  160. }