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.

805 lines
21KB

  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. if (this->paramQuantity)
  486. light->module = this->paramQuantity->module;
  487. light->firstLightId = firstLightId;
  488. }
  489. void step() override {
  490. TBase::step();
  491. // Move center of light to center of handle
  492. light->box.pos = this->handle->box.pos
  493. .plus(this->handle->box.size.div(2))
  494. .minus(light->box.size.div(2));
  495. }
  496. };
  497. template <typename TLightBase = RedLight>
  498. struct LEDLightSlider : LightSlider<LEDSlider, TLightBase> {
  499. LEDLightSlider() {
  500. this->setHandleSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/LEDSliderHandle.svg")));
  501. this->light->box.size = app::mm2px(math::Vec(1.524, 3.276));
  502. }
  503. };
  504. template <typename TLightBase = RedLight>
  505. struct LEDLightSliderHorizontal : LightSlider<LEDSliderHorizontal, TLightBase> {
  506. LEDLightSliderHorizontal() {
  507. this->setHandleSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/LEDSliderHorizontalHandle.svg")));
  508. this->light->box.size = app::mm2px(math::Vec(3.276, 1.524));
  509. }
  510. };
  511. ////////////////////
  512. // Ports
  513. ////////////////////
  514. struct PJ301MPort : app::SvgPort {
  515. PJ301MPort() {
  516. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/PJ301M.svg")));
  517. }
  518. };
  519. struct PJ3410Port : app::SvgPort {
  520. PJ3410Port() {
  521. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/PJ3410.svg")));
  522. }
  523. };
  524. struct CL1362Port : app::SvgPort {
  525. CL1362Port() {
  526. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/CL1362.svg")));
  527. }
  528. };
  529. ////////////////////
  530. // Switches
  531. ////////////////////
  532. template <typename TSwitch>
  533. struct LatchingSwitch : TSwitch {
  534. LatchingSwitch() {
  535. this->momentary = false;
  536. }
  537. };
  538. template <typename TSwitch>
  539. struct MomentarySwitch : TSwitch {
  540. MomentarySwitch() {
  541. this->momentary = true;
  542. }
  543. };
  544. struct NKK : app::SvgSwitch {
  545. NKK() {
  546. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/NKK_0.svg")));
  547. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/NKK_1.svg")));
  548. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/NKK_2.svg")));
  549. }
  550. };
  551. struct CKSS : app::SvgSwitch {
  552. CKSS() {
  553. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/CKSS_0.svg")));
  554. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/CKSS_1.svg")));
  555. }
  556. };
  557. struct CKSSThree : app::SvgSwitch {
  558. CKSSThree() {
  559. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/CKSSThree_0.svg")));
  560. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/CKSSThree_1.svg")));
  561. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/CKSSThree_2.svg")));
  562. }
  563. };
  564. struct CKD6 : app::SvgSwitch {
  565. CKD6() {
  566. momentary = true;
  567. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/CKD6_0.svg")));
  568. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/CKD6_1.svg")));
  569. }
  570. };
  571. struct TL1105 : app::SvgSwitch {
  572. TL1105() {
  573. momentary = true;
  574. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/TL1105_0.svg")));
  575. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/TL1105_1.svg")));
  576. }
  577. };
  578. struct LEDButton : app::SvgSwitch {
  579. LEDButton() {
  580. momentary = true;
  581. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/LEDButton.svg")));
  582. }
  583. };
  584. struct BefacoSwitch : app::SvgSwitch {
  585. BefacoSwitch() {
  586. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/BefacoSwitch_0.svg")));
  587. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/BefacoSwitch_1.svg")));
  588. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/BefacoSwitch_2.svg")));
  589. }
  590. };
  591. struct BefacoPush : app::SvgSwitch {
  592. BefacoPush() {
  593. momentary = true;
  594. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/BefacoPush_0.svg")));
  595. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/BefacoPush_1.svg")));
  596. }
  597. };
  598. struct LEDBezel : app::SvgSwitch {
  599. LEDBezel() {
  600. momentary = true;
  601. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/LEDBezel.svg")));
  602. }
  603. };
  604. template <typename TLightBase = WhiteLight>
  605. struct LEDLightBezel : LEDBezel {
  606. app::ModuleLightWidget* light;
  607. LEDLightBezel() {
  608. light = new LEDBezelLight<TLightBase>;
  609. // Move center of light to center of box
  610. light->box.pos = box.size.div(2).minus(light->box.size.div(2));
  611. addChild(light);
  612. }
  613. void setFirstLightId(int firstLightId) {
  614. if (paramQuantity)
  615. light->module = paramQuantity->module;
  616. light->firstLightId = firstLightId;
  617. }
  618. };
  619. struct PB61303 : app::SvgSwitch {
  620. PB61303() {
  621. momentary = true;
  622. addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/PB61303.svg")));
  623. }
  624. };
  625. ////////////////////
  626. // Misc
  627. ////////////////////
  628. struct ScrewSilver : app::SvgScrew {
  629. ScrewSilver() {
  630. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/ScrewSilver.svg")));
  631. }
  632. };
  633. struct ScrewBlack : app::SvgScrew {
  634. ScrewBlack() {
  635. setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/ScrewBlack.svg")));
  636. }
  637. };
  638. struct SegmentDisplay : widget::Widget {
  639. int lightsLen = 0;
  640. bool vertical = false;
  641. float margin = app::mm2px(0.5);
  642. void draw(const DrawArgs& args) override {
  643. // Background
  644. nvgBeginPath(args.vg);
  645. nvgRect(args.vg, 0, 0, box.size.x, box.size.y);
  646. nvgFillColor(args.vg, color::BLACK);
  647. nvgFill(args.vg);
  648. Widget::draw(args);
  649. }
  650. template <typename TLightBase = WhiteLight>
  651. void setLights(engine::Module* module, int firstLightId, int lightsLen) {
  652. clearChildren();
  653. this->lightsLen = lightsLen;
  654. float r = (vertical ? box.size.y : box.size.x) - margin;
  655. for (int i = 0; i < lightsLen; i++) {
  656. float p = float(i) / lightsLen;
  657. app::ModuleLightWidget* light = new RectangleLight<TLightBase>;
  658. if (vertical) {
  659. light->box.pos.y = p * r + margin;
  660. light->box.size.y = r / lightsLen - margin;
  661. light->box.size.x = box.size.x;
  662. }
  663. else {
  664. light->box.pos.x = p * r + margin;
  665. light->box.size.x = r / lightsLen - margin;
  666. light->box.size.y = box.size.y;
  667. }
  668. light->module = module;
  669. light->firstLightId = firstLightId;
  670. firstLightId += light->baseColors.size();
  671. addChild(light);
  672. }
  673. }
  674. };
  675. } // namespace componentlibrary
  676. } // namespace rack