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.

308 lines
7.7KB

  1. #pragma once
  2. #include "rack.hpp"
  3. #include "QuantizeUtils.cpp"
  4. using namespace rack;
  5. RACK_PLUGIN_DECLARE(JW_Modules);
  6. #ifdef USE_VST2
  7. #define plugin "JW-Modules"
  8. #endif // USE_VST2
  9. namespace rack_plugin_JW_Modules {
  10. ////////////////////////////////////////////// LABELS //////////////////////////////////////////////
  11. struct CenteredLabel : Widget {
  12. std::string text;
  13. int fontSize;
  14. CenteredLabel(int _fontSize = 12) {
  15. fontSize = _fontSize;
  16. box.size.y = BND_WIDGET_HEIGHT;
  17. }
  18. void draw(NVGcontext *vg) override {
  19. nvgTextAlign(vg, NVG_ALIGN_CENTER);
  20. nvgFillColor(vg, nvgRGB(25, 150, 252));
  21. nvgFontSize(vg, fontSize);
  22. nvgText(vg, box.pos.x, box.pos.y, text.c_str(), NULL);
  23. }
  24. };
  25. ////////////////////////////////////////////// KNOBS //////////////////////////////////////////////
  26. struct SmallWhiteKnob : RoundKnob {
  27. SmallWhiteKnob() {
  28. setSVG(SVG::load(assetPlugin(plugin, "res/SmallWhiteKnob.svg")));
  29. }
  30. CenteredLabel* linkedLabel = nullptr;
  31. void connectLabel(CenteredLabel* label) {
  32. linkedLabel = label;
  33. if (linkedLabel) {
  34. linkedLabel->text = formatCurrentValue();
  35. }
  36. }
  37. void onChange(EventChange &e) override {
  38. RoundKnob::onChange(e);
  39. if (linkedLabel) {
  40. linkedLabel->text = formatCurrentValue();
  41. }
  42. }
  43. virtual std::string formatCurrentValue() {
  44. return std::to_string(static_cast<unsigned int>(value));
  45. }
  46. };
  47. struct NoteKnob : SmallWhiteKnob {
  48. QuantizeUtils *quantizeUtils;
  49. NoteKnob(){
  50. snap = true;
  51. }
  52. std::string formatCurrentValue() override {
  53. return quantizeUtils->noteName(int(value));
  54. }
  55. };
  56. struct ScaleKnob : SmallWhiteKnob {
  57. QuantizeUtils *quantizeUtils;
  58. ScaleKnob(){
  59. snap = true;
  60. }
  61. std::string formatCurrentValue() override {
  62. return quantizeUtils->scaleName(int(value));
  63. }
  64. };
  65. struct JwSmallSnapKnob : SmallWhiteKnob {
  66. JwSmallSnapKnob() {
  67. snap = true;
  68. }
  69. };
  70. struct JwTinyKnob : RoundKnob {
  71. JwTinyKnob() {
  72. setSVG(SVG::load(assetPlugin(plugin, "res/TinyWhiteKnob.svg")));
  73. }
  74. };
  75. struct BPMPartKnob : JwSmallSnapKnob {
  76. BPMPartKnob(){}
  77. };
  78. ////////////////////////////////////////////// SWITCHES //////////////////////////////////////////////
  79. struct JwHorizontalSwitch : SVGSwitch, ToggleSwitch {
  80. JwHorizontalSwitch() {
  81. addFrame(SVG::load(assetPlugin(plugin, "res/Switch_Horizontal_0.svg")));
  82. addFrame(SVG::load(assetPlugin(plugin, "res/Switch_Horizontal_1.svg")));
  83. }
  84. };
  85. struct JwVerticalSwitch : SVGSwitch, ToggleSwitch {
  86. JwVerticalSwitch() {
  87. addFrame(SVG::load(assetPlugin(plugin, "res/Switch_Vertical_0.svg")));
  88. addFrame(SVG::load(assetPlugin(plugin, "res/Switch_Vertical_1.svg")));
  89. }
  90. };
  91. struct BowlSwitch : SVGSwitch, ToggleSwitch {
  92. BowlSwitch() {
  93. addFrame(SVG::load(assetPlugin(plugin, "res/Bowl-no-food.svg")));
  94. addFrame(SVG::load(assetPlugin(plugin, "res/Bowl-food.svg")));
  95. }
  96. };
  97. ////////////////////////////////////////////// PORTS //////////////////////////////////////////////
  98. struct TinyPJ301MPort : SVGPort {
  99. TinyPJ301MPort() {
  100. background->svg = SVG::load(assetPlugin(plugin, "res/TinyPJ301M.svg"));
  101. background->wrap();
  102. box.size = background->box.size;
  103. }
  104. };
  105. struct Orange_TinyPJ301MPort : SVGPort {
  106. Orange_TinyPJ301MPort() {
  107. background->svg = SVG::load(assetPlugin(plugin, "res/TinyPJ301M_orange.svg"));
  108. background->wrap();
  109. box.size = background->box.size;
  110. }
  111. };
  112. struct Yellow_TinyPJ301MPort : SVGPort {
  113. Yellow_TinyPJ301MPort() {
  114. background->svg = SVG::load(assetPlugin(plugin, "res/TinyPJ301M_yellow.svg"));
  115. background->wrap();
  116. box.size = background->box.size;
  117. }
  118. };
  119. struct Purple_TinyPJ301MPort : SVGPort {
  120. Purple_TinyPJ301MPort() {
  121. background->svg = SVG::load(assetPlugin(plugin, "res/TinyPJ301M_purple.svg"));
  122. background->wrap();
  123. box.size = background->box.size;
  124. }
  125. };
  126. struct Blue_TinyPJ301MPort : SVGPort {
  127. Blue_TinyPJ301MPort() {
  128. background->svg = SVG::load(assetPlugin(plugin, "res/TinyPJ301M_blue.svg"));
  129. background->wrap();
  130. box.size = background->box.size;
  131. }
  132. };
  133. struct White_TinyPJ301MPort : SVGPort {
  134. White_TinyPJ301MPort() {
  135. background->svg = SVG::load(assetPlugin(plugin, "res/TinyPJ301M_white.svg"));
  136. background->wrap();
  137. box.size = background->box.size;
  138. }
  139. };
  140. ////////////////////////////////////////////// LIGHTS //////////////////////////////////////////////
  141. struct MyBlueValueLight : ModuleLightWidget {
  142. MyBlueValueLight() {
  143. firstLightId = 1;
  144. addBaseColor(nvgRGB(25, 150, 252));
  145. }
  146. };
  147. struct MyGreenValueLight : ModuleLightWidget {
  148. MyGreenValueLight() {
  149. firstLightId = 1;
  150. addBaseColor(nvgRGB(0, 200, 0));
  151. }
  152. };
  153. struct MyRedValueLight : ModuleLightWidget {
  154. MyRedValueLight() {
  155. firstLightId = 1;
  156. addBaseColor(nvgRGB(200, 0, 0));
  157. }
  158. };
  159. ////////////////////////////////////////////// BUTTONS //////////////////////////////////////////////
  160. struct RightMoveButton : SVGSwitch, MomentarySwitch {
  161. RightMoveButton() {
  162. addFrame(SVG::load(assetPlugin(plugin, "res/RightButton.svg")));
  163. addFrame(SVG::load(assetPlugin(plugin, "res/RightButtonDown.svg")));
  164. }
  165. };
  166. struct LeftMoveButton : SVGSwitch, MomentarySwitch {
  167. LeftMoveButton() {
  168. addFrame(SVG::load(assetPlugin(plugin, "res/LeftButton.svg")));
  169. addFrame(SVG::load(assetPlugin(plugin, "res/LeftButtonDown.svg")));
  170. }
  171. };
  172. struct DownMoveButton : SVGSwitch, MomentarySwitch {
  173. DownMoveButton() {
  174. addFrame(SVG::load(assetPlugin(plugin, "res/DownButton.svg")));
  175. addFrame(SVG::load(assetPlugin(plugin, "res/DownButtonDown.svg")));
  176. }
  177. };
  178. struct UpMoveButton : SVGSwitch, MomentarySwitch {
  179. UpMoveButton() {
  180. addFrame(SVG::load(assetPlugin(plugin, "res/UpButton.svg")));
  181. addFrame(SVG::load(assetPlugin(plugin, "res/UpButtonDown.svg")));
  182. }
  183. };
  184. struct RndMoveButton : SVGSwitch, MomentarySwitch {
  185. RndMoveButton() {
  186. addFrame(SVG::load(assetPlugin(plugin, "res/RndButton.svg")));
  187. addFrame(SVG::load(assetPlugin(plugin, "res/RndButtonDown.svg")));
  188. }
  189. };
  190. struct RepMoveButton : SVGSwitch, MomentarySwitch {
  191. RepMoveButton() {
  192. addFrame(SVG::load(assetPlugin(plugin, "res/RepButton.svg")));
  193. addFrame(SVG::load(assetPlugin(plugin, "res/RepButtonDown.svg")));
  194. }
  195. };
  196. struct TinyButton : SVGSwitch, MomentarySwitch {
  197. TinyButton() {
  198. addFrame(SVG::load(assetPlugin(plugin, "res/TinyButtonUp.svg")));
  199. addFrame(SVG::load(assetPlugin(plugin, "res/TinyButtonDown.svg")));
  200. }
  201. };
  202. struct SmallButton : SVGSwitch, MomentarySwitch {
  203. SmallButton() {
  204. addFrame(SVG::load(assetPlugin(plugin, "res/SmallButtonUp.svg")));
  205. addFrame(SVG::load(assetPlugin(plugin, "res/SmallButtonDown.svg")));
  206. }
  207. };
  208. ////////////////////////////////////////////// SCREWS //////////////////////////////////////////////
  209. struct Snowflake : SVGScrew {
  210. Snowflake() {
  211. sw->setSVG(SVG::load(assetPlugin(plugin, "res/SnowFlake.svg")));
  212. box.size = sw->box.size;
  213. }
  214. };
  215. struct WavHeadLogo : SVGScrew {
  216. WavHeadLogo() {
  217. sw->setSVG(SVG::load(assetPlugin(plugin, "res/WavHeadSmall.svg")));
  218. box.size = sw->box.size;
  219. }
  220. };
  221. struct Screw_J : SVGScrew {
  222. Screw_J() {
  223. sw->setSVG(SVG::load(assetPlugin(plugin, "res/Screw_J.svg")));
  224. box.size = sw->box.size;
  225. }
  226. };
  227. struct Screw_W : SVGScrew {
  228. Screw_W() {
  229. sw->setSVG(SVG::load(assetPlugin(plugin, "res/Screw_W.svg")));
  230. box.size = sw->box.size;
  231. }
  232. };
  233. struct CatScrew : SVGScrew {
  234. CatScrew() {
  235. sw->setSVG(SVG::load(assetPlugin(plugin, "res/Cat.svg")));
  236. box.size = sw->box.size;
  237. }
  238. };
  239. struct HairballScrew : SVGScrew {
  240. HairballScrew() {
  241. sw->setSVG(SVG::load(assetPlugin(plugin, "res/Hairball.svg")));
  242. box.size = sw->box.size;
  243. }
  244. };
  245. ////////////////////////////////////////////// WIDGETS //////////////////////////////////////////////
  246. inline int clampijw(int x, int minimum, int maximum) {
  247. return min(max(x, minimum), maximum);
  248. }
  249. inline float clampfjw(float x, float minimum, float maximum) {
  250. return fminf(fmaxf(x, minimum), maximum);
  251. }
  252. inline float rescalefjw(float x, float xMin, float xMax, float yMin, float yMax) {
  253. return yMin + (x - xMin) / (xMax - xMin) * (yMax - yMin);
  254. }
  255. } // namespace rack_plugin_JW_Modules