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.

53 lines
987B

  1. #include "app.hpp"
  2. #include "window.hpp"
  3. #include "engine.hpp"
  4. // For GLFW_KEY_LEFT_CONTROL, etc.
  5. #include <GLFW/glfw3.h>
  6. namespace rack {
  7. static const float KNOB_SENSITIVITY = 0.0015f;
  8. Knob::Knob() {
  9. smooth = true;
  10. }
  11. void Knob::onDragStart(EventDragStart &e) {
  12. windowCursorLock();
  13. dragValue = value;
  14. randomizable = false;
  15. }
  16. void Knob::onDragMove(EventDragMove &e) {
  17. float range;
  18. if (std::isfinite(minValue) && std::isfinite(maxValue)) {
  19. range = maxValue - minValue;
  20. }
  21. else {
  22. // Continuous encoders scale as if their limits are +/-1
  23. range = 1.f - (-1.f);
  24. }
  25. float delta = KNOB_SENSITIVITY * -e.mouseRel.y * speed * range;
  26. // Drag slower if Mod is held
  27. if (windowIsModPressed())
  28. delta /= 16.f;
  29. dragValue += delta;
  30. dragValue = clampBetween(dragValue, minValue, maxValue);
  31. if (snap)
  32. setValue(std::round(dragValue));
  33. else
  34. setValue(dragValue);
  35. }
  36. void Knob::onDragEnd(EventDragEnd &e) {
  37. windowCursorUnlock();
  38. randomizable = true;
  39. }
  40. } // namespace rack