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.

componentlibrary.hpp 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802
  1. #pragma once
  2. #include <app/SvgKnob.hpp>
  3. #include <app/SvgSlider.hpp>
  4. #include <app/SvgPort.hpp>
  5. #include <app/ModuleLightWidget.hpp>
  6. #include <app/SvgSwitch.hpp>
  7. #include <app/SvgScrew.hpp>
  8. #include <asset.hpp>
  9. namespace rack {
  10. /** Component Library by [Grayscale](https://grayscale.info/).
  11. Copied from `LICENSE.md`:
  12. The **Component Library graphics** in the `res/ComponentLibrary` directory are copyright © 2019 [Grayscale](http://grayscale.info/) and licensed under [CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/).
  13. You may not freely sell plugins using Component Library graphics.
  14. However, a free commercial license is available for plugins sold through the [VCV Store](https://vcvrack.com/plugins.html).
  15. Email contact@vcvrack.com for more information about licensing or the VCV Store.
  16. */
  17. namespace componentlibrary {
  18. ////////////////////
  19. // Color scheme
  20. ////////////////////
  21. static const NVGcolor SCHEME_BLACK_TRANSPARENT = nvgRGBA(0x00, 0x00, 0x00, 0x00);
  22. static const NVGcolor SCHEME_BLACK = nvgRGB(0x00, 0x00, 0x00);
  23. static const NVGcolor SCHEME_WHITE = nvgRGB(0xff, 0xff, 0xff);
  24. static const NVGcolor SCHEME_RED = nvgRGB(0xed, 0x2c, 0x24);
  25. static const NVGcolor SCHEME_ORANGE = nvgRGB(0xf2, 0xb1, 0x20);
  26. static const NVGcolor SCHEME_YELLOW = nvgRGB(0xf9, 0xdf, 0x1c);
  27. static const NVGcolor SCHEME_GREEN = nvgRGB(0x90, 0xc7, 0x3e);
  28. static const NVGcolor SCHEME_CYAN = nvgRGB(0x22, 0xe6, 0xef);
  29. static const NVGcolor SCHEME_BLUE = nvgRGB(0x29, 0xb2, 0xef);
  30. static const NVGcolor SCHEME_PURPLE = nvgRGB(0xd5, 0x2b, 0xed);
  31. static const NVGcolor SCHEME_LIGHT_GRAY = nvgRGB(0xe6, 0xe6, 0xe6);
  32. static const NVGcolor SCHEME_DARK_GRAY = nvgRGB(0x17, 0x17, 0x17);
  33. ////////////////////
  34. // Lights
  35. ////////////////////
  36. /*
  37. Many of these classes use CRTP (https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern).
  38. To use a red light with its default base class for example, use `RedLight` or `TRedLight<>`. (They are synonymous.)
  39. Use the `TBase` template argument if you want a different base class.
  40. E.g. `RectangleLight<RedLight>`
  41. Although this paradigm might seem confusing at first, it ends up being extremely simple in your plugin code and perfect for "decorating" your classes with appearance traits and behavioral properties.
  42. For example, need a slider with a green LED? Just use
  43. createLightParamCentered<LEDLightSlider<GreenLight>>(...)
  44. */
  45. template <typename TBase = app::ModuleLightWidget>
  46. struct TGrayModuleLightWidget : TBase {
  47. TGrayModuleLightWidget() {
  48. this->bgColor = nvgRGB(0x5a, 0x5a, 0x5a);
  49. this->borderColor = nvgRGBA(0, 0, 0, 0x60);
  50. }
  51. };
  52. typedef TGrayModuleLightWidget<> GrayModuleLightWidget;
  53. template <typename TBase = GrayModuleLightWidget>
  54. struct TRedLight : TBase {
  55. TRedLight() {
  56. this->addBaseColor(SCHEME_RED);
  57. }
  58. };
  59. typedef TRedLight<> RedLight;
  60. template <typename TBase = GrayModuleLightWidget>
  61. struct TGreenLight : TBase {
  62. TGreenLight() {
  63. this->addBaseColor(SCHEME_GREEN);
  64. }
  65. };
  66. typedef TGreenLight<> GreenLight;
  67. template <typename TBase = GrayModuleLightWidget>
  68. struct TYellowLight : TBase {
  69. TYellowLight() {
  70. this->addBaseColor(SCHEME_YELLOW);
  71. }
  72. };
  73. typedef TYellowLight<> YellowLight;
  74. template <typename TBase = GrayModuleLightWidget>
  75. struct TBlueLight : TBase {
  76. TBlueLight() {
  77. this->addBaseColor(SCHEME_BLUE);
  78. }
  79. };
  80. typedef TBlueLight<> BlueLight;
  81. template <typename TBase = GrayModuleLightWidget>
  82. struct TWhiteLight : TBase {
  83. TWhiteLight() {
  84. this->addBaseColor(SCHEME_WHITE);
  85. }
  86. };
  87. typedef TWhiteLight<> WhiteLight;
  88. /** Reads two adjacent lightIds, so `lightId` and `lightId + 1` must be defined */
  89. template <typename TBase = GrayModuleLightWidget>
  90. struct TGreenRedLight : TBase {
  91. TGreenRedLight() {
  92. this->addBaseColor(SCHEME_GREEN);
  93. this->addBaseColor(SCHEME_RED);
  94. }
  95. };
  96. typedef TGreenRedLight<> GreenRedLight;
  97. template <typename TBase = GrayModuleLightWidget>
  98. struct TRedGreenBlueLight : TBase {
  99. TRedGreenBlueLight() {
  100. this->addBaseColor(SCHEME_RED);
  101. this->addBaseColor(SCHEME_GREEN);
  102. this->addBaseColor(SCHEME_BLUE);
  103. }
  104. };
  105. typedef TRedGreenBlueLight<> RedGreenBlueLight;
  106. /** Based on the size of 5mm LEDs */
  107. template <typename TBase>
  108. struct LargeLight : TBase {
  109. LargeLight() {
  110. this->box.size = app::mm2px(math::Vec(5.179, 5.179));
  111. }
  112. };
  113. /** Based on the size of 3mm LEDs */
  114. template <typename TBase>
  115. struct MediumLight : TBase {
  116. MediumLight() {
  117. this->box.size = app::mm2px(math::Vec(3.176, 3.176));
  118. }
  119. };
  120. /** Based on the size of 2mm LEDs */
  121. template <typename TBase>
  122. struct SmallLight : TBase {
  123. SmallLight() {
  124. this->box.size = app::mm2px(math::Vec(2.176, 2.176));
  125. }
  126. };
  127. /** Based on the size of 1mm LEDs */
  128. template <typename TBase>
  129. struct TinyLight : TBase {
  130. TinyLight() {
  131. this->box.size = app::mm2px(math::Vec(1.088, 1.088));
  132. }
  133. };
  134. template <typename TBase>
  135. struct RectangleLight : TBase {
  136. void drawLight(const widget::Widget::DrawArgs& args) override {
  137. nvgBeginPath(args.vg);
  138. nvgRect(args.vg, 0, 0, this->box.size.x, this->box.size.y);
  139. // Background
  140. if (this->bgColor.a > 0.0) {
  141. nvgFillColor(args.vg, this->bgColor);
  142. nvgFill(args.vg);
  143. }
  144. // Foreground
  145. if (this->color.a > 0.0) {
  146. nvgFillColor(args.vg, this->color);
  147. nvgFill(args.vg);
  148. }
  149. // Border
  150. if (this->borderColor.a > 0.0) {
  151. nvgStrokeWidth(args.vg, 0.5);
  152. nvgStrokeColor(args.vg, this->borderColor);
  153. nvgStroke(args.vg);
  154. }
  155. }
  156. };
  157. /** A light for displaying on top of PB61303. Must add a color by subclassing or templating. */
  158. template <typename TBase>
  159. struct LEDBezelLight : TBase {
  160. LEDBezelLight() {
  161. this->bgColor = color::BLACK_TRANSPARENT;
  162. this->box.size = app::mm2px(math::Vec(6.0, 6.0));
  163. }
  164. };
  165. /** A light to displayed over PB61303. Must add a color by subclassing or templating.
  166. Don't add this as a child of the PB61303 itself. Instead, just place it over it as a sibling in the scene graph, offset by app::mm2px(math::Vec(0.5, 0.5)).
  167. */
  168. template <typename TBase>
  169. struct PB61303Light : TBase {
  170. PB61303Light() {
  171. this->bgColor = color::BLACK_TRANSPARENT;
  172. this->box.size = app::mm2px(math::Vec(9.0, 9.0));
  173. }
  174. };
  175. ////////////////////
  176. // Knobs
  177. ////////////////////
  178. struct RoundKnob : app::SvgKnob {
  179. RoundKnob() {
  180. minAngle = -0.83 * M_PI;
  181. maxAngle = 0.83 * M_PI;
  182. }
  183. };
  184. struct RoundBlackKnob : RoundKnob {
  185. RoundBlackKnob() {
  186. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/RoundBlackKnob.svg")));
  187. }
  188. };
  189. struct RoundSmallBlackKnob : RoundKnob {
  190. RoundSmallBlackKnob() {
  191. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/RoundSmallBlackKnob.svg")));
  192. }
  193. };
  194. struct RoundLargeBlackKnob : RoundKnob {
  195. RoundLargeBlackKnob() {
  196. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/RoundLargeBlackKnob.svg")));
  197. }
  198. };
  199. struct RoundHugeBlackKnob : RoundKnob {
  200. RoundHugeBlackKnob() {
  201. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/RoundHugeBlackKnob.svg")));
  202. }
  203. };
  204. struct RoundBlackSnapKnob : RoundBlackKnob {
  205. RoundBlackSnapKnob() {
  206. snap = true;
  207. }
  208. };
  209. struct Davies1900hKnob : app::SvgKnob {
  210. Davies1900hKnob() {
  211. minAngle = -0.83 * M_PI;
  212. maxAngle = 0.83 * M_PI;
  213. }
  214. };
  215. struct Davies1900hWhiteKnob : Davies1900hKnob {
  216. Davies1900hWhiteKnob() {
  217. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Davies1900hWhite.svg")));
  218. }
  219. };
  220. struct Davies1900hBlackKnob : Davies1900hKnob {
  221. Davies1900hBlackKnob() {
  222. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Davies1900hBlack.svg")));
  223. }
  224. };
  225. struct Davies1900hRedKnob : Davies1900hKnob {
  226. Davies1900hRedKnob() {
  227. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Davies1900hRed.svg")));
  228. }
  229. };
  230. struct Davies1900hLargeWhiteKnob : Davies1900hKnob {
  231. Davies1900hLargeWhiteKnob() {
  232. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Davies1900hLargeWhite.svg")));
  233. }
  234. };
  235. struct Davies1900hLargeBlackKnob : Davies1900hKnob {
  236. Davies1900hLargeBlackKnob() {
  237. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Davies1900hLargeBlack.svg")));
  238. }
  239. };
  240. struct Davies1900hLargeRedKnob : Davies1900hKnob {
  241. Davies1900hLargeRedKnob() {
  242. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Davies1900hLargeRed.svg")));
  243. }
  244. };
  245. struct Rogan : app::SvgKnob {
  246. Rogan() {
  247. minAngle = -0.83 * M_PI;
  248. maxAngle = 0.83 * M_PI;
  249. }
  250. };
  251. struct Rogan6PSWhite : Rogan {
  252. Rogan6PSWhite() {
  253. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan6PSWhite.svg")));
  254. }
  255. };
  256. struct Rogan5PSGray : Rogan {
  257. Rogan5PSGray() {
  258. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan5PSGray.svg")));
  259. }
  260. };
  261. struct Rogan3PSBlue : Rogan {
  262. Rogan3PSBlue() {
  263. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan3PSBlue.svg")));
  264. }
  265. };
  266. struct Rogan3PSRed : Rogan {
  267. Rogan3PSRed() {
  268. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan3PSRed.svg")));
  269. }
  270. };
  271. struct Rogan3PSGreen : Rogan {
  272. Rogan3PSGreen() {
  273. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan3PSGreen.svg")));
  274. }
  275. };
  276. struct Rogan3PSWhite : Rogan {
  277. Rogan3PSWhite() {
  278. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan3PSWhite.svg")));
  279. }
  280. };
  281. struct Rogan3PBlue : Rogan {
  282. Rogan3PBlue() {
  283. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan3PBlue.svg")));
  284. }
  285. };
  286. struct Rogan3PRed : Rogan {
  287. Rogan3PRed() {
  288. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan3PRed.svg")));
  289. }
  290. };
  291. struct Rogan3PGreen : Rogan {
  292. Rogan3PGreen() {
  293. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan3PGreen.svg")));
  294. }
  295. };
  296. struct Rogan3PWhite : Rogan {
  297. Rogan3PWhite() {
  298. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan3PWhite.svg")));
  299. }
  300. };
  301. struct Rogan2SGray : Rogan {
  302. Rogan2SGray() {
  303. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan2SGray.svg")));
  304. }
  305. };
  306. struct Rogan2PSBlue : Rogan {
  307. Rogan2PSBlue() {
  308. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan2PSBlue.svg")));
  309. }
  310. };
  311. struct Rogan2PSRed : Rogan {
  312. Rogan2PSRed() {
  313. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan2PSRed.svg")));
  314. }
  315. };
  316. struct Rogan2PSGreen : Rogan {
  317. Rogan2PSGreen() {
  318. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan2PSGreen.svg")));
  319. }
  320. };
  321. struct Rogan2PSWhite : Rogan {
  322. Rogan2PSWhite() {
  323. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan2PSWhite.svg")));
  324. }
  325. };
  326. struct Rogan2PBlue : Rogan {
  327. Rogan2PBlue() {
  328. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan2PBlue.svg")));
  329. }
  330. };
  331. struct Rogan2PRed : Rogan {
  332. Rogan2PRed() {
  333. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan2PRed.svg")));
  334. }
  335. };
  336. struct Rogan2PGreen : Rogan {
  337. Rogan2PGreen() {
  338. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan2PGreen.svg")));
  339. }
  340. };
  341. struct Rogan2PWhite : Rogan {
  342. Rogan2PWhite() {
  343. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan2PWhite.svg")));
  344. }
  345. };
  346. struct Rogan1PSBlue : Rogan {
  347. Rogan1PSBlue() {
  348. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan1PSBlue.svg")));
  349. }
  350. };
  351. struct Rogan1PSRed : Rogan {
  352. Rogan1PSRed() {
  353. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan1PSRed.svg")));
  354. }
  355. };
  356. struct Rogan1PSGreen : Rogan {
  357. Rogan1PSGreen() {
  358. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan1PSGreen.svg")));
  359. }
  360. };
  361. struct Rogan1PSWhite : Rogan {
  362. Rogan1PSWhite() {
  363. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan1PSWhite.svg")));
  364. }
  365. };
  366. struct Rogan1PBlue : Rogan {
  367. Rogan1PBlue() {
  368. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan1PBlue.svg")));
  369. }
  370. };
  371. struct Rogan1PRed : Rogan {
  372. Rogan1PRed() {
  373. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan1PRed.svg")));
  374. }
  375. };
  376. struct Rogan1PGreen : Rogan {
  377. Rogan1PGreen() {
  378. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan1PGreen.svg")));
  379. }
  380. };
  381. struct Rogan1PWhite : Rogan {
  382. Rogan1PWhite() {
  383. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan1PWhite.svg")));
  384. }
  385. };
  386. struct SynthTechAlco : app::SvgKnob {
  387. SynthTechAlco() {
  388. minAngle = -0.82 * M_PI;
  389. maxAngle = 0.82 * M_PI;
  390. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/SynthTechAlco.svg")));
  391. // Add cap
  392. widget::FramebufferWidget* capFb = new widget::FramebufferWidget;
  393. widget::SvgWidget* cap = new widget::SvgWidget;
  394. cap->setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/SynthTechAlco_cap.svg")));
  395. capFb->addChild(cap);
  396. addChild(capFb);
  397. }
  398. };
  399. struct Trimpot : app::SvgKnob {
  400. Trimpot() {
  401. minAngle = -0.75 * M_PI;
  402. maxAngle = 0.75 * M_PI;
  403. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Trimpot.svg")));
  404. }
  405. };
  406. struct BefacoBigKnob : app::SvgKnob {
  407. BefacoBigKnob() {
  408. minAngle = -0.75 * M_PI;
  409. maxAngle = 0.75 * M_PI;
  410. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/BefacoBigKnob.svg")));
  411. }
  412. };
  413. struct BefacoBigSnapKnob : BefacoBigKnob {
  414. BefacoBigSnapKnob() {
  415. snap = true;
  416. }
  417. };
  418. struct BefacoTinyKnob : app::SvgKnob {
  419. BefacoTinyKnob() {
  420. minAngle = -0.75 * M_PI;
  421. maxAngle = 0.75 * M_PI;
  422. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/BefacoTinyKnob.svg")));
  423. }
  424. };
  425. struct BefacoSlidePot : app::SvgSlider {
  426. BefacoSlidePot() {
  427. math::Vec margin = math::Vec(3.5, 3.5);
  428. maxHandlePos = math::Vec(-1, -2).plus(margin);
  429. minHandlePos = math::Vec(-1, 87).plus(margin);
  430. setBackgroundSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/BefacoSlidePot.svg")));
  431. setHandleSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/BefacoSlidePotHandle.svg")));
  432. background->box.pos = margin;
  433. box.size = background->box.size.plus(margin.mult(2));
  434. }
  435. };
  436. struct LEDSlider : app::SvgSlider {
  437. LEDSlider() {
  438. maxHandlePos = app::mm2px(math::Vec(0.738, 0.738).plus(math::Vec(2, 0)));
  439. minHandlePos = app::mm2px(math::Vec(0.738, 22.078).plus(math::Vec(2, 0)));
  440. setBackgroundSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/LEDSlider.svg")));
  441. }
  442. };
  443. /** API is unstable for LEDSlider. Will add a LightWidget later. */
  444. struct LEDSliderGreen : LEDSlider {
  445. LEDSliderGreen() {
  446. setHandleSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/LEDSliderGreenHandle.svg")));
  447. }
  448. };
  449. struct LEDSliderRed : LEDSlider {
  450. LEDSliderRed() {
  451. setHandleSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/LEDSliderRedHandle.svg")));
  452. }
  453. };
  454. struct LEDSliderYellow : LEDSlider {
  455. LEDSliderYellow() {
  456. setHandleSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/LEDSliderYellowHandle.svg")));
  457. }
  458. };
  459. struct LEDSliderBlue : LEDSlider {
  460. LEDSliderBlue() {
  461. setHandleSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/LEDSliderBlueHandle.svg")));
  462. }
  463. };
  464. struct LEDSliderWhite : LEDSlider {
  465. LEDSliderWhite() {
  466. setHandleSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/LEDSliderWhiteHandle.svg")));
  467. }
  468. };
  469. struct LEDSliderHorizontal : app::SvgSlider {
  470. LEDSliderHorizontal() {
  471. horizontal = true;
  472. maxHandlePos = app::mm2px(math::Vec(22.078, 0.738).plus(math::Vec(0, 2)));
  473. minHandlePos = app::mm2px(math::Vec(0.738, 0.738).plus(math::Vec(0, 2)));
  474. setBackgroundSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/LEDSliderHorizontal.svg")));
  475. }
  476. };
  477. template <typename TBase, typename TLightBase = RedLight>
  478. struct LightSlider : TBase {
  479. app::ModuleLightWidget* light;
  480. LightSlider() {
  481. light = new RectangleLight<TLightBase>;
  482. this->addChild(light);
  483. }
  484. void setFirstLightId(int firstLightId) {
  485. light->module = this->module;
  486. light->firstLightId = firstLightId;
  487. }
  488. void step() override {
  489. TBase::step();
  490. // Move center of light to center of handle
  491. light->box.pos = this->handle->box.pos
  492. .plus(this->handle->box.size.div(2))
  493. .minus(light->box.size.div(2));
  494. }
  495. };
  496. template <typename TLightBase = RedLight>
  497. struct LEDLightSlider : LightSlider<LEDSlider, TLightBase> {
  498. LEDLightSlider() {
  499. this->setHandleSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/LEDSliderHandle.svg")));
  500. this->light->box.size = app::mm2px(math::Vec(1.524, 3.276));
  501. }
  502. };
  503. template <typename TLightBase = RedLight>
  504. struct LEDLightSliderHorizontal : LightSlider<LEDSliderHorizontal, TLightBase> {
  505. LEDLightSliderHorizontal() {
  506. this->setHandleSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/LEDSliderHorizontalHandle.svg")));
  507. this->light->box.size = app::mm2px(math::Vec(3.276, 1.524));
  508. }
  509. };
  510. ////////////////////
  511. // Ports
  512. ////////////////////
  513. struct PJ301MPort : app::SvgPort {
  514. PJ301MPort() {
  515. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/PJ301M.svg")));
  516. }
  517. };
  518. struct PJ3410Port : app::SvgPort {
  519. PJ3410Port() {
  520. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/PJ3410.svg")));
  521. }
  522. };
  523. struct CL1362Port : app::SvgPort {
  524. CL1362Port() {
  525. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/CL1362.svg")));
  526. }
  527. };
  528. ////////////////////
  529. // Switches
  530. ////////////////////
  531. template <typename TSwitch>
  532. struct LatchingSwitch : TSwitch {
  533. LatchingSwitch() {
  534. this->momentary = false;
  535. }
  536. };
  537. template <typename TSwitch>
  538. struct MomentarySwitch : TSwitch {
  539. MomentarySwitch() {
  540. this->momentary = true;
  541. }
  542. };
  543. struct NKK : app::SvgSwitch {
  544. NKK() {
  545. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/NKK_0.svg")));
  546. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/NKK_1.svg")));
  547. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/NKK_2.svg")));
  548. }
  549. };
  550. struct CKSS : app::SvgSwitch {
  551. CKSS() {
  552. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/CKSS_0.svg")));
  553. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/CKSS_1.svg")));
  554. }
  555. };
  556. struct CKSSThree : app::SvgSwitch {
  557. CKSSThree() {
  558. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/CKSSThree_0.svg")));
  559. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/CKSSThree_1.svg")));
  560. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/CKSSThree_2.svg")));
  561. }
  562. };
  563. struct CKD6 : app::SvgSwitch {
  564. CKD6() {
  565. momentary = true;
  566. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/CKD6_0.svg")));
  567. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/CKD6_1.svg")));
  568. }
  569. };
  570. struct TL1105 : app::SvgSwitch {
  571. TL1105() {
  572. momentary = true;
  573. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/TL1105_0.svg")));
  574. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/TL1105_1.svg")));
  575. }
  576. };
  577. struct LEDButton : app::SvgSwitch {
  578. LEDButton() {
  579. momentary = true;
  580. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/LEDButton.svg")));
  581. }
  582. };
  583. struct BefacoSwitch : app::SvgSwitch {
  584. BefacoSwitch() {
  585. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/BefacoSwitch_0.svg")));
  586. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/BefacoSwitch_1.svg")));
  587. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/BefacoSwitch_2.svg")));
  588. }
  589. };
  590. struct BefacoPush : app::SvgSwitch {
  591. BefacoPush() {
  592. momentary = true;
  593. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/BefacoPush_0.svg")));
  594. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/BefacoPush_1.svg")));
  595. }
  596. };
  597. struct LEDBezel : app::SvgSwitch {
  598. LEDBezel() {
  599. momentary = true;
  600. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/LEDBezel.svg")));
  601. }
  602. };
  603. template <typename TLightBase = WhiteLight>
  604. struct LEDLightBezel : LEDBezel {
  605. app::ModuleLightWidget* light;
  606. LEDLightBezel() {
  607. light = new LEDBezelLight<TLightBase>;
  608. // Move center of light to center of box
  609. light->box.pos = box.size.div(2).minus(light->box.size.div(2));
  610. addChild(light);
  611. }
  612. void setFirstLightId(int firstLightId) {
  613. light->module = this->module;
  614. light->firstLightId = firstLightId;
  615. }
  616. };
  617. struct PB61303 : app::SvgSwitch {
  618. PB61303() {
  619. momentary = true;
  620. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/PB61303.svg")));
  621. }
  622. };
  623. ////////////////////
  624. // Misc
  625. ////////////////////
  626. struct ScrewSilver : app::SvgScrew {
  627. ScrewSilver() {
  628. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/ScrewSilver.svg")));
  629. }
  630. };
  631. struct ScrewBlack : app::SvgScrew {
  632. ScrewBlack() {
  633. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/ScrewBlack.svg")));
  634. }
  635. };
  636. struct SegmentDisplay : widget::Widget {
  637. int lightsLen = 0;
  638. bool vertical = false;
  639. float margin = app::mm2px(0.5);
  640. void draw(const DrawArgs& args) override {
  641. // Background
  642. nvgBeginPath(args.vg);
  643. nvgRect(args.vg, 0, 0, box.size.x, box.size.y);
  644. nvgFillColor(args.vg, color::BLACK);
  645. nvgFill(args.vg);
  646. Widget::draw(args);
  647. }
  648. template <typename TLightBase = WhiteLight>
  649. void setLights(engine::Module* module, int firstLightId, int lightsLen) {
  650. clearChildren();
  651. this->lightsLen = lightsLen;
  652. float r = (vertical ? box.size.y : box.size.x) - margin;
  653. for (int i = 0; i < lightsLen; i++) {
  654. float p = float(i) / lightsLen;
  655. app::ModuleLightWidget* light = new RectangleLight<TLightBase>;
  656. if (vertical) {
  657. light->box.pos.y = p * r + margin;
  658. light->box.size.y = r / lightsLen - margin;
  659. light->box.size.x = box.size.x;
  660. }
  661. else {
  662. light->box.pos.x = p * r + margin;
  663. light->box.size.x = r / lightsLen - margin;
  664. light->box.size.y = box.size.y;
  665. }
  666. light->module = module;
  667. light->firstLightId = firstLightId;
  668. firstLightId += light->baseColors.size();
  669. addChild(light);
  670. }
  671. }
  672. };
  673. } // namespace componentlibrary
  674. } // namespace rack