diff --git a/README.md b/README.md index b9af12ba..74d85f62 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Rack's dependencies (GLEW, glfw, etc) do not need to be installed on your system ### Mac Install [Xcode](https://developer.apple.com/xcode/). -Install [CMake](https://cmake.org/) and wget, preferably from [Homebrew](https://brew.sh/). +Install [CMake](https://cmake.org/) (for some of Rack's dependencies) and wget, preferably from [Homebrew](https://brew.sh/). ### Windows diff --git a/include/app.hpp b/include/app.hpp index 25558904..1158067c 100644 --- a/include/app.hpp +++ b/include/app.hpp @@ -183,6 +183,9 @@ struct ParamWidget : OpaqueWidget, QuantityWidget { /** Implements vertical dragging behavior for ParamWidgets */ struct Knob : ParamWidget { + /** Snap to nearest integer while dragging */ + bool snap = false; + float snapValue; void onDragStart(); void onDragMove(Vec mouseRel); void onDragEnd(); @@ -209,14 +212,6 @@ struct SVGKnob : virtual Knob, FramebufferWidget { void onChange(); }; -/** Snaps to the nearest integer value on mouse release */ -struct SnapKnob : virtual Knob { - void onDragEnd() { - setValue(roundf(value)); - Knob::onDragEnd(); - } -}; - struct SVGSlider : Knob, FramebufferWidget { /** Intermediate positions will be interpolated between these positions */ Vec minHandlePos, maxHandlePos; diff --git a/include/components.hpp b/include/components.hpp index e261e06e..87d7276c 100644 --- a/include/components.hpp +++ b/include/components.hpp @@ -57,7 +57,11 @@ struct RoundHugeBlackKnob : RoundBlackKnob { } }; -struct RoundSmallBlackSnapKnob : RoundSmallBlackKnob, SnapKnob {}; +struct RoundSmallBlackSnapKnob : RoundSmallBlackKnob { + RoundSmallBlackSnapKnob() { + snap = true; + } +}; struct Davies1900hKnob : SVGKnob { @@ -109,7 +113,11 @@ struct Davies1900hSmallBlackKnob : Davies1900hKnob { } }; -struct Davies1900hSmallBlackSnapKnob : Davies1900hSmallBlackKnob, SnapKnob {}; +struct Davies1900hSmallBlackSnapKnob : Davies1900hSmallBlackKnob { + Davies1900hSmallBlackSnapKnob() { + snap = true; + } +}; struct Rogan : SVGKnob { @@ -366,7 +374,11 @@ struct BefacoBigKnob : SVGKnob { } }; -struct BefacoBigSnapKnob : BefacoBigKnob, SnapKnob {}; +struct BefacoBigSnapKnob : BefacoBigKnob { + BefacoBigSnapKnob() { + snap = true; + } +}; struct BefacoTinyKnob : SVGKnob { BefacoTinyKnob() { diff --git a/src/app/Knob.cpp b/src/app/Knob.cpp index d8961c53..ab52cf46 100644 --- a/src/app/Knob.cpp +++ b/src/app/Knob.cpp @@ -12,6 +12,7 @@ namespace rack { void Knob::onDragStart() { guiCursorLock(); + snapValue = value; randomizable = false; } @@ -19,7 +20,11 @@ void Knob::onDragMove(Vec mouseRel) { // Drag slower if Mod if (guiIsModPressed()) mouseRel = mouseRel.mult(1/16.0); - setValue(value - KNOB_SENSITIVITY * (maxValue - minValue) * mouseRel.y); + snapValue += KNOB_SENSITIVITY * (maxValue - minValue) * -mouseRel.y; + if (snap) + setValue(roundf(snapValue)); + else + setValue(snapValue); } void Knob::onDragEnd() {