Browse Source

Push ParamChange history action when scrolling knobs.

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
e80210779e
2 changed files with 35 additions and 2 deletions
  1. +1
    -0
      include/app/Knob.hpp
  2. +34
    -2
      src/app/Knob.cpp

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

@@ -37,6 +37,7 @@ struct Knob : ParamWidget {
void onDragMove(const DragMoveEvent& e) override;
void onDragLeave(const DragLeaveEvent& e) override;
void onHoverScroll(const HoverScrollEvent& e) override;
void onLeave(const LeaveEvent& e) override;
};




+ 34
- 2
src/app/Knob.cpp View File

@@ -13,7 +13,7 @@ namespace app {

struct Knob::Internal {
/** Value of the knob before dragging. */
float oldValue = 0.f;
float oldValue = NAN;
/** Fractional value between the param's value and the dragged knob position.
Using a "snapValue" variable and rounding is insufficient because the mouse needs to reach 1.0, not 0.5 to obtain the first increment.
*/
@@ -98,7 +98,7 @@ void Knob::onDragEnd(const DragEndEvent& e) {
engine::ParamQuantity* pq = getParamQuantity();
if (pq) {
float newValue = pq->getSmoothValue();
if (internal->oldValue != newValue) {
if (!std::isnan(internal->oldValue) && internal->oldValue != newValue) {
// Push ParamChange history action
history::ParamChange* h = new history::ParamChange;
h->name = "move knob";
@@ -111,6 +111,7 @@ void Knob::onDragEnd(const DragEndEvent& e) {
// Reset snap delta
internal->snapDelta = 0.f;
}
internal->oldValue = NAN;

ParamWidget::onDragEnd(e);
}
@@ -238,6 +239,10 @@ void Knob::onHoverScroll(const HoverScrollEvent& e) {
return;

float value = pq->getSmoothValue();
// Set old value if unset
if (std::isnan(internal->oldValue)) {
internal->oldValue = value;
}

float rangeRatio;
if (pq->isBounded()) {
@@ -247,6 +252,7 @@ void Knob::onHoverScroll(const HoverScrollEvent& e) {
rangeRatio = 1.f;
}


float delta = e.scrollDelta.y;
delta *= settings::knobScrollSensitivity;
delta *= getModSpeed();
@@ -267,5 +273,31 @@ void Knob::onHoverScroll(const HoverScrollEvent& e) {
}


void Knob::onLeave(const LeaveEvent& e) {
ParamWidget::onLeave(e);

if (!settings::knobScroll)
return;

engine::ParamQuantity* pq = getParamQuantity();
if (pq) {
float newValue = pq->getSmoothValue();
if (!std::isnan(internal->oldValue) && internal->oldValue != newValue) {
// Push ParamChange history action
history::ParamChange* h = new history::ParamChange;
h->name = "move knob";
h->moduleId = module->id;
h->paramId = paramId;
h->oldValue = internal->oldValue;
h->newValue = newValue;
APP->history->push(h);
}
// Reset snap delta
internal->snapDelta = 0.f;
}
internal->oldValue = NAN;
}


} // namespace app
} // namespace rack

Loading…
Cancel
Save