Browse Source

Add `smooth` variable for ParamWidgets

tags/v0.6.0
Andrew Belt 6 years ago
parent
commit
4596d29f1c
4 changed files with 13 additions and 13 deletions
  1. +3
    -2
      include/app.hpp
  2. +2
    -0
      include/componentlibrary.hpp
  3. +4
    -10
      src/app/Knob.cpp
  4. +4
    -1
      src/app/ParamWidget.cpp

+ 3
- 2
include/app.hpp View File

@@ -217,6 +217,8 @@ struct ParamWidget : OpaqueWidget, QuantityWidget {
To permanently disable or change randomization behavior, override the randomize() method instead of changing this.
*/
bool randomizable = true;
/** Apply per-sample smoothing in the engine */
bool smooth = false;

json_t *toJson();
void fromJson(json_t *rootJ);
@@ -243,11 +245,10 @@ struct Knob : ParamWidget {
/** Multiplier for mouse movement to adjust knob value */
float speed = 1.0;
float dragValue;
Knob();
void onDragStart(EventDragStart &e) override;
void onDragMove(EventDragMove &e) override;
void onDragEnd(EventDragEnd &e) override;
/** Tell engine to smoothly vary this parameter */
void onChange(EventChange &e) override;
};

struct SpriteKnob : virtual Knob, SpriteWidget {


+ 2
- 0
include/componentlibrary.hpp View File

@@ -62,6 +62,7 @@ struct RoundHugeBlackKnob : RoundBlackKnob {
struct RoundSmallBlackSnapKnob : RoundSmallBlackKnob {
RoundSmallBlackSnapKnob() {
snap = true;
smooth = false;
}
};

@@ -312,6 +313,7 @@ struct BefacoBigKnob : SVGKnob {
struct BefacoBigSnapKnob : BefacoBigKnob {
BefacoBigSnapKnob() {
snap = true;
smooth = false;
}
};



+ 4
- 10
src/app/Knob.cpp View File

@@ -10,6 +10,10 @@ namespace rack {
#define KNOB_SENSITIVITY 0.0015


Knob::Knob() {
smooth = true;
}

void Knob::onDragStart(EventDragStart &e) {
windowCursorLock();
dragValue = value;
@@ -37,15 +41,5 @@ void Knob::onDragEnd(EventDragEnd &e) {
randomizable = true;
}

void Knob::onChange(EventChange &e) {
if (!module)
return;

if (snap)
engineSetParam(module, paramId, value);
else
engineSetParamSmooth(module, paramId, value);
}


} // namespace rack

+ 4
- 1
src/app/ParamWidget.cpp View File

@@ -39,7 +39,10 @@ void ParamWidget::onChange(EventChange &e) {
if (!module)
return;

engineSetParam(module, paramId, value);
if (smooth)
engineSetParamSmooth(module, paramId, value);
else
engineSetParam(module, paramId, value);
}




Loading…
Cancel
Save