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.

93 lines
2.1KB

  1. #pragma once
  2. #include <utility>
  3. #include <app.hpp>
  4. #include <componentlibrary.hpp>
  5. #include "display/controls.h"
  6. #include "display/menus.h"
  7. namespace DHE {
  8. template <typename T> class Control {
  9. public:
  10. std::function<void(T)> notify{[](T) {}};
  11. };
  12. template <typename P>
  13. class Knob : public Control<float>, public rack::RoundKnob {
  14. public:
  15. explicit Knob(const std::string &size) {
  16. static const auto prefix = std::string{"knob-"};
  17. setSVG(P::svg(prefix + size));
  18. shadow->opacity = 0.f;
  19. }
  20. void onChange(rack::EventChange &e) override {
  21. rack::RoundKnob::onChange(e);
  22. notify(this->value);
  23. }
  24. };
  25. template <typename P> class LargeKnob : public Knob<P> {
  26. public:
  27. LargeKnob() : Knob<P>("large") {}
  28. };
  29. template <typename P> class MediumKnob : public Knob<P> {
  30. public:
  31. MediumKnob() : Knob<P>("medium") {}
  32. };
  33. template <typename P> class SmallKnob : public Knob<P> {
  34. public:
  35. SmallKnob() : Knob<P>("small") {}
  36. };
  37. template <typename P> class TinyKnob : public Knob<P> {
  38. public:
  39. TinyKnob() : Knob<P>("tiny") {}
  40. };
  41. template <typename P>
  42. class Button : public Control<bool>,
  43. public rack::SVGSwitch,
  44. public rack::MomentarySwitch {
  45. public:
  46. explicit Button(const std::string &name = "button") {
  47. addFrame(P::svg(name + "-1"));
  48. addFrame(P::svg(name + "-2"));
  49. }
  50. void onChange(rack::EventChange &e) override {
  51. rack::SVGSwitch::onChange(e);
  52. notify(this->value > 0.5f);
  53. }
  54. };
  55. template <typename P> class ReverseButton : public Button<P> {
  56. public:
  57. ReverseButton() : Button<P>("button-reversed") {}
  58. };
  59. template <typename P, int N>
  60. class Toggle : public Control<int>,
  61. public rack::SVGSwitch,
  62. public rack::ToggleSwitch {
  63. public:
  64. explicit Toggle(const std::string &name = "toggle-" + std::to_string(N)) {
  65. auto base = name + "-";
  66. for (int position = 1; position <= size; position++) {
  67. addFrame(P::svg(base + std::to_string(position)));
  68. }
  69. }
  70. void onChange(rack::EventChange &e) override {
  71. rack::SVGSwitch::onChange(e);
  72. notify(static_cast<int>(this->value));
  73. }
  74. static constexpr auto size = N;
  75. };
  76. } // namespace DHE