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.

Knob.hpp 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #pragma once
  2. #include <app/common.hpp>
  3. #include <app/ParamWidget.hpp>
  4. #include <context.hpp>
  5. namespace rack {
  6. namespace app {
  7. /** Implements vertical dragging behavior for ParamWidgets */
  8. struct Knob : ParamWidget {
  9. struct Internal;
  10. Internal* internal;
  11. /** Drag horizontally instead of vertically. */
  12. bool horizontal = false;
  13. /** Enables per-sample value smoothing while dragging.
  14. Alternatively, use ParamQuantity::smoothEnabled.
  15. */
  16. bool smooth = true;
  17. /** Enables value snapping to the nearest integer.
  18. Alternatively, use ParamQuantity::snapEnabled.
  19. */
  20. bool snap = false;
  21. /** Multiplier for mouse movement to adjust knob value */
  22. float speed = 1.f;
  23. /** Force dragging to linear, e.g. for sliders. */
  24. bool forceLinear = false;
  25. /** Angles in radians.
  26. For drawing and handling the global radial knob setting.
  27. */
  28. float minAngle = -M_PI;
  29. float maxAngle = M_PI;
  30. Knob();
  31. ~Knob();
  32. void initParamQuantity() override;
  33. void onHover(const HoverEvent& e) override;
  34. void onButton(const ButtonEvent& e) override;
  35. void onDragStart(const DragStartEvent& e) override;
  36. void onDragEnd(const DragEndEvent& e) override;
  37. void onDragMove(const DragMoveEvent& e) override;
  38. void onDragLeave(const DragLeaveEvent& e) override;
  39. void onHoverScroll(const HoverScrollEvent& e) override;
  40. void onLeave(const LeaveEvent& e) override;
  41. /** Called when user clicks the knob without moving it.
  42. Useful for handling emulating push-knobs in hardware.
  43. */
  44. void onAction(const ActionEvent& e) override {}
  45. };
  46. } // namespace app
  47. } // namespace rack