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.

231 lines
4.6KB

  1. #pragma once
  2. #include "common.hpp"
  3. #include <sstream>
  4. #include <iomanip>
  5. #include <algorithm>
  6. #include "M581Types.hpp"
  7. ////////////////////
  8. // module widgets
  9. ////////////////////
  10. namespace rack_plugin_TheXOR {
  11. struct M581;
  12. struct M581Widget : SequencerWidget
  13. {
  14. private:
  15. enum MENUACTIONS
  16. {
  17. RANDOMIZE_PITCH,
  18. RANDOMIZE_COUNTER,
  19. RANDOMIZE_MODE,
  20. RANDOMIZE_ENABLE
  21. };
  22. Menu *addContextMenu(Menu *menu) override;
  23. public:
  24. M581Widget(M581 *module);
  25. void onMenu(int action);
  26. };
  27. struct BefacoSlidePotFix : SVGSlider
  28. {
  29. BefacoSlidePotFix()
  30. {
  31. Vec margin = Vec(4.5, 4.5);
  32. maxHandlePos = Vec(mm2px(-3.09541 / 2.0 + 2.27312 / 2.0), -mm2px(5.09852 / 2.0)).plus(margin);
  33. minHandlePos = Vec(mm2px(-3.09541 / 2.0 + 2.27312 / 2.0), mm2px(27.51667 - 5.09852 / 2.0)).plus(margin);
  34. setSVGs(SVG::load(assetPlugin(plugin, "res/BefacoSlidePot.svg")), SVG::load(assetPlugin(plugin, "res/BefacoSlidePotHandle.svg")));
  35. background->box.pos = margin;
  36. box.size = background->box.size.plus(margin.mult(2));
  37. }
  38. };
  39. struct CounterSwitch : SVGFader
  40. {
  41. CounterSwitch()
  42. {
  43. snap = true;
  44. maxHandlePos = Vec(-mm2px(2.3-2.3/2.0), 0);
  45. minHandlePos = Vec(-mm2px(2.3-2.3/2.0), mm2px(24-2.8));
  46. background->svg = SVG::load(assetPlugin(plugin, "res/counterSwitchPot.svg"));
  47. background->wrap();
  48. background->box.pos = Vec(0, 0);
  49. box.size = background->box.size;
  50. handle->svg = SVG::load(assetPlugin(plugin, "res/counterSwitchPotHandle.svg"));
  51. handle->wrap();
  52. }
  53. void randomize() override { setValue(roundf(randomUniform() * maxValue)); }
  54. };
  55. struct RunModeDisplay : TransparentWidget
  56. {
  57. float *mode;
  58. std::shared_ptr<Font> font;
  59. RunModeDisplay()
  60. {
  61. font = Font::load(assetPlugin(plugin, "res/Segment7Standard.ttf"));
  62. }
  63. void draw(NVGcontext *vg) override
  64. {
  65. // Background
  66. NVGcolor backgroundColor = nvgRGB(0x20, 0x20, 0x20);
  67. NVGcolor borderColor = nvgRGB(0x10, 0x10, 0x10);
  68. nvgBeginPath(vg);
  69. nvgRoundedRect(vg, 0.0, 0.0, box.size.x, box.size.y, 4.0);
  70. nvgFillColor(vg, backgroundColor);
  71. nvgFill(vg);
  72. nvgStrokeWidth(vg, 1.0);
  73. nvgStrokeColor(vg, borderColor);
  74. nvgStroke(vg);
  75. // text
  76. nvgFontSize(vg, 18);
  77. nvgFontFaceId(vg, font->handle);
  78. nvgTextLetterSpacing(vg, 2.5);
  79. Vec textPos = Vec(2, 18);
  80. NVGcolor textColor = nvgRGB(0xdf, 0xd2, 0x2c);
  81. nvgFillColor(vg, nvgTransRGBA(textColor, 16));
  82. nvgText(vg, textPos.x, textPos.y, "~~", NULL);
  83. textColor = nvgRGB(0xda, 0xe9, 0x29);
  84. nvgFillColor(vg, nvgTransRGBA(textColor, 16));
  85. nvgText(vg, textPos.x, textPos.y, "\\\\", NULL);
  86. textColor = nvgRGB(0xf0, 0x00, 0x00);
  87. nvgFillColor(vg, textColor);
  88. nvgText(vg, textPos.x, textPos.y, run_modes[int(std::round(*mode))], NULL);
  89. }
  90. private:
  91. const char *run_modes[5] = {
  92. "FWD",
  93. "BWD",
  94. "PNG",
  95. "BRN",
  96. "RND"
  97. };
  98. };
  99. struct M581 : Module
  100. {
  101. enum ParamIds
  102. {
  103. GATE_SWITCH,
  104. COUNTER_SWITCH = GATE_SWITCH + 8,
  105. STEP_NOTES = COUNTER_SWITCH + 8,
  106. STEP_ENABLE = STEP_NOTES + 8,
  107. GATE_TIME = STEP_ENABLE + 8,
  108. SLIDE_TIME,
  109. NUM_STEPS,
  110. RUN_MODE,
  111. STEP_DIV,
  112. MAXVOLTS
  113. , NUM_PARAMS
  114. };
  115. enum InputIds
  116. {
  117. CLOCK,
  118. RESET,
  119. NUM_INPUTS
  120. };
  121. enum OutputIds
  122. {
  123. CV,
  124. GATE,
  125. NUM_OUTPUTS
  126. };
  127. enum LightIds
  128. {
  129. LED_STEP,
  130. LED_SUBDIV = LED_STEP + 8,
  131. temp = LED_SUBDIV + 8,
  132. NUM_LIGHTS
  133. };
  134. M581() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS)
  135. {
  136. #ifdef LAUNCHPAD
  137. drv = new LaunchpadBindingDriver(this, Scene2, 3);
  138. drv->SetAutoPageKey(LaunchpadKey::SESSION, 0);
  139. drv->SetAutoPageKey(LaunchpadKey::NOTE, 1);
  140. drv->SetAutoPageKey(LaunchpadKey::DEVICE, 2);
  141. #endif
  142. #ifdef OSCTEST_MODULE
  143. oscDrv = new OSCDriver(this, 2);
  144. #endif
  145. on_loaded();
  146. }
  147. #ifdef DIGITAL_EXT
  148. ~M581()
  149. {
  150. #if defined(LAUNCHPAD)
  151. delete drv;
  152. #endif
  153. #if defined(OSCTEST_MODULE)
  154. delete oscDrv;
  155. #endif
  156. }
  157. #endif
  158. void step() override;
  159. void reset() override { load(); }
  160. void randomize() override { load(); }
  161. void fromJson(json_t *root) override { Module::fromJson(root); on_loaded(); }
  162. json_t *toJson() override
  163. {
  164. json_t *rootJ = json_object();
  165. return rootJ;
  166. }
  167. float *getAddress(int var)
  168. {
  169. switch(var)
  170. {
  171. case 0: return &params[M581::RUN_MODE].value;
  172. case 1: return &params[M581::NUM_STEPS].value;
  173. }
  174. return NULL;
  175. }
  176. #ifdef DIGITAL_EXT
  177. float connected;
  178. #endif
  179. #ifdef LAUNCHPAD
  180. LaunchpadBindingDriver *drv;
  181. #endif
  182. #if defined(OSCTEST_MODULE)
  183. OSCDriver *oscDrv;
  184. #endif
  185. private:
  186. CV_LINE cvControl;
  187. GATE_LINE gateControl;
  188. TIMER Timer;
  189. STEP_COUNTER stepCounter;
  190. ParamGetter getter;
  191. void _reset();
  192. void on_loaded();
  193. void load();
  194. void beginNewStep();
  195. void showCurStep(int cur_step, int sub_div);
  196. bool any();
  197. SchmittTrigger clockTrigger;
  198. SchmittTrigger resetTrigger;
  199. };
  200. } // namespace rack_plugin_TheXOR