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.

207 lines
4.5KB

  1. #include "ML_components.hpp"
  2. #include <functional>
  3. using namespace rack;
  4. MLSVGSwitch::MLSVGSwitch() {
  5. shadow = new CircularShadow();
  6. addChild(shadow);
  7. shadow->box.size = Vec();
  8. sw = new SVGWidget();
  9. addChild(sw);
  10. }
  11. void MLSVGSwitch::addFrame(std::shared_ptr<SVG> svg) {
  12. frames.push_back(svg);
  13. // If this is our first frame, automatically set SVG and size
  14. if (!sw->svg) {
  15. sw->setSVG(svg);
  16. box.size = sw->box.size;
  17. }
  18. }
  19. void MLSVGSwitch::onChange(EventChange &e) {
  20. assert(frames.size() > 0);
  21. float valueScaled = rescale(value, minValue, maxValue, 0, frames.size() - 1);
  22. int index = clamp((int) roundf(valueScaled), 0, (int) frames.size() - 1);
  23. sw->setSVG(frames[index]);
  24. dirty = true;
  25. ParamWidget::onChange(e);
  26. }
  27. WhiteLight::WhiteLight() {
  28. addBaseColor(COLOR_WHITE);
  29. }
  30. BlueMLKnob::BlueMLKnob() {
  31. setSVG(SVG::load(assetPlugin(plugin,"res/Knob.svg")));
  32. };
  33. SmallBlueMLKnob::SmallBlueMLKnob() {
  34. setSVG(SVG::load(assetPlugin(plugin,"res/Knob_28.svg")));
  35. };
  36. BlueSnapMLKnob::BlueSnapMLKnob() {
  37. setSVG(SVG::load(assetPlugin(plugin,"res/Knob.svg")));
  38. snap = true;
  39. };
  40. SmallBlueSnapMLKnob::SmallBlueSnapMLKnob() {
  41. setSVG(SVG::load(assetPlugin(plugin,"res/Knob_28.svg")));
  42. snap = true;
  43. };
  44. RedMLKnob::RedMLKnob() {
  45. setSVG(SVG::load(assetPlugin(plugin,"res/RedKnob.svg")));
  46. };
  47. SmallRedMLKnob::SmallRedMLKnob() {
  48. setSVG(SVG::load(assetPlugin(plugin,"res/RedKnob_28.svg")));
  49. };
  50. RedSnapMLKnob::RedSnapMLKnob() {
  51. setSVG(SVG::load(assetPlugin(plugin,"res/RedKnob.svg")));
  52. snap = true;
  53. };
  54. SmallRedSnapMLKnob::SmallRedSnapMLKnob() {
  55. setSVG(SVG::load(assetPlugin(plugin,"res/RedKnob_28.svg")));
  56. snap = true;
  57. };
  58. GreyMLKnob::GreyMLKnob() {
  59. setSVG(SVG::load(assetPlugin(plugin,"res/GreyKnob.svg")));
  60. };
  61. SmallGreyMLKnob::SmallGreyMLKnob() {
  62. setSVG(SVG::load(assetPlugin(plugin,"res/GreyKnob_28.svg")));
  63. };
  64. GreySnapMLKnob::GreySnapMLKnob() {
  65. setSVG(SVG::load(assetPlugin(plugin,"res/GreyKnob.svg")));
  66. snap = true;
  67. };
  68. SmallGreySnapMLKnob::SmallGreySnapMLKnob() {
  69. setSVG(SVG::load(assetPlugin(plugin,"res/GreyKnob_28.svg")));
  70. snap = true;
  71. };
  72. MLPort::MLPort() {
  73. setSVG(SVG::load(assetPlugin(plugin, "res/Jack.svg")));
  74. };
  75. MLButton::MLButton() {
  76. addFrame(SVG::load(assetPlugin(plugin, "res/MLButton_0.svg")));
  77. addFrame(SVG::load(assetPlugin(plugin, "res/MLButton_1.svg")));
  78. sw->wrap();
  79. box.size = sw->box.size;
  80. };
  81. MLSmallButton::MLSmallButton() {
  82. addFrame(SVG::load(assetPlugin(plugin, "res/SmallButton_0.svg")));
  83. addFrame(SVG::load(assetPlugin(plugin, "res/SmallButton_1.svg")));
  84. sw->wrap();
  85. box.size = sw->box.size;
  86. };
  87. ML_LEDButton::ML_LEDButton() {
  88. addFrame(SVG::load(assetPlugin(plugin, "res/LEDButton.svg")));
  89. sw->wrap();
  90. box.size = sw->box.size;
  91. shadow->box.size = box.size;
  92. shadow->blurRadius = 0.0f;
  93. shadow->box.pos = Vec(0, sw->box.size.y * 0.1);
  94. };
  95. ML_MediumLEDButton::ML_MediumLEDButton() {
  96. addFrame(SVG::load(assetPlugin(plugin, "res/LEDButton_medium.svg")));
  97. sw->wrap();
  98. box.size = sw->box.size;
  99. shadow->box.size = box.size;
  100. shadow->blurRadius = 0.0f;
  101. shadow->box.pos = Vec(0, sw->box.size.y * 0.1);
  102. };
  103. ML_SmallLEDButton::ML_SmallLEDButton() {
  104. addFrame(SVG::load(assetPlugin(plugin, "res/LEDButton_small.svg")));
  105. sw->wrap();
  106. box.size = sw->box.size;
  107. shadow->box.size = box.size;
  108. shadow->blurRadius = 0.0f;
  109. shadow->box.pos = Vec(0, sw->box.size.y * 0.1);
  110. };
  111. ML_ResetButton::ML_ResetButton() {
  112. addFrame(SVG::load(assetPlugin(plugin, "res/ResetButton_0.svg")));
  113. addFrame(SVG::load(assetPlugin(plugin, "res/ResetButton_1.svg")));
  114. sw->wrap();
  115. box.size = sw->box.size;
  116. }
  117. MLSwitch::MLSwitch() {
  118. addFrame(SVG::load(assetPlugin(plugin, "res/Switch_0.svg")));
  119. addFrame(SVG::load(assetPlugin(plugin, "res/Switch_1.svg")));
  120. addFrame(SVG::load(assetPlugin(plugin, "res/Switch_2.svg")));
  121. shadow->box.size = box.size;
  122. shadow->blurRadius = 0.0f;
  123. shadow->box.pos = Vec(0, sw->box.size.y * 0.1);
  124. };
  125. MLSwitch2::MLSwitch2() {
  126. addFrame(SVG::load(assetPlugin(plugin, "res/Switch_0.svg")));
  127. addFrame(SVG::load(assetPlugin(plugin, "res/Switch_2.svg")));
  128. shadow->box.size = box.size;
  129. shadow->blurRadius = 0.0f;
  130. shadow->box.pos = Vec(0, sw->box.size.y * 0.1);
  131. };
  132. BlueMLSwitch::BlueMLSwitch() {
  133. addFrame(SVG::load(assetPlugin(plugin, "res/BlueSwitch_0.svg")));
  134. addFrame(SVG::load(assetPlugin(plugin, "res/BlueSwitch_1.svg")));
  135. addFrame(SVG::load(assetPlugin(plugin, "res/BlueSwitch_2.svg")));
  136. shadow->box.size = box.size;
  137. shadow->blurRadius = 0.0f;
  138. shadow->box.pos = Vec(0, sw->box.size.y * 0.1);
  139. };