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.

115 lines
3.0KB

  1. //***********************************************************************************************
  2. //Blank Panel for VCV Rack by Marc Boulé
  3. //***********************************************************************************************
  4. #include "ImpromptuModular.hpp"
  5. namespace rack_plugin_ImpromptuModular {
  6. struct BlankPanel : Module {
  7. int panelTheme = 0;
  8. BlankPanel() : Module(0, 0, 0, 0) {
  9. onReset();
  10. }
  11. void onReset() override {
  12. }
  13. void onRandomize() override {
  14. }
  15. json_t *toJson() override {
  16. json_t *rootJ = json_object();
  17. // panelTheme
  18. json_object_set_new(rootJ, "panelTheme", json_integer(panelTheme));
  19. return rootJ;
  20. }
  21. void fromJson(json_t *rootJ) override {
  22. // panelTheme
  23. json_t *panelThemeJ = json_object_get(rootJ, "panelTheme");
  24. if (panelThemeJ)
  25. panelTheme = json_integer_value(panelThemeJ);
  26. }
  27. // Advances the module by 1 audio frame with duration 1.0 / engineGetSampleRate()
  28. void step() override {
  29. }
  30. };
  31. struct BlankPanelWidget : ModuleWidget {
  32. struct PanelThemeItem : MenuItem {
  33. BlankPanel *module;
  34. int theme;
  35. void onAction(EventAction &e) override {
  36. module->panelTheme = theme;
  37. }
  38. void step() override {
  39. rightText = (module->panelTheme == theme) ? "✔" : "";
  40. }
  41. };
  42. Menu *createContextMenu() override {
  43. Menu *menu = ModuleWidget::createContextMenu();
  44. MenuLabel *spacerLabel = new MenuLabel();
  45. menu->addChild(spacerLabel);
  46. BlankPanel *module = dynamic_cast<BlankPanel*>(this->module);
  47. assert(module);
  48. MenuLabel *themeLabel = new MenuLabel();
  49. themeLabel->text = "Panel Theme";
  50. menu->addChild(themeLabel);
  51. PanelThemeItem *lightItem = new PanelThemeItem();
  52. lightItem->text = lightPanelID;// ImpromptuModular.hpp
  53. lightItem->module = module;
  54. lightItem->theme = 0;
  55. menu->addChild(lightItem);
  56. PanelThemeItem *darkItem = new PanelThemeItem();
  57. darkItem->text = darkPanelID;// ImpromptuModular.hpp
  58. darkItem->module = module;
  59. darkItem->theme = 1;
  60. menu->addChild(darkItem);
  61. return menu;
  62. }
  63. BlankPanelWidget(BlankPanel *module) : ModuleWidget(module) {
  64. // Main panel from Inkscape
  65. DynamicSVGPanel *panel = new DynamicSVGPanel();
  66. panel->addPanel(SVG::load(assetPlugin(plugin, "res/light/BlankPanel.svg")));
  67. panel->addPanel(SVG::load(assetPlugin(plugin, "res/dark/BlankPanel_dark.svg")));
  68. box.size = panel->box.size;
  69. panel->mode = &module->panelTheme;
  70. addChild(panel);
  71. // Screws
  72. addChild(createDynamicScrew<IMScrew>(Vec(15, 0), &module->panelTheme));
  73. addChild(createDynamicScrew<IMScrew>(Vec(box.size.x-30, 0), &module->panelTheme));
  74. addChild(createDynamicScrew<IMScrew>(Vec(15, 365), &module->panelTheme));
  75. addChild(createDynamicScrew<IMScrew>(Vec(box.size.x-30, 365), &module->panelTheme));
  76. }
  77. };
  78. } // namespace rack_plugin_ImpromptuModular
  79. using namespace rack_plugin_ImpromptuModular;
  80. RACK_PLUGIN_MODEL_INIT(ImpromptuModular, BlankPanel) {
  81. Model *modelBlankPanel = Model::create<BlankPanel, BlankPanelWidget>("Impromptu Modular", "Blank-Panel", "MISC - Blank-Panel", BLANK_TAG);
  82. return modelBlankPanel;
  83. }