Browse Source

Add ParamQuantity::smoothEnabled.

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
c08c6e365a
5 changed files with 18 additions and 13 deletions
  1. +1
    -1
      include/app/Knob.hpp
  2. +2
    -0
      include/engine/ParamQuantity.hpp
  3. +6
    -10
      src/app/Knob.cpp
  4. +1
    -0
      src/app/Switch.cpp
  5. +8
    -2
      src/engine/ParamQuantity.cpp

+ 1
- 1
include/app/Knob.hpp View File

@@ -17,7 +17,7 @@ struct Knob : ParamWidget {
bool horizontal = false;
/** Enables per-sample value smoothing while dragging. */
bool smooth = true;
/** DEPRECATED. Use `ParamQuantity::snapEnabled`. */
/** Enables value snapping to the nearest integer. */
bool snap = false;
/** Multiplier for mouse movement to adjust knob value */
float speed = 1.f;


+ 2
- 0
include/engine/ParamQuantity.hpp View File

@@ -58,6 +58,8 @@ struct ParamQuantity : Quantity {
Unbounded (infinite) parameters are not randomizable, regardless of this setting.
*/
bool randomizeEnabled = true;
/** Enables per-sample Engine parameter smoothing when setSmoothValue() is called. */
bool smoothEnabled = false;
/** Rounds values to the nearest integer. */
bool snapEnabled = false;



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

@@ -40,6 +40,8 @@ void Knob::initParamQuantity() {
if (pq) {
if (snap)
pq->snapEnabled = true;
if (smooth)
pq->smoothEnabled = true;
}
}

@@ -133,7 +135,7 @@ void Knob::onDragMove(const DragMoveEvent& e) {

engine::ParamQuantity* pq = getParamQuantity();
if (pq) {
float value = smooth ? pq->getSmoothValue() : pq->getValue();
float value = pq->getSmoothValue();

// Ratio between parameter value scale / (angle range / 2*pi)
float rangeRatio;
@@ -206,10 +208,7 @@ void Knob::onDragMove(const DragMoveEvent& e) {
}

// Set value
if (smooth)
pq->setSmoothValue(value);
else
pq->setValue(value);
pq->setSmoothValue(value);
}

ParamWidget::onDragMove(e);
@@ -230,7 +229,7 @@ void Knob::onHoverScroll(const HoverScrollEvent& e) {
if (settings::knobScroll) {
engine::ParamQuantity* pq = getParamQuantity();
if (pq) {
float value = smooth ? pq->getSmoothValue() : pq->getValue();
float value = pq->getSmoothValue();

float rangeRatio;
if (pq->isBounded()) {
@@ -254,10 +253,7 @@ void Knob::onHoverScroll(const HoverScrollEvent& e) {
}

value += delta;
if (smooth)
pq->setSmoothValue(value);
else
pq->setValue(value);
pq->setSmoothValue(value);

e.consume(this);
}


+ 1
- 0
src/app/Switch.cpp View File

@@ -14,6 +14,7 @@ void Switch::initParamQuantity() {
engine::ParamQuantity* pq = getParamQuantity();
if (pq) {
pq->snapEnabled = true;
pq->smoothEnabled = false;
if (momentary) {
pq->resetEnabled = false;
pq->randomizeEnabled = false;


+ 8
- 2
src/engine/ParamQuantity.cpp View File

@@ -22,13 +22,19 @@ void ParamQuantity::setSmoothValue(float value) {
value = math::clampSafe(value, getMinValue(), getMaxValue());
if (snapEnabled)
value = std::round(value);
APP->engine->setParamSmoothValue(module, paramId, value);
if (smoothEnabled)
APP->engine->setParamSmoothValue(module, paramId, value);
else
APP->engine->setParamValue(module, paramId, value);
}

float ParamQuantity::getSmoothValue() {
if (!module)
return 0.f;
return APP->engine->getParamSmoothValue(module, paramId);
if (smoothEnabled)
return APP->engine->getParamSmoothValue(module, paramId);
else
return APP->engine->getParamValue(module, paramId);
}

void ParamQuantity::setSmoothScaledValue(float scaledValue) {


Loading…
Cancel
Save