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.

407 lines
8.1KB

  1. #pragma once
  2. #include <cstdint>
  3. #include "asset.hpp"
  4. #include "rack.hpp"
  5. using namespace rack;
  6. #define plugin "SynthKit"
  7. struct WaveSelect : TransparentWidget {
  8. uint8_t *value;
  9. std::shared_ptr<Font> font;
  10. WaveSelect ( ) {
  11. value = NULL;
  12. font = Font::load(assetPlugin(plugin, "res/digit.ttf"));
  13. }
  14. void draw (NVGcontext *vg) override {
  15. nvgFontSize(vg, 8);
  16. nvgFontFaceId(vg, font->handle);
  17. nvgTextLetterSpacing(vg, 1);
  18. nvgFillColor(vg, nvgRGBA(0x00, 0xff, 0x00, 0xff));
  19. if (value) {
  20. switch (*value) {
  21. case 0:
  22. nvgText(vg, box.pos.x + 1, box.pos.y + 1, "SIN", NULL);
  23. break;
  24. case 1:
  25. nvgText(vg, box.pos.x + 1, box.pos.y + 1, "TRI", NULL);
  26. break;
  27. case 2:
  28. nvgText(vg, box.pos.x + 1, box.pos.y + 1, "SAW", NULL);
  29. break;
  30. case 3:
  31. nvgText(vg, box.pos.x + 1, box.pos.y + 1, "SQR", NULL);
  32. break;
  33. default:
  34. nvgText(vg, box.pos.x + 1, box.pos.y + 1, "ERR", NULL);
  35. break;
  36. }
  37. } else {
  38. nvgText(vg, box.pos.x + 1, box.pos.y + 1, "NUL", NULL);
  39. }
  40. }
  41. };
  42. struct ValueDisplay : TransparentWidget {
  43. float *value;
  44. std::shared_ptr<Font> font;
  45. ValueDisplay ( ) {
  46. value = NULL;
  47. font = Font::load(assetPlugin(plugin, "res/digit.ttf"));
  48. }
  49. void draw (NVGcontext *vg) override {
  50. char text[12];
  51. nvgFontSize(vg, 8);
  52. nvgFontFaceId(vg, font->handle);
  53. nvgTextLetterSpacing(vg, 1);
  54. nvgFillColor(vg, nvgRGBA(0x00, 0xff, 0x00, 0xff));
  55. if (value) {
  56. sprintf(text, "%6.2f", *value);
  57. } else {
  58. sprintf(text, "ERROR");
  59. }
  60. nvgText(vg, box.pos.x + 1, box.pos.y + 1, text, NULL);
  61. }
  62. };
  63. struct LEDDisplay : TransparentWidget {
  64. float *value;
  65. LEDDisplay ( ) {
  66. value = NULL;
  67. }
  68. void draw (NVGcontext *vg) override {
  69. NVGcolor red = nvgRGBA(192, 0, 0, 255);
  70. NVGcolor yellow = nvgRGBA(255, 192, 0, 255);
  71. NVGcolor green = nvgRGBA(0, 192, 0, 255);
  72. NVGcolor grey = nvgRGBA(64, 64, 64, 255);
  73. float val = *value ? *value : 0.0f;
  74. nvgBeginPath(vg);
  75. nvgRect(vg, 0, 0, 8, 8);
  76. if (fabs(val) >= 4.5) {
  77. nvgFillColor(vg, red);
  78. } else {
  79. nvgFillColor(vg, grey);
  80. }
  81. nvgFill(vg);
  82. nvgBeginPath(vg);
  83. nvgRect(vg, 0, 11, 8, 8);
  84. if (fabs(val) >= 4.0) {
  85. nvgFillColor(vg, yellow);
  86. } else {
  87. nvgFillColor(vg, grey);
  88. }
  89. nvgFill(vg);
  90. nvgBeginPath(vg);
  91. nvgRect(vg, 0, 22, 8, 8);
  92. if (fabs(val) >= 3.5) {
  93. nvgFillColor(vg, yellow);
  94. } else {
  95. nvgFillColor(vg, grey);
  96. }
  97. nvgFill(vg);
  98. nvgBeginPath(vg);
  99. nvgRect(vg, 0, 33, 8, 8);
  100. if (fabs(val) >= 3.0) {
  101. nvgFillColor(vg, green);
  102. } else {
  103. nvgFillColor(vg, grey);
  104. }
  105. nvgFill(vg);
  106. nvgBeginPath(vg);
  107. nvgRect(vg, 0, 44, 8, 8);
  108. if (fabs(val) >= 2.5) {
  109. nvgFillColor(vg, green);
  110. } else {
  111. nvgFillColor(vg, grey);
  112. }
  113. nvgFill(vg);
  114. nvgBeginPath(vg);
  115. nvgRect(vg, 0, 55, 8, 8);
  116. if (fabs(val) >= 2.0) {
  117. nvgFillColor(vg, green);
  118. } else {
  119. nvgFillColor(vg, grey);
  120. }
  121. nvgFill(vg);
  122. nvgBeginPath(vg);
  123. nvgRect(vg, 0, 66, 8, 8);
  124. if (fabs(val) >= 1.5) {
  125. nvgFillColor(vg, green);
  126. } else {
  127. nvgFillColor(vg, grey);
  128. }
  129. nvgFill(vg);
  130. nvgBeginPath(vg);
  131. nvgRect(vg, 0, 77, 8, 8);
  132. if (fabs(val) >= 1.0) {
  133. nvgFillColor(vg, green);
  134. } else {
  135. nvgFillColor(vg, grey);
  136. }
  137. nvgFill(vg);
  138. nvgBeginPath(vg);
  139. nvgRect(vg, 0, 88, 8, 8);
  140. if (fabs(val) >= 0.5) {
  141. nvgFillColor(vg, green);
  142. } else {
  143. nvgFillColor(vg, grey);
  144. }
  145. nvgFill(vg);
  146. nvgBeginPath(vg);
  147. nvgRect(vg, 0, 99, 8, 8);
  148. if (fabs(val) > 0.0) {
  149. nvgFillColor(vg, green);
  150. } else {
  151. nvgFillColor(vg, grey);
  152. }
  153. nvgFill(vg);
  154. }
  155. };
  156. struct LEDSmallDisplay : TransparentWidget {
  157. float *value;
  158. LEDSmallDisplay ( ) {
  159. value = NULL;
  160. }
  161. void draw (NVGcontext *vg) override {
  162. NVGcolor red = nvgRGBA(192, 0, 0, 255);
  163. NVGcolor yellow = nvgRGBA(255, 192, 0, 255);
  164. NVGcolor green = nvgRGBA(0, 192, 0, 255);
  165. NVGcolor grey = nvgRGBA(64, 64, 64, 255);
  166. float val = *value ? *value : 0.0f;
  167. nvgBeginPath(vg);
  168. nvgRect(vg, 0, 0, 8, 6);
  169. if (fabs(val) >= 4.5) {
  170. nvgFillColor(vg, red);
  171. } else {
  172. nvgFillColor(vg, grey);
  173. }
  174. nvgFill(vg);
  175. nvgBeginPath(vg);
  176. nvgRect(vg, 0, 8, 8, 6);
  177. if (fabs(val) >= 4.0) {
  178. nvgFillColor(vg, yellow);
  179. } else {
  180. nvgFillColor(vg, grey);
  181. }
  182. nvgFill(vg);
  183. nvgBeginPath(vg);
  184. nvgRect(vg, 0, 16, 8, 6);
  185. if (fabs(val) >= 3.5) {
  186. nvgFillColor(vg, yellow);
  187. } else {
  188. nvgFillColor(vg, grey);
  189. }
  190. nvgFill(vg);
  191. nvgBeginPath(vg);
  192. nvgRect(vg, 0, 24, 8, 6);
  193. if (fabs(val) >= 3.0) {
  194. nvgFillColor(vg, green);
  195. } else {
  196. nvgFillColor(vg, grey);
  197. }
  198. nvgFill(vg);
  199. nvgBeginPath(vg);
  200. nvgRect(vg, 0, 32, 8, 6);
  201. if (fabs(val) >= 2.5) {
  202. nvgFillColor(vg, green);
  203. } else {
  204. nvgFillColor(vg, grey);
  205. }
  206. nvgFill(vg);
  207. nvgBeginPath(vg);
  208. nvgRect(vg, 0, 40, 8, 6);
  209. if (fabs(val) >= 2.0) {
  210. nvgFillColor(vg, green);
  211. } else {
  212. nvgFillColor(vg, grey);
  213. }
  214. nvgFill(vg);
  215. nvgBeginPath(vg);
  216. nvgRect(vg, 0, 48, 8, 6);
  217. if (fabs(val) >= 1.5) {
  218. nvgFillColor(vg, green);
  219. } else {
  220. nvgFillColor(vg, grey);
  221. }
  222. nvgFill(vg);
  223. nvgBeginPath(vg);
  224. nvgRect(vg, 0, 56, 8, 6);
  225. if (fabs(val) >= 1.0) {
  226. nvgFillColor(vg, green);
  227. } else {
  228. nvgFillColor(vg, grey);
  229. }
  230. nvgFill(vg);
  231. nvgBeginPath(vg);
  232. nvgRect(vg, 0, 64, 8, 6);
  233. if (fabs(val) >= 0.5) {
  234. nvgFillColor(vg, green);
  235. } else {
  236. nvgFillColor(vg, grey);
  237. }
  238. nvgFill(vg);
  239. nvgBeginPath(vg);
  240. nvgRect(vg, 0, 72, 8, 6);
  241. if (fabs(val) > 0.0) {
  242. nvgFillColor(vg, green);
  243. } else {
  244. nvgFillColor(vg, grey);
  245. }
  246. nvgFill(vg);
  247. }
  248. };
  249. struct LEDWideDisplay : TransparentWidget {
  250. float *value;
  251. LEDWideDisplay ( ) {
  252. value = NULL;
  253. }
  254. void draw (NVGcontext *vg) override {
  255. NVGcolor red = nvgRGBA(192, 0, 0, 255);
  256. NVGcolor yellow = nvgRGBA(255, 192, 0, 255);
  257. NVGcolor green = nvgRGBA(0, 192, 0, 255);
  258. NVGcolor grey = nvgRGBA(64, 64, 64, 255);
  259. float val = *value ? *value : 0.0f;
  260. nvgBeginPath(vg);
  261. nvgRect(vg, 0, 0, 16, 8);
  262. if (fabs(val) >= 4.5) {
  263. nvgFillColor(vg, red);
  264. } else {
  265. nvgFillColor(vg, grey);
  266. }
  267. nvgFill(vg);
  268. nvgBeginPath(vg);
  269. nvgRect(vg, 0, 11, 16, 8);
  270. if (fabs(val) >= 4.0) {
  271. nvgFillColor(vg, yellow);
  272. } else {
  273. nvgFillColor(vg, grey);
  274. }
  275. nvgFill(vg);
  276. nvgBeginPath(vg);
  277. nvgRect(vg, 0, 22, 16, 8);
  278. if (fabs(val) >= 3.5) {
  279. nvgFillColor(vg, yellow);
  280. } else {
  281. nvgFillColor(vg, grey);
  282. }
  283. nvgFill(vg);
  284. nvgBeginPath(vg);
  285. nvgRect(vg, 0, 33, 16, 8);
  286. if (fabs(val) >= 3.0) {
  287. nvgFillColor(vg, green);
  288. } else {
  289. nvgFillColor(vg, grey);
  290. }
  291. nvgFill(vg);
  292. nvgBeginPath(vg);
  293. nvgRect(vg, 0, 44, 16, 8);
  294. if (fabs(val) >= 2.5) {
  295. nvgFillColor(vg, green);
  296. } else {
  297. nvgFillColor(vg, grey);
  298. }
  299. nvgFill(vg);
  300. nvgBeginPath(vg);
  301. nvgRect(vg, 0, 55, 16, 8);
  302. if (fabs(val) >= 2.0) {
  303. nvgFillColor(vg, green);
  304. } else {
  305. nvgFillColor(vg, grey);
  306. }
  307. nvgFill(vg);
  308. nvgBeginPath(vg);
  309. nvgRect(vg, 0, 66, 16, 8);
  310. if (fabs(val) >= 1.5) {
  311. nvgFillColor(vg, green);
  312. } else {
  313. nvgFillColor(vg, grey);
  314. }
  315. nvgFill(vg);
  316. nvgBeginPath(vg);
  317. nvgRect(vg, 0, 77, 16, 8);
  318. if (fabs(val) >= 1.0) {
  319. nvgFillColor(vg, green);
  320. } else {
  321. nvgFillColor(vg, grey);
  322. }
  323. nvgFill(vg);
  324. nvgBeginPath(vg);
  325. nvgRect(vg, 0, 88, 16, 8);
  326. if (fabs(val) >= 0.5) {
  327. nvgFillColor(vg, green);
  328. } else {
  329. nvgFillColor(vg, grey);
  330. }
  331. nvgFill(vg);
  332. nvgBeginPath(vg);
  333. nvgRect(vg, 0, 99, 16, 8);
  334. if (fabs(val) > 0.0) {
  335. nvgFillColor(vg, green);
  336. } else {
  337. nvgFillColor(vg, grey);
  338. }
  339. nvgFill(vg);
  340. }
  341. };
  342. template <typename BASE>
  343. struct ButtonLight : BASE {
  344. ButtonLight() {
  345. //this->box.size = Vec(20.0, 20.0);
  346. this->box.size = mm2px(Vec(6.0, 6.0));
  347. }
  348. };