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.

179 lines
5.0KB

  1. /* *\
  2. ** __ ___ ______ **
  3. ** / / / _ \/_ __/ **
  4. ** / /__/ , _/ / / Lindenberg **
  5. ** /____/_/|_| /_/ Research Tec. **
  6. ** **
  7. ** **
  8. ** https://github.com/lindenbergresearch/LRTRack **
  9. ** heapdump@icloud.com **
  10. ** **
  11. ** Sound Modules for VCV Rack **
  12. ** Copyright 2017/2018 by Patrick Lindenberg / LRT **
  13. ** **
  14. ** For Redistribution and use in source and binary forms, **
  15. ** with or without modification please see LICENSE. **
  16. ** **
  17. \* */
  18. #pragma once
  19. #include "LRComponents.hpp"
  20. #include "rack.hpp"
  21. #include "asset.hpp"
  22. #include "widgets.hpp"
  23. static const char *const JSON_GESTALT_KEY = "gestaltID";
  24. static const char *const JSON_GRADIENT_KEY = "gradient";
  25. static const char *const JSON_PATINA_KEY = "patina";
  26. static const char *const JSON_PATINA_A_X = "patina_a_x";
  27. static const char *const JSON_PATINA_A_Y = "patina_a_y";
  28. static const char *const JSON_PATINA_B_X = "patina_b_x";
  29. static const char *const JSON_PATINA_B_Y = "patina_b_y";
  30. namespace lrt {
  31. using std::string;
  32. using std::vector;
  33. static const string STR_CHECKMARK_UNICODE = "✔";
  34. /**
  35. * @brief Standard LR Module definition
  36. */
  37. struct LRModule : public Module {
  38. LRGestalt *gestalt = nullptr;
  39. /**
  40. * @brief Default constructor derived from rack
  41. * @param numParams
  42. * @param numInputs
  43. * @param numOutputs
  44. * @param numLights
  45. */
  46. explicit LRModule(int numParams, int numInputs, int numOutputs, int numLights);
  47. };
  48. /**
  49. * @brief Standard LR ModuleWidget definition
  50. */
  51. struct LRModuleWidget : ModuleWidget {
  52. /* standard module panel */
  53. LRPanel *panel = nullptr;
  54. /* Gestalt ID and UI settings */
  55. LRGestalt gestalt = LIGHT; // DARK == default
  56. LRGestalt prevGestalt = NIL; // set to NIL to trigger change event on first start
  57. bool gradient = true; // gradient used at panel
  58. bool patina = false; // patina used at panel
  59. bool noVariants = false; // if set all gestalt options and menus are disabled
  60. Vec patinaXY = Vec(0, 0); // randomized coordinates
  61. /**
  62. * @brief Default constructor derived from rack
  63. * @param module LRModule instance
  64. */
  65. explicit LRModuleWidget(LRModule *module) : ModuleWidget(module) {
  66. // pass gestalt pointer to module, to point to the origin at the widget
  67. module->gestalt = &gestalt;
  68. panel = new LRPanel();
  69. }
  70. /**
  71. * @brief Represents an Item for selecting the gestalt
  72. */
  73. struct GestaltItem : MenuItem {
  74. LRGestalt gestaltM;
  75. LRModuleWidget *widget;
  76. GestaltItem(LRGestalt gestaltM, LRModuleWidget *widget) : gestaltM(gestaltM), widget(widget) {}
  77. void onAction(EventAction &e) override {
  78. if (widget != nullptr) {
  79. // set new global gestalt to current ID of selected menu item
  80. widget->gestalt = gestaltM;
  81. }
  82. }
  83. void step() override {
  84. rightText = (widget->gestalt == gestaltM) ? STR_CHECKMARK_UNICODE : "";
  85. }
  86. };
  87. /**
  88. * @brief Represents a gradient select item
  89. */
  90. struct GradientItem : MenuItem {
  91. LRPanel *panel;
  92. explicit GradientItem(LRPanel *panel) : panel(panel) {}
  93. void onAction(EventAction &e) override {
  94. if (panel != nullptr) {
  95. panel->setGradientVariant(true);
  96. panel->dirty = true;
  97. }
  98. }
  99. void step() override {
  100. rightText = *panel->gradient ? STR_CHECKMARK_UNICODE : "";
  101. }
  102. };
  103. /**
  104. * @brief Represents a gradient select item
  105. */
  106. struct PatinaItem : MenuItem {
  107. LRPanel *panel;
  108. explicit PatinaItem(LRPanel *panel) : panel(panel) {}
  109. void onAction(EventAction &e) override {
  110. if (panel != nullptr) {
  111. panel->setPatina(!*panel->patina); // invert flag on trigger
  112. panel->dirty = true;
  113. }
  114. }
  115. void step() override {
  116. rightText = *panel->patina ? STR_CHECKMARK_UNICODE : "";
  117. }
  118. };
  119. void step() override;
  120. /**
  121. * @brief Create standard menu for all modules
  122. * @return
  123. */
  124. Menu *createContextMenu() override;
  125. json_t *toJson() override;
  126. void fromJson(json_t *rootJ) override;
  127. void randomize() override;
  128. };
  129. }