Browse Source

Added boolean parameter to make knobs snap, made them visually snap as

well
tags/v0.5.0
Andrew Belt 7 years ago
parent
commit
5cee9b53a9
4 changed files with 25 additions and 13 deletions
  1. +1
    -1
      README.md
  2. +3
    -8
      include/app.hpp
  3. +15
    -3
      include/components.hpp
  4. +6
    -1
      src/app/Knob.cpp

+ 1
- 1
README.md View File

@@ -20,7 +20,7 @@ Rack's dependencies (GLEW, glfw, etc) do not need to be installed on your system
### Mac ### Mac


Install [Xcode](https://developer.apple.com/xcode/). 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 ### Windows




+ 3
- 8
include/app.hpp View File

@@ -183,6 +183,9 @@ struct ParamWidget : OpaqueWidget, QuantityWidget {


/** Implements vertical dragging behavior for ParamWidgets */ /** Implements vertical dragging behavior for ParamWidgets */
struct Knob : ParamWidget { struct Knob : ParamWidget {
/** Snap to nearest integer while dragging */
bool snap = false;
float snapValue;
void onDragStart(); void onDragStart();
void onDragMove(Vec mouseRel); void onDragMove(Vec mouseRel);
void onDragEnd(); void onDragEnd();
@@ -209,14 +212,6 @@ struct SVGKnob : virtual Knob, FramebufferWidget {
void onChange(); 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 { struct SVGSlider : Knob, FramebufferWidget {
/** Intermediate positions will be interpolated between these positions */ /** Intermediate positions will be interpolated between these positions */
Vec minHandlePos, maxHandlePos; Vec minHandlePos, maxHandlePos;


+ 15
- 3
include/components.hpp View File

@@ -57,7 +57,11 @@ struct RoundHugeBlackKnob : RoundBlackKnob {
} }
}; };


struct RoundSmallBlackSnapKnob : RoundSmallBlackKnob, SnapKnob {};
struct RoundSmallBlackSnapKnob : RoundSmallBlackKnob {
RoundSmallBlackSnapKnob() {
snap = true;
}
};




struct Davies1900hKnob : SVGKnob { struct Davies1900hKnob : SVGKnob {
@@ -109,7 +113,11 @@ struct Davies1900hSmallBlackKnob : Davies1900hKnob {
} }
}; };


struct Davies1900hSmallBlackSnapKnob : Davies1900hSmallBlackKnob, SnapKnob {};
struct Davies1900hSmallBlackSnapKnob : Davies1900hSmallBlackKnob {
Davies1900hSmallBlackSnapKnob() {
snap = true;
}
};




struct Rogan : SVGKnob { struct Rogan : SVGKnob {
@@ -366,7 +374,11 @@ struct BefacoBigKnob : SVGKnob {
} }
}; };


struct BefacoBigSnapKnob : BefacoBigKnob, SnapKnob {};
struct BefacoBigSnapKnob : BefacoBigKnob {
BefacoBigSnapKnob() {
snap = true;
}
};


struct BefacoTinyKnob : SVGKnob { struct BefacoTinyKnob : SVGKnob {
BefacoTinyKnob() { BefacoTinyKnob() {


+ 6
- 1
src/app/Knob.cpp View File

@@ -12,6 +12,7 @@ namespace rack {


void Knob::onDragStart() { void Knob::onDragStart() {
guiCursorLock(); guiCursorLock();
snapValue = value;
randomizable = false; randomizable = false;
} }


@@ -19,7 +20,11 @@ void Knob::onDragMove(Vec mouseRel) {
// Drag slower if Mod // Drag slower if Mod
if (guiIsModPressed()) if (guiIsModPressed())
mouseRel = mouseRel.mult(1/16.0); 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() { void Knob::onDragEnd() {


Loading…
Cancel
Save