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 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984
  1. #pragma once
  2. #include <widget/FramebufferWidget.hpp>
  3. #include <widget/SvgWidget.hpp>
  4. #include <app/SvgKnob.hpp>
  5. #include <app/SvgSlider.hpp>
  6. #include <app/SvgPort.hpp>
  7. #include <app/ModuleLightWidget.hpp>
  8. #include <app/SvgSwitch.hpp>
  9. #include <app/SvgScrew.hpp>
  10. #include <app/AudioWidget.hpp>
  11. #include <app/MidiWidget.hpp>
  12. #include <asset.hpp>
  13. namespace rack {
  14. /** Library of Rack components: knobs, ports, lights, switches, buttons, etc.
  15. See LICENSE.md for legal details about using Rack component graphics in your Rack plugin.
  16. */
  17. namespace componentlibrary {
  18. using namespace window;
  19. ////////////////////
  20. // Color scheme
  21. ////////////////////
  22. static const NVGcolor SCHEME_BLACK_TRANSPARENT = nvgRGBA(0x00, 0x00, 0x00, 0x00);
  23. static const NVGcolor SCHEME_BLACK = nvgRGB(0x00, 0x00, 0x00);
  24. static const NVGcolor SCHEME_WHITE = nvgRGB(0xff, 0xff, 0xff);
  25. static const NVGcolor SCHEME_RED = nvgRGB(0xed, 0x2c, 0x24);
  26. static const NVGcolor SCHEME_ORANGE = nvgRGB(0xf2, 0xb1, 0x20);
  27. static const NVGcolor SCHEME_YELLOW = nvgRGB(0xf9, 0xdf, 0x1c);
  28. static const NVGcolor SCHEME_GREEN = nvgRGB(0x90, 0xc7, 0x3e);
  29. static const NVGcolor SCHEME_CYAN = nvgRGB(0x22, 0xe6, 0xef);
  30. static const NVGcolor SCHEME_BLUE = nvgRGB(0x29, 0xb2, 0xef);
  31. static const NVGcolor SCHEME_PURPLE = nvgRGB(0xd5, 0x2b, 0xed);
  32. static const NVGcolor SCHEME_LIGHT_GRAY = nvgRGB(0xe6, 0xe6, 0xe6);
  33. static const NVGcolor SCHEME_DARK_GRAY = nvgRGB(0x17, 0x17, 0x17);
  34. ////////////////////
  35. // Lights
  36. ////////////////////
  37. /*
  38. Many of these classes use CRTP (https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern).
  39. To use a red light with its default base class for example, use `RedLight` or `TRedLight<>`. (They are synonymous.)
  40. Use the `TBase` template argument if you want a different base class.
  41. E.g. `RectangleLight<RedLight>`
  42. 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.
  43. For example, need a slider with a green LED? Just use
  44. createLightParamCentered<LEDLightSlider<GreenLight>>(...)
  45. */
  46. template <typename TBase = app::ModuleLightWidget>
  47. struct TSvgLight : TBase {
  48. widget::FramebufferWidget* fb;
  49. widget::SvgWidget* sw;
  50. TSvgLight() {
  51. fb = new widget::FramebufferWidget;
  52. this->addChild(fb);
  53. sw = new widget::SvgWidget;
  54. fb->addChild(sw);
  55. }
  56. void setSvg(std::shared_ptr<Svg> svg) {
  57. sw->setSvg(svg);
  58. fb->box.size = sw->box.size;
  59. this->box.size = sw->box.size;
  60. }
  61. };
  62. typedef TSvgLight<> SvgLight;
  63. template <typename TBase = app::ModuleLightWidget>
  64. struct TGrayModuleLightWidget : TBase {
  65. TGrayModuleLightWidget() {
  66. this->bgColor = nvgRGBA(0x33, 0x33, 0x33, 0xff);
  67. this->borderColor = nvgRGBA(0, 0, 0, 53);
  68. }
  69. };
  70. typedef TGrayModuleLightWidget<> GrayModuleLightWidget;
  71. template <typename TBase = GrayModuleLightWidget>
  72. struct TWhiteLight : TBase {
  73. TWhiteLight() {
  74. this->addBaseColor(SCHEME_WHITE);
  75. }
  76. };
  77. typedef TWhiteLight<> WhiteLight;
  78. template <typename TBase = GrayModuleLightWidget>
  79. struct TRedLight : TBase {
  80. TRedLight() {
  81. this->addBaseColor(SCHEME_RED);
  82. }
  83. };
  84. typedef TRedLight<> RedLight;
  85. template <typename TBase = GrayModuleLightWidget>
  86. struct TGreenLight : TBase {
  87. TGreenLight() {
  88. this->addBaseColor(SCHEME_GREEN);
  89. }
  90. };
  91. typedef TGreenLight<> GreenLight;
  92. template <typename TBase = GrayModuleLightWidget>
  93. struct TBlueLight : TBase {
  94. TBlueLight() {
  95. this->addBaseColor(SCHEME_BLUE);
  96. }
  97. };
  98. typedef TBlueLight<> BlueLight;
  99. template <typename TBase = GrayModuleLightWidget>
  100. struct TYellowLight : TBase {
  101. TYellowLight() {
  102. this->addBaseColor(SCHEME_YELLOW);
  103. }
  104. };
  105. typedef TYellowLight<> YellowLight;
  106. /** Reads two adjacent lightIds, so `lightId` and `lightId + 1` must be defined */
  107. template <typename TBase = GrayModuleLightWidget>
  108. struct TGreenRedLight : TBase {
  109. TGreenRedLight() {
  110. this->addBaseColor(SCHEME_GREEN);
  111. this->addBaseColor(SCHEME_RED);
  112. }
  113. };
  114. typedef TGreenRedLight<> GreenRedLight;
  115. template <typename TBase = GrayModuleLightWidget>
  116. struct TRedGreenBlueLight : TBase {
  117. TRedGreenBlueLight() {
  118. this->addBaseColor(SCHEME_RED);
  119. this->addBaseColor(SCHEME_GREEN);
  120. this->addBaseColor(SCHEME_BLUE);
  121. }
  122. };
  123. typedef TRedGreenBlueLight<> RedGreenBlueLight;
  124. /** Based on the size of 5mm LEDs */
  125. template <typename TBase>
  126. struct LargeLight : TSvgLight<TBase> {
  127. LargeLight() {
  128. this->setSvg(Svg::load(asset::system("res/ComponentLibrary/LargeLight.svg")));
  129. }
  130. };
  131. /** Based on the size of 3mm LEDs */
  132. template <typename TBase>
  133. struct MediumLight : TSvgLight<TBase> {
  134. MediumLight() {
  135. this->setSvg(Svg::load(asset::system("res/ComponentLibrary/MediumLight.svg")));
  136. }
  137. };
  138. /** Based on the size of 2mm LEDs */
  139. template <typename TBase>
  140. struct SmallLight : TSvgLight<TBase> {
  141. SmallLight() {
  142. this->setSvg(Svg::load(asset::system("res/ComponentLibrary/SmallLight.svg")));
  143. }
  144. };
  145. /** Based on the size of 1mm LEDs */
  146. template <typename TBase>
  147. struct TinyLight : TSvgLight<TBase> {
  148. TinyLight() {
  149. this->setSvg(Svg::load(asset::system("res/ComponentLibrary/TinyLight.svg")));
  150. }
  151. };
  152. /** Based on the size of 5mm LEDs */
  153. template <typename TBase = GrayModuleLightWidget>
  154. struct LargeSimpleLight : TBase {
  155. LargeSimpleLight() {
  156. this->box.size = mm2px(math::Vec(5, 5));
  157. }
  158. };
  159. /** Based on the size of 3mm LEDs */
  160. template <typename TBase = GrayModuleLightWidget>
  161. struct MediumSimpleLight : TBase {
  162. MediumSimpleLight() {
  163. this->box.size = mm2px(math::Vec(3, 3));
  164. }
  165. };
  166. /** Based on the size of 2mm LEDs */
  167. template <typename TBase = GrayModuleLightWidget>
  168. struct SmallSimpleLight : TBase {
  169. SmallSimpleLight() {
  170. this->box.size = mm2px(math::Vec(2, 2));
  171. }
  172. };
  173. /** Based on the size of 1mm LEDs */
  174. template <typename TBase = GrayModuleLightWidget>
  175. struct TinySimpleLight : TBase {
  176. TinySimpleLight() {
  177. this->box.size = mm2px(math::Vec(1, 1));
  178. }
  179. };
  180. template <typename TBase>
  181. struct RectangleLight : TBase {
  182. void drawBackground(const widget::Widget::DrawArgs& args) override {
  183. // Derived from LightWidget::drawBackground()
  184. nvgBeginPath(args.vg);
  185. nvgRect(args.vg, 0, 0, this->box.size.x, this->box.size.y);
  186. // Background
  187. if (this->bgColor.a > 0.0) {
  188. nvgFillColor(args.vg, this->bgColor);
  189. nvgFill(args.vg);
  190. }
  191. // Border
  192. if (this->borderColor.a > 0.0) {
  193. nvgStrokeWidth(args.vg, 0.5);
  194. nvgStrokeColor(args.vg, this->borderColor);
  195. nvgStroke(args.vg);
  196. }
  197. }
  198. void drawLight(const widget::Widget::DrawArgs& args) override {
  199. // Derived from LightWidget::drawLight()
  200. // Foreground
  201. if (this->color.a > 0.0) {
  202. nvgBeginPath(args.vg);
  203. nvgRect(args.vg, 0, 0, this->box.size.x, this->box.size.y);
  204. nvgFillColor(args.vg, this->color);
  205. nvgFill(args.vg);
  206. }
  207. }
  208. };
  209. /** A light for displaying on top of PB61303. Must add a color by subclassing or templating. */
  210. template <typename TBase>
  211. struct LEDBezelLight : TBase {
  212. LEDBezelLight() {
  213. this->borderColor = color::BLACK_TRANSPARENT;
  214. this->bgColor = color::BLACK_TRANSPARENT;
  215. this->box.size = math::Vec(17.545, 17.545);
  216. }
  217. };
  218. /** A light to displayed over PB61303. Must add a color by subclassing or templating.
  219. */
  220. template <typename TBase>
  221. struct PB61303Light : TBase {
  222. PB61303Light() {
  223. this->bgColor = color::BLACK_TRANSPARENT;
  224. this->box.size = mm2px(math::Vec(9.0, 9.0));
  225. }
  226. };
  227. ////////////////////
  228. // Knobs
  229. ////////////////////
  230. struct RoundKnob : app::SvgKnob {
  231. widget::SvgWidget* bg;
  232. RoundKnob() {
  233. minAngle = -0.83 * M_PI;
  234. maxAngle = 0.83 * M_PI;
  235. bg = new widget::SvgWidget;
  236. fb->addChildBelow(bg, tw);
  237. }
  238. };
  239. struct RoundBlackKnob : RoundKnob {
  240. RoundBlackKnob() {
  241. setSvg(Svg::load(asset::system("res/ComponentLibrary/RoundBlackKnob.svg")));
  242. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/RoundBlackKnob-bg.svg")));
  243. }
  244. };
  245. struct RoundSmallBlackKnob : RoundKnob {
  246. RoundSmallBlackKnob() {
  247. setSvg(Svg::load(asset::system("res/ComponentLibrary/RoundSmallBlackKnob.svg")));
  248. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/RoundSmallBlackKnob-bg.svg")));
  249. }
  250. };
  251. struct RoundLargeBlackKnob : RoundKnob {
  252. RoundLargeBlackKnob() {
  253. setSvg(Svg::load(asset::system("res/ComponentLibrary/RoundLargeBlackKnob.svg")));
  254. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/RoundLargeBlackKnob-bg.svg")));
  255. }
  256. };
  257. struct RoundBigBlackKnob : RoundKnob {
  258. RoundBigBlackKnob() {
  259. setSvg(Svg::load(asset::system("res/ComponentLibrary/RoundBigBlackKnob.svg")));
  260. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/RoundBigBlackKnob-bg.svg")));
  261. }
  262. };
  263. struct RoundHugeBlackKnob : RoundKnob {
  264. RoundHugeBlackKnob() {
  265. setSvg(Svg::load(asset::system("res/ComponentLibrary/RoundHugeBlackKnob.svg")));
  266. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/RoundHugeBlackKnob-bg.svg")));
  267. }
  268. };
  269. struct RoundBlackSnapKnob : RoundBlackKnob {
  270. RoundBlackSnapKnob() {
  271. snap = true;
  272. }
  273. };
  274. struct Davies1900hKnob : app::SvgKnob {
  275. Davies1900hKnob() {
  276. minAngle = -0.83 * M_PI;
  277. maxAngle = 0.83 * M_PI;
  278. }
  279. };
  280. struct Davies1900hWhiteKnob : Davies1900hKnob {
  281. Davies1900hWhiteKnob() {
  282. setSvg(Svg::load(asset::system("res/ComponentLibrary/Davies1900hWhite.svg")));
  283. }
  284. };
  285. struct Davies1900hBlackKnob : Davies1900hKnob {
  286. Davies1900hBlackKnob() {
  287. setSvg(Svg::load(asset::system("res/ComponentLibrary/Davies1900hBlack.svg")));
  288. }
  289. };
  290. struct Davies1900hRedKnob : Davies1900hKnob {
  291. Davies1900hRedKnob() {
  292. setSvg(Svg::load(asset::system("res/ComponentLibrary/Davies1900hRed.svg")));
  293. }
  294. };
  295. struct Davies1900hLargeWhiteKnob : Davies1900hKnob {
  296. Davies1900hLargeWhiteKnob() {
  297. setSvg(Svg::load(asset::system("res/ComponentLibrary/Davies1900hLargeWhite.svg")));
  298. }
  299. };
  300. struct Davies1900hLargeBlackKnob : Davies1900hKnob {
  301. Davies1900hLargeBlackKnob() {
  302. setSvg(Svg::load(asset::system("res/ComponentLibrary/Davies1900hLargeBlack.svg")));
  303. }
  304. };
  305. struct Davies1900hLargeRedKnob : Davies1900hKnob {
  306. Davies1900hLargeRedKnob() {
  307. setSvg(Svg::load(asset::system("res/ComponentLibrary/Davies1900hLargeRed.svg")));
  308. }
  309. };
  310. struct Rogan : app::SvgKnob {
  311. widget::SvgWidget* bg;
  312. widget::SvgWidget* fg;
  313. Rogan() {
  314. minAngle = -0.83 * M_PI;
  315. maxAngle = 0.83 * M_PI;
  316. bg = new widget::SvgWidget;
  317. fb->addChildBelow(bg, tw);
  318. fg = new widget::SvgWidget;
  319. fb->addChildAbove(fg, tw);
  320. }
  321. };
  322. struct Rogan6PSWhite : Rogan {
  323. Rogan6PSWhite() {
  324. setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan6PSWhite.svg")));
  325. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan6PS-bg.svg")));
  326. fg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan6PSWhite-fg.svg")));
  327. }
  328. };
  329. struct Rogan5PSGray : Rogan {
  330. Rogan5PSGray() {
  331. setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan5PSGray.svg")));
  332. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan5PS-bg.svg")));
  333. fg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan5PSGray-fg.svg")));
  334. }
  335. };
  336. struct Rogan3PSBlue : Rogan {
  337. Rogan3PSBlue() {
  338. setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan3PSBlue.svg")));
  339. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan3PS-bg.svg")));
  340. fg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan3PSBlue-fg.svg")));
  341. }
  342. };
  343. struct Rogan3PSRed : Rogan {
  344. Rogan3PSRed() {
  345. setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan3PSRed.svg")));
  346. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan3PS-bg.svg")));
  347. fg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan3PSRed-fg.svg")));
  348. }
  349. };
  350. struct Rogan3PSGreen : Rogan {
  351. Rogan3PSGreen() {
  352. setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan3PSGreen.svg")));
  353. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan3PS-bg.svg")));
  354. fg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan3PSGreen-fg.svg")));
  355. }
  356. };
  357. struct Rogan3PSWhite : Rogan {
  358. Rogan3PSWhite() {
  359. setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan3PSWhite.svg")));
  360. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan3PS-bg.svg")));
  361. fg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan3PSWhite-fg.svg")));
  362. }
  363. };
  364. struct Rogan3PBlue : Rogan {
  365. Rogan3PBlue() {
  366. setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan3PBlue.svg")));
  367. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan3P-bg.svg")));
  368. fg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan3PBlue-fg.svg")));
  369. }
  370. };
  371. struct Rogan3PRed : Rogan {
  372. Rogan3PRed() {
  373. setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan3PRed.svg")));
  374. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan3P-bg.svg")));
  375. fg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan3PRed-fg.svg")));
  376. }
  377. };
  378. struct Rogan3PGreen : Rogan {
  379. Rogan3PGreen() {
  380. setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan3PGreen.svg")));
  381. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan3P-bg.svg")));
  382. fg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan3PGreen-fg.svg")));
  383. }
  384. };
  385. struct Rogan3PWhite : Rogan {
  386. Rogan3PWhite() {
  387. setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan3PWhite.svg")));
  388. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan3P-bg.svg")));
  389. fg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan3PWhite-fg.svg")));
  390. }
  391. };
  392. struct Rogan2SGray : Rogan {
  393. Rogan2SGray() {
  394. setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan2SGray.svg")));
  395. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan2S-bg.svg")));
  396. fg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan2SGray-fg.svg")));
  397. }
  398. };
  399. struct Rogan2PSBlue : Rogan {
  400. Rogan2PSBlue() {
  401. setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan2PSBlue.svg")));
  402. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan2PS-bg.svg")));
  403. fg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan2PSBlue-fg.svg")));
  404. }
  405. };
  406. struct Rogan2PSRed : Rogan {
  407. Rogan2PSRed() {
  408. setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan2PSRed.svg")));
  409. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan2PS-bg.svg")));
  410. fg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan2PSRed-fg.svg")));
  411. }
  412. };
  413. struct Rogan2PSGreen : Rogan {
  414. Rogan2PSGreen() {
  415. setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan2PSGreen.svg")));
  416. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan2PS-bg.svg")));
  417. fg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan2PSGreen-fg.svg")));
  418. }
  419. };
  420. struct Rogan2PSWhite : Rogan {
  421. Rogan2PSWhite() {
  422. setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan2PSWhite.svg")));
  423. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan2PS-bg.svg")));
  424. fg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan2PSWhite-fg.svg")));
  425. }
  426. };
  427. struct Rogan2PBlue : Rogan {
  428. Rogan2PBlue() {
  429. setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan2PBlue.svg")));
  430. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan2P-bg.svg")));
  431. fg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan2PBlue-fg.svg")));
  432. }
  433. };
  434. struct Rogan2PRed : Rogan {
  435. Rogan2PRed() {
  436. setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan2PRed.svg")));
  437. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan2P-bg.svg")));
  438. fg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan2PRed-fg.svg")));
  439. }
  440. };
  441. struct Rogan2PGreen : Rogan {
  442. Rogan2PGreen() {
  443. setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan2PGreen.svg")));
  444. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan2P-bg.svg")));
  445. fg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan2PGreen-fg.svg")));
  446. }
  447. };
  448. struct Rogan2PWhite : Rogan {
  449. Rogan2PWhite() {
  450. setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan2PWhite.svg")));
  451. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan2P-bg.svg")));
  452. fg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan2PWhite-fg.svg")));
  453. }
  454. };
  455. struct Rogan1PSBlue : Rogan {
  456. Rogan1PSBlue() {
  457. setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan1PSBlue.svg")));
  458. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan1PS-bg.svg")));
  459. fg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan1PSBlue-fg.svg")));
  460. }
  461. };
  462. struct Rogan1PSRed : Rogan {
  463. Rogan1PSRed() {
  464. setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan1PSRed.svg")));
  465. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan1PS-bg.svg")));
  466. fg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan1PSRed-fg.svg")));
  467. }
  468. };
  469. struct Rogan1PSGreen : Rogan {
  470. Rogan1PSGreen() {
  471. setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan1PSGreen.svg")));
  472. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan1PS-bg.svg")));
  473. fg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan1PSGreen-fg.svg")));
  474. }
  475. };
  476. struct Rogan1PSWhite : Rogan {
  477. Rogan1PSWhite() {
  478. setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan1PSWhite.svg")));
  479. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan1PS-bg.svg")));
  480. fg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan1PSWhite-fg.svg")));
  481. }
  482. };
  483. struct Rogan1PBlue : Rogan {
  484. Rogan1PBlue() {
  485. setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan1PBlue.svg")));
  486. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan1P-bg.svg")));
  487. fg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan1PBlue-fg.svg")));
  488. }
  489. };
  490. struct Rogan1PRed : Rogan {
  491. Rogan1PRed() {
  492. setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan1PRed.svg")));
  493. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan1P-bg.svg")));
  494. fg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan1PRed-fg.svg")));
  495. }
  496. };
  497. struct Rogan1PGreen : Rogan {
  498. Rogan1PGreen() {
  499. setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan1PGreen.svg")));
  500. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan1P-bg.svg")));
  501. fg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan1PGreen-fg.svg")));
  502. }
  503. };
  504. struct Rogan1PWhite : Rogan {
  505. Rogan1PWhite() {
  506. setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan1PWhite.svg")));
  507. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan1P-bg.svg")));
  508. fg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan1PWhite-fg.svg")));
  509. }
  510. };
  511. struct SynthTechAlco : app::SvgKnob {
  512. SynthTechAlco() {
  513. minAngle = -0.82 * M_PI;
  514. maxAngle = 0.82 * M_PI;
  515. setSvg(Svg::load(asset::system("res/ComponentLibrary/SynthTechAlco.svg")));
  516. // Add cap
  517. widget::FramebufferWidget* capFb = new widget::FramebufferWidget;
  518. widget::SvgWidget* cap = new widget::SvgWidget;
  519. cap->setSvg(Svg::load(asset::system("res/ComponentLibrary/SynthTechAlco_cap.svg")));
  520. capFb->addChild(cap);
  521. addChild(capFb);
  522. }
  523. };
  524. struct Trimpot : app::SvgKnob {
  525. widget::SvgWidget* bg;
  526. Trimpot() {
  527. minAngle = -0.75 * M_PI;
  528. maxAngle = 0.75 * M_PI;
  529. bg = new widget::SvgWidget;
  530. fb->addChildBelow(bg, tw);
  531. setSvg(Svg::load(asset::system("res/ComponentLibrary/Trimpot.svg")));
  532. bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Trimpot-bg.svg")));
  533. }
  534. };
  535. struct BefacoBigKnob : app::SvgKnob {
  536. BefacoBigKnob() {
  537. minAngle = -0.75 * M_PI;
  538. maxAngle = 0.75 * M_PI;
  539. setSvg(Svg::load(asset::system("res/ComponentLibrary/BefacoBigKnob.svg")));
  540. }
  541. };
  542. struct BefacoBigSnapKnob : BefacoBigKnob {
  543. BefacoBigSnapKnob() {
  544. snap = true;
  545. }
  546. };
  547. struct BefacoTinyKnob : app::SvgKnob {
  548. BefacoTinyKnob() {
  549. minAngle = -0.75 * M_PI;
  550. maxAngle = 0.75 * M_PI;
  551. setSvg(Svg::load(asset::system("res/ComponentLibrary/BefacoTinyKnob.svg")));
  552. }
  553. };
  554. struct BefacoSlidePot : app::SvgSlider {
  555. BefacoSlidePot() {
  556. math::Vec margin = math::Vec(3.5, 3.5);
  557. maxHandlePos = math::Vec(-1, -2).plus(margin);
  558. minHandlePos = math::Vec(-1, 87).plus(margin);
  559. setBackgroundSvg(Svg::load(asset::system("res/ComponentLibrary/BefacoSlidePot.svg")));
  560. setHandleSvg(Svg::load(asset::system("res/ComponentLibrary/BefacoSlidePotHandle.svg")));
  561. background->box.pos = margin;
  562. box.size = background->box.size.plus(margin.mult(2));
  563. }
  564. };
  565. struct LEDSlider : app::SvgSlider {
  566. LEDSlider() {
  567. setBackgroundSvg(Svg::load(asset::system("res/ComponentLibrary/LEDSlider.svg")));
  568. setHandleSvg(Svg::load(asset::system("res/ComponentLibrary/LEDSliderHandle.svg")));
  569. setHandlePosCentered(
  570. math::Vec(19.84260/2, 76.53517 - 11.74218/2),
  571. math::Vec(19.84260/2, 0.0 + 11.74218/2)
  572. );
  573. }
  574. };
  575. // TODO Modernize
  576. struct LEDSliderHorizontal : app::SvgSlider {
  577. LEDSliderHorizontal() {
  578. horizontal = true;
  579. maxHandlePos = mm2px(math::Vec(22.078, 0.738).plus(math::Vec(0, 2)));
  580. minHandlePos = mm2px(math::Vec(0.738, 0.738).plus(math::Vec(0, 2)));
  581. setBackgroundSvg(Svg::load(asset::system("res/ComponentLibrary/LEDSliderHorizontal.svg")));
  582. }
  583. };
  584. template <typename TBase, typename TLightBase = RedLight>
  585. struct LightSlider : TBase {
  586. app::ModuleLightWidget* light;
  587. LightSlider() {
  588. light = new TLightBase;
  589. this->addChild(light);
  590. }
  591. app::ModuleLightWidget* getLight() {
  592. return light;
  593. }
  594. void step() override {
  595. TBase::step();
  596. // Move center of light to center of handle
  597. light->box.pos = this->handle->box.pos
  598. .plus(this->handle->box.size.div(2))
  599. .minus(light->box.size.div(2));
  600. }
  601. };
  602. template <typename TBase>
  603. struct LEDSliderLight : RectangleLight<TSvgLight<TBase>> {
  604. LEDSliderLight() {
  605. this->setSvg(Svg::load(asset::system("res/ComponentLibrary/LEDSliderLight.svg")));
  606. }
  607. };
  608. template <typename TLightBase = RedLight>
  609. struct LEDLightSlider : LightSlider<LEDSlider, LEDSliderLight<TLightBase>> {
  610. LEDLightSlider() {}
  611. };
  612. /** Deprecated. Use LEDSliderLight with your preferred LightWidget. */
  613. struct LEDSliderGreen : LEDLightSlider<GreenLight> {};
  614. struct LEDSliderRed : LEDLightSlider<RedLight> {};
  615. struct LEDSliderYellow : LEDLightSlider<YellowLight> {};
  616. struct LEDSliderBlue : LEDLightSlider<BlueLight> {};
  617. struct LEDSliderWhite : LEDLightSlider<WhiteLight> {};
  618. // TODO Modernize
  619. template <typename TLightBase = RedLight>
  620. struct LEDLightSliderHorizontal : LightSlider<LEDSliderHorizontal, TLightBase> {
  621. LEDLightSliderHorizontal() {
  622. this->setHandleSvg(Svg::load(asset::system("res/ComponentLibrary/LEDSliderHorizontalHandle.svg")));
  623. this->light->box.size = mm2px(math::Vec(3.276, 1.524));
  624. }
  625. };
  626. ////////////////////
  627. // Ports
  628. ////////////////////
  629. struct PJ301MPort : app::SvgPort {
  630. PJ301MPort() {
  631. setSvg(Svg::load(asset::system("res/ComponentLibrary/PJ301M.svg")));
  632. }
  633. };
  634. struct PJ3410Port : app::SvgPort {
  635. PJ3410Port() {
  636. setSvg(Svg::load(asset::system("res/ComponentLibrary/PJ3410.svg")));
  637. }
  638. };
  639. struct CL1362Port : app::SvgPort {
  640. CL1362Port() {
  641. setSvg(Svg::load(asset::system("res/ComponentLibrary/CL1362.svg")));
  642. }
  643. };
  644. ////////////////////
  645. // Switches
  646. ////////////////////
  647. template <typename TSwitch>
  648. struct LatchingSwitch : TSwitch {
  649. LatchingSwitch() {
  650. this->momentary = false;
  651. }
  652. };
  653. template <typename TSwitch>
  654. struct MomentarySwitch : TSwitch {
  655. MomentarySwitch() {
  656. this->momentary = true;
  657. }
  658. };
  659. struct NKK : app::SvgSwitch {
  660. NKK() {
  661. addFrame(Svg::load(asset::system("res/ComponentLibrary/NKK_0.svg")));
  662. addFrame(Svg::load(asset::system("res/ComponentLibrary/NKK_1.svg")));
  663. addFrame(Svg::load(asset::system("res/ComponentLibrary/NKK_2.svg")));
  664. }
  665. };
  666. struct CKSS : app::SvgSwitch {
  667. CKSS() {
  668. addFrame(Svg::load(asset::system("res/ComponentLibrary/CKSS_0.svg")));
  669. addFrame(Svg::load(asset::system("res/ComponentLibrary/CKSS_1.svg")));
  670. }
  671. };
  672. struct CKSSThree : app::SvgSwitch {
  673. CKSSThree() {
  674. addFrame(Svg::load(asset::system("res/ComponentLibrary/CKSSThree_0.svg")));
  675. addFrame(Svg::load(asset::system("res/ComponentLibrary/CKSSThree_1.svg")));
  676. addFrame(Svg::load(asset::system("res/ComponentLibrary/CKSSThree_2.svg")));
  677. }
  678. };
  679. struct CKSSThreeHorizontal : app::SvgSwitch {
  680. CKSSThreeHorizontal() {
  681. addFrame(Svg::load(asset::system("res/ComponentLibrary/CKSSThreeHorizontal_0.svg")));
  682. addFrame(Svg::load(asset::system("res/ComponentLibrary/CKSSThreeHorizontal_1.svg")));
  683. addFrame(Svg::load(asset::system("res/ComponentLibrary/CKSSThreeHorizontal_2.svg")));
  684. }
  685. };
  686. struct CKD6 : app::SvgSwitch {
  687. CKD6() {
  688. momentary = true;
  689. addFrame(Svg::load(asset::system("res/ComponentLibrary/CKD6_0.svg")));
  690. addFrame(Svg::load(asset::system("res/ComponentLibrary/CKD6_1.svg")));
  691. }
  692. };
  693. struct TL1105 : app::SvgSwitch {
  694. TL1105() {
  695. momentary = true;
  696. addFrame(Svg::load(asset::system("res/ComponentLibrary/TL1105_0.svg")));
  697. addFrame(Svg::load(asset::system("res/ComponentLibrary/TL1105_1.svg")));
  698. }
  699. };
  700. struct LEDButton : app::SvgSwitch {
  701. LEDButton() {
  702. momentary = true;
  703. addFrame(Svg::load(asset::system("res/ComponentLibrary/LEDButton.svg")));
  704. addFrame(Svg::load(asset::system("res/ComponentLibrary/LEDButton_1.svg")));
  705. }
  706. };
  707. template <typename TLight>
  708. struct LEDLightButton : LEDButton {
  709. app::ModuleLightWidget* light;
  710. LEDLightButton() {
  711. light = new TLight;
  712. // Move center of light to center of box
  713. light->box.pos = box.size.div(2).minus(light->box.size.div(2));
  714. addChild(light);
  715. }
  716. app::ModuleLightWidget* getLight() {
  717. return light;
  718. }
  719. };
  720. struct BefacoSwitch : app::SvgSwitch {
  721. BefacoSwitch() {
  722. addFrame(Svg::load(asset::system("res/ComponentLibrary/BefacoSwitch_0.svg")));
  723. addFrame(Svg::load(asset::system("res/ComponentLibrary/BefacoSwitch_1.svg")));
  724. addFrame(Svg::load(asset::system("res/ComponentLibrary/BefacoSwitch_2.svg")));
  725. }
  726. };
  727. struct BefacoPush : app::SvgSwitch {
  728. BefacoPush() {
  729. momentary = true;
  730. addFrame(Svg::load(asset::system("res/ComponentLibrary/BefacoPush_0.svg")));
  731. addFrame(Svg::load(asset::system("res/ComponentLibrary/BefacoPush_1.svg")));
  732. }
  733. };
  734. struct LEDBezel : app::SvgSwitch {
  735. LEDBezel() {
  736. momentary = true;
  737. addFrame(Svg::load(asset::system("res/ComponentLibrary/LEDBezel.svg")));
  738. }
  739. };
  740. template <typename TLightBase = WhiteLight>
  741. struct LEDLightBezel : LEDBezel {
  742. app::ModuleLightWidget* light;
  743. LEDLightBezel() {
  744. light = new LEDBezelLight<TLightBase>;
  745. // Move center of light to center of box
  746. light->box.pos = box.size.div(2).minus(light->box.size.div(2));
  747. addChild(light);
  748. }
  749. app::ModuleLightWidget* getLight() {
  750. return light;
  751. }
  752. };
  753. struct PB61303 : app::SvgSwitch {
  754. PB61303() {
  755. momentary = true;
  756. addFrame(Svg::load(asset::system("res/ComponentLibrary/PB61303.svg")));
  757. }
  758. };
  759. ////////////////////
  760. // Misc
  761. ////////////////////
  762. struct ScrewSilver : app::SvgScrew {
  763. ScrewSilver() {
  764. setSvg(Svg::load(asset::system("res/ComponentLibrary/ScrewSilver.svg")));
  765. }
  766. };
  767. struct ScrewBlack : app::SvgScrew {
  768. ScrewBlack() {
  769. setSvg(Svg::load(asset::system("res/ComponentLibrary/ScrewBlack.svg")));
  770. }
  771. };
  772. struct SegmentDisplay : widget::Widget {
  773. int lightsLen = 0;
  774. bool vertical = false;
  775. float margin = mm2px(0.5);
  776. void draw(const DrawArgs& args) override {
  777. // Background
  778. nvgBeginPath(args.vg);
  779. nvgRect(args.vg, 0, 0, box.size.x, box.size.y);
  780. nvgFillColor(args.vg, color::BLACK);
  781. nvgFill(args.vg);
  782. Widget::draw(args);
  783. }
  784. template <typename TLightBase = WhiteLight>
  785. void setLights(engine::Module* module, int firstLightId, int lightsLen) {
  786. clearChildren();
  787. this->lightsLen = lightsLen;
  788. float r = (vertical ? box.size.y : box.size.x) - margin;
  789. for (int i = 0; i < lightsLen; i++) {
  790. float p = float(i) / lightsLen;
  791. app::ModuleLightWidget* light = new RectangleLight<TLightBase>;
  792. if (vertical) {
  793. light->box.pos.y = p * r + margin;
  794. light->box.size.y = r / lightsLen - margin;
  795. light->box.size.x = box.size.x;
  796. }
  797. else {
  798. light->box.pos.x = p * r + margin;
  799. light->box.size.x = r / lightsLen - margin;
  800. light->box.size.y = box.size.y;
  801. }
  802. light->module = module;
  803. light->firstLightId = firstLightId;
  804. firstLightId += light->baseColors.size();
  805. addChild(light);
  806. }
  807. }
  808. };
  809. struct AudioButton_ADAT : app::AudioButton {
  810. AudioButton_ADAT() {
  811. addFrame(Svg::load(asset::system("res/ComponentLibrary/ADAT.svg")));
  812. shadow->opacity = 0.0;
  813. }
  814. };
  815. struct AudioButton_USB_B : app::AudioButton {
  816. AudioButton_USB_B() {
  817. addFrame(Svg::load(asset::system("res/ComponentLibrary/USB-B.svg")));
  818. shadow->opacity = 0.0;
  819. }
  820. };
  821. struct MidiButton_MIDI_DIN : app::MidiButton {
  822. MidiButton_MIDI_DIN() {
  823. addFrame(Svg::load(asset::system("res/ComponentLibrary/MIDI_DIN.svg")));
  824. shadow->opacity = 0.0;
  825. }
  826. };
  827. } // namespace componentlibrary
  828. } // namespace rack