Browse Source

Fixed reset() and toJson() for continuous encoders

tags/v0.6.1
Andrew Belt 7 years ago
parent
commit
fa622a502b
2 changed files with 18 additions and 8 deletions
  1. +5
    -3
      src/app/Knob.cpp
  2. +13
    -5
      src/app/ParamWidget.cpp

+ 5
- 3
src/app/Knob.cpp View File

@@ -7,7 +7,8 @@

namespace rack {

#define KNOB_SENSITIVITY 0.0015

static const float KNOB_SENSITIVITY = 0.0015f;


Knob::Knob() {
@@ -26,13 +27,14 @@ void Knob::onDragMove(EventDragMove &e) {
range = maxValue - minValue;
}
else {
range = 1.0 - (-1.0);
// Continuous encoders scale as if their limits are +/-1
range = 1.f - (-1.f);
}
float delta = KNOB_SENSITIVITY * -e.mouseRel.y * speed * range;

// Drag slower if Mod is held
if (windowIsModPressed())
delta /= 16.0;
delta /= 16.f;
dragValue += delta;
dragValue = clamp2(dragValue, minValue, maxValue);
if (snap)


+ 13
- 5
src/app/ParamWidget.cpp View File

@@ -8,7 +8,10 @@ namespace rack {
json_t *ParamWidget::toJson() {
json_t *rootJ = json_object();
json_object_set_new(rootJ, "paramId", json_integer(paramId));
json_object_set_new(rootJ, "value", json_real(value));

// Infinite params should serialize to 0
float v = (isfinite(minValue) && isfinite(maxValue)) ? value : 0.f;
json_object_set_new(rootJ, "value", json_real(v));
return rootJ;
}

@@ -19,17 +22,22 @@ void ParamWidget::fromJson(json_t *rootJ) {
}

void ParamWidget::reset() {
setValue(defaultValue);
// Infinite params should not be reset
if (isfinite(minValue) && isfinite(maxValue)) {
setValue(defaultValue);
}
}

void ParamWidget::randomize() {
if (randomizable && isfinite(minValue) && isfinite(maxValue))
setValue(rescale(randomUniform(), 0.0, 1.0, minValue, maxValue));
// Infinite params should not be randomized
if (randomizable && isfinite(minValue) && isfinite(maxValue)) {
setValue(rescale(randomUniform(), 0.f, 1.f, minValue, maxValue));
}
}

void ParamWidget::onMouseDown(EventMouseDown &e) {
if (e.button == 1) {
setValue(defaultValue);
reset();
}
e.consumed = true;
e.target = this;


Loading…
Cancel
Save