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.

204 lines
4.4KB

  1. #include "widgets.hpp"
  2. #include "dsp/signal.hpp"
  3. using namespace bogaudio;
  4. using namespace bogaudio::dsp;
  5. Button18::Button18() {
  6. addFrame(SVG::load(assetPlugin(plugin, "res/button_18px_0.svg")));
  7. addFrame(SVG::load(assetPlugin(plugin, "res/button_18px_1.svg")));
  8. box.size = Vec(18, 18);
  9. }
  10. BGKnob::BGKnob(const char* svg, int dim) {
  11. setSVG(SVG::load(assetPlugin(plugin, svg)));
  12. box.size = Vec(dim, dim);
  13. shadow->blurRadius = 2.0;
  14. // k->shadow->opacity = 0.15;
  15. shadow->box.pos = Vec(0.0, 3.0);
  16. }
  17. Knob16::Knob16() : BGKnob("res/knob_16px.svg", 16) {
  18. shadow->box.pos = Vec(0.0, 2.5);
  19. }
  20. Knob19::Knob19() : BGKnob("res/knob_19px.svg", 19) {
  21. shadow->box.pos = Vec(0.0, 2.5);
  22. }
  23. Knob26::Knob26() : BGKnob("res/knob_26px.svg", 26) {
  24. }
  25. Knob29::Knob29() : BGKnob("res/knob_29px.svg", 29) {
  26. }
  27. Knob38::Knob38() : BGKnob("res/knob_38px.svg", 38) {
  28. }
  29. Knob45::Knob45() : BGKnob("res/knob_45px.svg", 45) {
  30. }
  31. Knob68::Knob68() : BGKnob("res/knob_68px.svg", 68) {
  32. shadow->box.pos = Vec(0.0, 4.0);
  33. }
  34. Port24::Port24() {
  35. setSVG(SVG::load(assetPlugin(plugin, "res/port.svg")));
  36. box.size = Vec(24, 24);
  37. shadow->blurRadius = 1.0;
  38. shadow->box.pos = Vec(0.0, 1.5);
  39. }
  40. BlankPort24::BlankPort24() {
  41. setSVG(NULL);
  42. box.size = Vec(24, 24);
  43. }
  44. SliderSwitch::SliderSwitch() {
  45. shadow = new CircularShadow();
  46. addChild(shadow);
  47. shadow->box.size = Vec();
  48. }
  49. SliderSwitch2State14::SliderSwitch2State14() {
  50. addFrame(SVG::load(assetPlugin(plugin, "res/slider_switch_2_14px_0.svg")));
  51. addFrame(SVG::load(assetPlugin(plugin, "res/slider_switch_2_14px_1.svg")));
  52. shadow->box.size = Vec(14.0, 24.0);
  53. shadow->blurRadius = 1.0;
  54. shadow->box.pos = Vec(0.0, 7.0);
  55. }
  56. StatefulButton::StatefulButton(const char* offSVGPath, const char* onSVGPath) {
  57. shadow = new CircularShadow();
  58. addChild(shadow);
  59. _svgWidget = new SVGWidget();
  60. addChild(_svgWidget);
  61. auto svg = SVG::load(assetPlugin(plugin, offSVGPath));
  62. _frames.push_back(svg);
  63. _frames.push_back(SVG::load(assetPlugin(plugin, onSVGPath)));
  64. _svgWidget->setSVG(svg);
  65. box.size = _svgWidget->box.size;
  66. shadow->box.size = _svgWidget->box.size;
  67. shadow->blurRadius = 1.0;
  68. shadow->box.pos = Vec(0.0, 1.0);
  69. }
  70. void StatefulButton::step() {
  71. FramebufferWidget::step();
  72. }
  73. void StatefulButton::onDragStart(EventDragStart& e) {
  74. _svgWidget->setSVG(_frames[1]);
  75. dirty = true;
  76. if (value >= maxValue) {
  77. setValue(minValue);
  78. }
  79. else {
  80. setValue(value + 1.0);
  81. }
  82. }
  83. void StatefulButton::onDragEnd(EventDragEnd& e) {
  84. _svgWidget->setSVG(_frames[0]);
  85. dirty = true;
  86. }
  87. StatefulButton9::StatefulButton9() : StatefulButton("res/button_9px_0.svg", "res/button_9px_1.svg") {
  88. }
  89. StatefulButton18::StatefulButton18() : StatefulButton("res/button_18px_0.svg", "res/button_18px_1.svg") {
  90. }
  91. ToggleButton18::ToggleButton18() {
  92. addFrame(SVG::load(assetPlugin(plugin, "res/button_18px_0.svg")));
  93. addFrame(SVG::load(assetPlugin(plugin, "res/button_18px_1.svg")));
  94. }
  95. NVGcolor bogaudio::decibelsToColor(float db) {
  96. if (db < -80.0f) {
  97. return nvgRGBA(0x00, 0x00, 0x00, 0x00);
  98. }
  99. if (db < -24.0f) {
  100. return nvgRGBA(0x55, 0xff, 0x00, (1.0f - (db + 24.0f) / -56.0f) * (float)0xff);
  101. }
  102. if (db < 0.0f) {
  103. return nvgRGBA((1.0f - db / -24.0f) * 0xff, 0xff, 0x00, 0xff);
  104. }
  105. #ifdef _MSC_VER
  106. #define sMIN(a,b) (((a)>(b))?(b):(a))
  107. return nvgRGBA(0xff, (1.0f - sMIN(db, 9.0f) / 9.0f) * 0xff, 0x00, 0xff);
  108. #else
  109. return nvgRGBA(0xff, (1.0f - std::min(db, 9.0f) / 9.0f) * 0xff, 0x00, 0xff);
  110. #endif
  111. }
  112. void VUSlider::draw(NVGcontext* vg) {
  113. nvgSave(vg);
  114. {
  115. nvgBeginPath(vg);
  116. nvgRoundedRect(vg, 6, 3, 6, box.size.y - 6, 2);
  117. nvgFillColor(vg, nvgRGBA(0x22, 0x22, 0x22, 0xff));
  118. nvgFill(vg);
  119. nvgStrokeColor(vg, nvgRGBA(0x88, 0x88, 0x88, 0xff));
  120. nvgStroke(vg);
  121. }
  122. nvgRestore(vg);
  123. nvgSave(vg);
  124. {
  125. nvgTranslate(vg, 0, (box.size.y - 13.0f) * (1.0f - value));
  126. nvgBeginPath(vg);
  127. nvgRoundedRect(vg, 0, 0, 18, 13, 1.5);
  128. nvgFillColor(vg, nvgRGBA(0x77, 0x77, 0x77, 0xff));
  129. nvgFill(vg);
  130. nvgBeginPath(vg);
  131. nvgRect(vg, 0, 2, 18, 9);
  132. nvgFillColor(vg, nvgRGBA(0x44, 0x44, 0x44, 0xff));
  133. nvgFill(vg);
  134. nvgBeginPath(vg);
  135. nvgRect(vg, 0, 6, 18, 1);
  136. nvgFillColor(vg, nvgRGBA(0xfa, 0xfa, 0xfa, 0xff));
  137. nvgFill(vg);
  138. nvgBeginPath(vg);
  139. nvgRoundedRect(vg, 2, 4, 14, 5, 1.0);
  140. nvgFillColor(vg, nvgRGBA(0xaa, 0xaa, 0xaa, 0xff));
  141. nvgFill(vg);
  142. float db = _vuLevel ? *_vuLevel : 0.0f;
  143. if (db > 0.0f) {
  144. db = amplitudeToDecibels(db);
  145. nvgBeginPath(vg);
  146. nvgRoundedRect(vg, 2, 4, 14, 5, 1.0);
  147. nvgFillColor(vg, decibelsToColor(db));
  148. nvgFill(vg);
  149. }
  150. }
  151. nvgRestore(vg);
  152. }