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.

components.hpp 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. #pragma once
  2. #include "app.hpp"
  3. #include "asset.hpp"
  4. namespace rack {
  5. ////////////////////
  6. // Colors
  7. ////////////////////
  8. #define COLOR_BLACK_TRANSPARENT nvgRGBA(0x00, 0x00, 0x00, 0x00)
  9. #define COLOR_BLACK nvgRGB(0x00, 0x00, 0x00)
  10. #define COLOR_WHITE nvgRGB(0xff, 0xff, 0xff)
  11. #define COLOR_RED nvgRGB(0xed, 0x2c, 0x24)
  12. #define COLOR_ORANGE nvgRGB(0xf2, 0xb1, 0x20)
  13. #define COLOR_YELLOW nvgRGB(0xf9, 0xdf, 0x1c)
  14. #define COLOR_GREEN nvgRGB(0x90, 0xc7, 0x3e)
  15. #define COLOR_CYAN nvgRGB(0x22, 0xe6, 0xef)
  16. #define COLOR_BLUE nvgRGB(0x29, 0xb2, 0xef)
  17. #define COLOR_PURPLE nvgRGB(0xd5, 0x2b, 0xed)
  18. ////////////////////
  19. // Knobs
  20. ////////////////////
  21. struct RoundKnob : SVGKnob {
  22. RoundKnob() {
  23. minAngle = -0.83*M_PI;
  24. maxAngle = 0.83*M_PI;
  25. }
  26. };
  27. struct RoundBlackKnob : RoundKnob {
  28. RoundBlackKnob() {
  29. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/RoundBlack.svg")));
  30. box.size = Vec(38, 38);
  31. }
  32. };
  33. struct RoundSmallBlackKnob : RoundBlackKnob {
  34. RoundSmallBlackKnob() {
  35. box.size = Vec(28, 28);
  36. }
  37. };
  38. struct RoundLargeBlackKnob : RoundBlackKnob {
  39. RoundLargeBlackKnob() {
  40. box.size = Vec(46, 46);
  41. }
  42. };
  43. struct RoundHugeBlackKnob : RoundBlackKnob {
  44. RoundHugeBlackKnob() {
  45. box.size = Vec(56, 56);
  46. }
  47. };
  48. struct RoundSmallBlackSnapKnob : RoundSmallBlackKnob {
  49. RoundSmallBlackSnapKnob() {
  50. snap = true;
  51. }
  52. };
  53. struct Davies1900hKnob : SVGKnob {
  54. Davies1900hKnob() {
  55. minAngle = -0.83*M_PI;
  56. maxAngle = 0.83*M_PI;
  57. }
  58. };
  59. struct Davies1900hWhiteKnob : Davies1900hKnob {
  60. Davies1900hWhiteKnob() {
  61. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hWhite.svg")));
  62. }
  63. };
  64. struct Davies1900hBlackKnob : Davies1900hKnob {
  65. Davies1900hBlackKnob() {
  66. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hBlack.svg")));
  67. }
  68. };
  69. struct Davies1900hRedKnob : Davies1900hKnob {
  70. Davies1900hRedKnob() {
  71. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hRed.svg")));
  72. }
  73. };
  74. struct Davies1900hLargeWhiteKnob : Davies1900hKnob {
  75. Davies1900hLargeWhiteKnob() {
  76. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hLargeWhite.svg")));
  77. }
  78. };
  79. struct Davies1900hLargeBlackKnob : Davies1900hKnob {
  80. Davies1900hLargeBlackKnob() {
  81. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hLargeBlack.svg")));
  82. }
  83. };
  84. struct Davies1900hLargeRedKnob : Davies1900hKnob {
  85. Davies1900hLargeRedKnob() {
  86. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hLargeRed.svg")));
  87. }
  88. };
  89. struct Davies1900hSmallBlackKnob : Davies1900hKnob {
  90. Davies1900hSmallBlackKnob() {
  91. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hSmallBlack.svg")));
  92. }
  93. };
  94. struct Davies1900hSmallBlackSnapKnob : Davies1900hSmallBlackKnob {
  95. Davies1900hSmallBlackSnapKnob() {
  96. snap = true;
  97. }
  98. };
  99. struct Rogan : SVGKnob {
  100. Rogan() {
  101. minAngle = -0.83*M_PI;
  102. maxAngle = 0.83*M_PI;
  103. }
  104. };
  105. struct Rogan6PS : Rogan {
  106. Rogan6PS() {
  107. box.size = Vec(89, 89);
  108. // minAngle = -0.83*M_PI;
  109. // maxAngle = 0.83*M_PI;
  110. }
  111. };
  112. struct Rogan5PS : Rogan {
  113. Rogan5PS() {
  114. box.size = Vec(60, 60);
  115. }
  116. };
  117. struct Rogan3PS : Rogan {
  118. Rogan3PS() {
  119. box.size = Vec(52, 52);
  120. }
  121. };
  122. struct Rogan3P : Rogan {
  123. Rogan3P() {
  124. box.size = Vec(42, 42);
  125. }
  126. };
  127. struct Rogan2S : Rogan {
  128. Rogan2S() {
  129. box.size = Vec(43, 43);
  130. }
  131. };
  132. struct Rogan2PS : Rogan {
  133. Rogan2PS() {
  134. box.size = Vec(43, 43);
  135. }
  136. };
  137. struct Rogan2P : Rogan {
  138. Rogan2P() {
  139. box.size = Vec(34, 34);
  140. }
  141. };
  142. struct Rogan1PS : Rogan {
  143. Rogan1PS() {
  144. box.size = Vec(40, 40);
  145. }
  146. };
  147. struct Rogan1P : Rogan {
  148. Rogan1P() {
  149. box.size = Vec(31, 31);
  150. }
  151. };
  152. struct Rogan6PSWhite : Rogan6PS {
  153. Rogan6PSWhite() {
  154. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Rogan6PSWhite.svg")));
  155. }
  156. };
  157. struct Rogan5PSGray : Rogan5PS {
  158. Rogan5PSGray() {
  159. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Rogan5PSGray.svg")));
  160. }
  161. };
  162. struct Rogan3PSBlue : Rogan3PS {
  163. Rogan3PSBlue() {
  164. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Rogan3PSBlue.svg")));
  165. }
  166. };
  167. struct Rogan3PSRed : Rogan3PS {
  168. Rogan3PSRed() {
  169. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Rogan3PSRed.svg")));
  170. }
  171. };
  172. struct Rogan3PSGreen : Rogan3PS {
  173. Rogan3PSGreen() {
  174. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Rogan3PSGreen.svg")));
  175. }
  176. };
  177. struct Rogan3PSWhite : Rogan3PS {
  178. Rogan3PSWhite() {
  179. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Rogan3PSWhite.svg")));
  180. }
  181. };
  182. struct Rogan3PBlue : Rogan3P {
  183. Rogan3PBlue() {
  184. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Rogan3PBlue.svg")));
  185. }
  186. };
  187. struct Rogan3PRed : Rogan3P {
  188. Rogan3PRed() {
  189. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Rogan3PRed.svg")));
  190. }
  191. };
  192. struct Rogan3PGreen : Rogan3P {
  193. Rogan3PGreen() {
  194. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Rogan3PGreen.svg")));
  195. }
  196. };
  197. struct Rogan3PWhite : Rogan3P {
  198. Rogan3PWhite() {
  199. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Rogan3PWhite.svg")));
  200. }
  201. };
  202. struct Rogan2SGray : Rogan2S {
  203. Rogan2SGray() {
  204. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Rogan2SGray.svg")));
  205. }
  206. };
  207. struct Rogan2PSBlue : Rogan2PS {
  208. Rogan2PSBlue() {
  209. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Rogan2PSBlue.svg")));
  210. }
  211. };
  212. struct Rogan2PSRed : Rogan2PS {
  213. Rogan2PSRed() {
  214. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Rogan2PSRed.svg")));
  215. }
  216. };
  217. struct Rogan2PSGreen : Rogan2PS {
  218. Rogan2PSGreen() {
  219. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Rogan2PSGreen.svg")));
  220. }
  221. };
  222. struct Rogan2PSWhite : Rogan2PS {
  223. Rogan2PSWhite() {
  224. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Rogan2PSWhite.svg")));
  225. }
  226. };
  227. struct Rogan2PBlue : Rogan2P {
  228. Rogan2PBlue() {
  229. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Rogan2PBlue.svg")));
  230. }
  231. };
  232. struct Rogan2PRed : Rogan2P {
  233. Rogan2PRed() {
  234. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Rogan2PRed.svg")));
  235. }
  236. };
  237. struct Rogan2PGreen : Rogan2P {
  238. Rogan2PGreen() {
  239. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Rogan2PGreen.svg")));
  240. }
  241. };
  242. struct Rogan2PWhite : Rogan2P {
  243. Rogan2PWhite() {
  244. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Rogan2PWhite.svg")));
  245. }
  246. };
  247. struct Rogan1PSBlue : Rogan1PS {
  248. Rogan1PSBlue() {
  249. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Rogan1PSBlue.svg")));
  250. }
  251. };
  252. struct Rogan1PSRed : Rogan1PS {
  253. Rogan1PSRed() {
  254. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Rogan1PSRed.svg")));
  255. }
  256. };
  257. struct Rogan1PSGreen : Rogan1PS {
  258. Rogan1PSGreen() {
  259. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Rogan1PSGreen.svg")));
  260. }
  261. };
  262. struct Rogan1PSWhite : Rogan1PS {
  263. Rogan1PSWhite() {
  264. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Rogan1PSWhite.svg")));
  265. }
  266. };
  267. struct Rogan1PBlue : Rogan1P {
  268. Rogan1PBlue() {
  269. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Rogan1PBlue.svg")));
  270. }
  271. };
  272. struct Rogan1PRed : Rogan1P {
  273. Rogan1PRed() {
  274. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Rogan1PRed.svg")));
  275. }
  276. };
  277. struct Rogan1PGreen : Rogan1P {
  278. Rogan1PGreen() {
  279. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Rogan1PGreen.svg")));
  280. }
  281. };
  282. struct Rogan1PWhite : Rogan1P {
  283. Rogan1PWhite() {
  284. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Rogan1PWhite.svg")));
  285. }
  286. };
  287. struct SynthTechAlco : SVGKnob {
  288. SynthTechAlco() {
  289. box.size = Vec(45, 45);
  290. minAngle = -0.82*M_PI;
  291. maxAngle = 0.82*M_PI;
  292. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/SynthTechAlco.svg")));
  293. }
  294. };
  295. struct Trimpot : SVGKnob {
  296. Trimpot() {
  297. box.size = Vec(17, 17);
  298. minAngle = -0.75*M_PI;
  299. maxAngle = 0.75*M_PI;
  300. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Trimpot.svg")));
  301. }
  302. };
  303. struct BefacoBigKnob : SVGKnob {
  304. BefacoBigKnob() {
  305. box.size = Vec(75, 75);
  306. minAngle = -0.75*M_PI;
  307. maxAngle = 0.75*M_PI;
  308. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/BefacoBigKnob.svg")));
  309. }
  310. };
  311. struct BefacoBigSnapKnob : BefacoBigKnob {
  312. BefacoBigSnapKnob() {
  313. snap = true;
  314. }
  315. };
  316. struct BefacoTinyKnob : SVGKnob {
  317. BefacoTinyKnob() {
  318. box.size = Vec(26, 26);
  319. minAngle = -0.75*M_PI;
  320. maxAngle = 0.75*M_PI;
  321. setSVG(SVG::load(assetGlobal("res/ComponentLibrary/BefacoTinyKnob.svg")));
  322. }
  323. };
  324. struct BefacoSlidePot : SVGSlider {
  325. BefacoSlidePot() {
  326. Vec margin = Vec(3.5, 3.5);
  327. maxHandlePos = Vec(-1, -2).plus(margin);
  328. minHandlePos = Vec(-1, 87).plus(margin);
  329. background->svg = SVG::load(assetGlobal("res/ComponentLibrary/BefacoSlidePot.svg"));
  330. background->wrap();
  331. background->box.pos = margin;
  332. box.size = background->box.size.plus(margin.mult(2));
  333. handle->svg = SVG::load(assetGlobal("res/ComponentLibrary/BefacoSlidePotHandle.svg"));
  334. handle->wrap();
  335. }
  336. };
  337. ////////////////////
  338. // Jacks
  339. ////////////////////
  340. struct PJ301MPort : SVGPort {
  341. PJ301MPort() {
  342. background->svg = SVG::load(assetGlobal("res/ComponentLibrary/PJ301M.svg"));
  343. background->wrap();
  344. box.size = background->box.size;
  345. }
  346. };
  347. struct PJ3410Port : SVGPort {
  348. PJ3410Port() {
  349. background->svg = SVG::load(assetGlobal("res/ComponentLibrary/PJ3410.svg"));
  350. background->wrap();
  351. box.size = background->box.size;
  352. }
  353. };
  354. struct CL1362Port : SVGPort {
  355. CL1362Port() {
  356. background->svg = SVG::load(assetGlobal("res/ComponentLibrary/CL1362.svg"));
  357. background->wrap();
  358. box.size = background->box.size;
  359. }
  360. };
  361. ////////////////////
  362. // LEDs
  363. ////////////////////
  364. struct ValueLight : Light {
  365. float *value = NULL;
  366. virtual void setValue(float v) {}
  367. void step() override {
  368. if (value)
  369. setValue(*value);
  370. }
  371. };
  372. struct ColorValueLight : ValueLight {
  373. NVGcolor baseColor;
  374. void setValue(float v) override {
  375. v = sqrtBipolar(v);
  376. color = baseColor;
  377. color.a *= clampf(v, 0.0, 1.0);
  378. }
  379. };
  380. struct RedValueLight : ColorValueLight {
  381. RedValueLight() {
  382. baseColor = COLOR_RED;
  383. }
  384. };
  385. struct YellowValueLight : ColorValueLight {
  386. YellowValueLight() {
  387. baseColor = COLOR_YELLOW;
  388. }
  389. };
  390. struct GreenValueLight : ColorValueLight {
  391. GreenValueLight() {
  392. baseColor = COLOR_GREEN;
  393. }
  394. };
  395. struct PolarityLight : ValueLight {
  396. NVGcolor posColor;
  397. NVGcolor negColor;
  398. void setValue(float v) override {
  399. v = sqrtBipolar(v);
  400. color = (v >= 0.0) ? posColor : negColor;
  401. color.a *= clampf(fabsf(v), 0.0, 1.0);
  402. }
  403. };
  404. struct GreenRedPolarityLight : PolarityLight {
  405. GreenRedPolarityLight() {
  406. posColor = COLOR_GREEN;
  407. negColor = COLOR_RED;
  408. }
  409. };
  410. struct ModeValueLight : ValueLight {
  411. std::vector<NVGcolor> colors;
  412. void setValue(float v) override {
  413. int mode = clampi((int)roundf(v), 0, colors.size());
  414. color = colors[mode];
  415. }
  416. void addColor(NVGcolor color) {
  417. colors.push_back(color);
  418. }
  419. };
  420. template <typename BASE>
  421. struct LargeLight : BASE {
  422. LargeLight() {
  423. this->box.size = Vec(20, 20);
  424. }
  425. };
  426. template <typename BASE>
  427. struct MediumLight : BASE {
  428. MediumLight() {
  429. this->box.size = Vec(12, 12);
  430. }
  431. };
  432. template <typename BASE>
  433. struct SmallLight : BASE {
  434. SmallLight() {
  435. this->box.size = Vec(8, 8);
  436. }
  437. };
  438. template <typename BASE>
  439. struct TinyLight : BASE {
  440. TinyLight() {
  441. this->box.size = Vec(5, 5);
  442. }
  443. };
  444. ////////////////////
  445. // Switches and Buttons
  446. ////////////////////
  447. struct NKK : SVGSwitch, ToggleSwitch {
  448. NKK() {
  449. addFrame(SVG::load(assetGlobal("res/ComponentLibrary/NKK_0.svg")));
  450. addFrame(SVG::load(assetGlobal("res/ComponentLibrary/NKK_1.svg")));
  451. addFrame(SVG::load(assetGlobal("res/ComponentLibrary/NKK_2.svg")));
  452. sw->wrap();
  453. box.size = sw->box.size;
  454. }
  455. };
  456. struct CKSS : SVGSwitch, ToggleSwitch {
  457. CKSS() {
  458. addFrame(SVG::load(assetGlobal("res/ComponentLibrary/CKSS_0.svg")));
  459. addFrame(SVG::load(assetGlobal("res/ComponentLibrary/CKSS_1.svg")));
  460. sw->wrap();
  461. box.size = sw->box.size;
  462. }
  463. };
  464. struct CKD6 : SVGSwitch, MomentarySwitch {
  465. CKD6() {
  466. addFrame(SVG::load(assetGlobal("res/ComponentLibrary/CKD6_0.svg")));
  467. addFrame(SVG::load(assetGlobal("res/ComponentLibrary/CKD6_1.svg")));
  468. sw->wrap();
  469. box.size = sw->box.size;
  470. }
  471. };
  472. struct TL1105 : SVGSwitch, MomentarySwitch {
  473. TL1105() {
  474. addFrame(SVG::load(assetGlobal("res/ComponentLibrary/TL1105_0.svg")));
  475. addFrame(SVG::load(assetGlobal("res/ComponentLibrary/TL1105_1.svg")));
  476. sw->wrap();
  477. box.size = sw->box.size;
  478. }
  479. };
  480. struct LEDButton : SVGSwitch, MomentarySwitch {
  481. LEDButton() {
  482. addFrame(SVG::load(assetGlobal("res/ComponentLibrary/LEDButton.svg")));
  483. sw->wrap();
  484. box.size = sw->box.size;
  485. }
  486. };
  487. struct BefacoSwitch : SVGSwitch, ToggleSwitch {
  488. BefacoSwitch() {
  489. addFrame(SVG::load(assetGlobal("res/ComponentLibrary/BefacoSwitch_0.svg")));
  490. addFrame(SVG::load(assetGlobal("res/ComponentLibrary/BefacoSwitch_1.svg")));
  491. addFrame(SVG::load(assetGlobal("res/ComponentLibrary/BefacoSwitch_2.svg")));
  492. sw->wrap();
  493. box.size = sw->box.size;
  494. }
  495. };
  496. struct BefacoPush : SVGSwitch, MomentarySwitch {
  497. BefacoPush() {
  498. addFrame(SVG::load(assetGlobal("res/ComponentLibrary/BefacoPush_0.svg")));
  499. addFrame(SVG::load(assetGlobal("res/ComponentLibrary/BefacoPush_1.svg")));
  500. sw->wrap();
  501. box.size = sw->box.size;
  502. }
  503. };
  504. struct PB61303 : SVGSwitch, MomentarySwitch {
  505. PB61303() {
  506. addFrame(SVG::load(assetGlobal("res/ComponentLibrary/PB61303_0.svg")));
  507. addFrame(SVG::load(assetGlobal("res/ComponentLibrary/PB61303_1.svg")));
  508. sw->wrap();
  509. box.size = sw->box.size;
  510. }
  511. };
  512. ////////////////////
  513. // Misc
  514. ////////////////////
  515. struct ScrewSilver : SVGScrew {
  516. ScrewSilver() {
  517. sw->svg = SVG::load(assetGlobal("res/ComponentLibrary/ScrewSilver.svg"));
  518. sw->wrap();
  519. box.size = sw->box.size;
  520. }
  521. };
  522. struct ScrewBlack : SVGScrew {
  523. ScrewBlack() {
  524. sw->svg = SVG::load(assetGlobal("res/ComponentLibrary/ScrewBlack.svg"));
  525. sw->wrap();
  526. box.size = sw->box.size;
  527. }
  528. };
  529. struct LightPanel : Panel {
  530. LightPanel() {
  531. backgroundColor = nvgRGB(0xe6, 0xe6, 0xe6);
  532. }
  533. };
  534. struct DarkPanel : Panel {
  535. DarkPanel() {
  536. backgroundColor = nvgRGB(0x17, 0x17, 0x17);
  537. }
  538. };
  539. } // namespace rack