Skip to content

Commit

Permalink
Fix latched velocity and modwheel when changing sidebar column mode (S…
Browse files Browse the repository at this point in the history
…ynthstromAudible#2116)

* Fix latched velocity and modwheel when changing sidebar column mode

* Remove the logic to preserve the presses of the previous column when switching columns, and instead reset back to prev pad in the moment of switching

# Conflicts:
#	src/deluge/gui/ui/keyboard/layout/column_controls.h
  • Loading branch information
soymonitus committed Jun 12, 2024
1 parent a7331a7 commit 548f470
Show file tree
Hide file tree
Showing 16 changed files with 64 additions and 27 deletions.
6 changes: 6 additions & 0 deletions src/deluge/gui/ui/keyboard/column_controls/chord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ bool ChordColumn::handleVerticalEncoder(int8_t pad, int32_t offset) {
return false;
};

void ChordColumn::handleLeavingColumn(ModelStackWithTimelineCounter* modelStackWithTimelineCounter,
KeyboardLayout* layout) {
// Restore previously set chord
setActiveChord(defaultChord);
};

void ChordColumn::handlePad(ModelStackWithTimelineCounter* modelStackWithTimelineCounter, PressedPad pad,
KeyboardLayout* layout) {
if (pad.active) {
Expand Down
2 changes: 2 additions & 0 deletions src/deluge/gui/ui/keyboard/column_controls/chord.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class ChordColumn : public ControlColumn {

void renderColumn(RGB image[][kDisplayWidth + kSideBarWidth], int32_t column) override;
bool handleVerticalEncoder(int8_t pad, int32_t offset) override;
void handleLeavingColumn(ModelStackWithTimelineCounter* modelStackWithTimelineCounter,
KeyboardLayout* layout) override;
void handlePad(ModelStackWithTimelineCounter* modelStackWithTimelineCounter, PressedPad pad,
KeyboardLayout* layout) override;

Expand Down
3 changes: 3 additions & 0 deletions src/deluge/gui/ui/keyboard/column_controls/chord_mem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ bool ChordMemColumn::handleVerticalEncoder(int8_t pad, int32_t offset) {
return false;
};

void ChordMemColumn::handleLeavingColumn(ModelStackWithTimelineCounter* modelStackWithTimelineCounter,
KeyboardLayout* layout){};

void ChordMemColumn::handlePad(ModelStackWithTimelineCounter* modelStackWithTimelineCounter, PressedPad pad,
KeyboardLayout* layout) {
NotesState& currentNotesState = layout->getNotesState();
Expand Down
2 changes: 2 additions & 0 deletions src/deluge/gui/ui/keyboard/column_controls/chord_mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class ChordMemColumn : public ControlColumn {

void renderColumn(RGB image[][kDisplayWidth + kSideBarWidth], int32_t column) override;
bool handleVerticalEncoder(int8_t pad, int32_t offset) override;
void handleLeavingColumn(ModelStackWithTimelineCounter* modelStackWithTimelineCounter,
KeyboardLayout* layout) override;
void handlePad(ModelStackWithTimelineCounter* modelStackWithTimelineCounter, PressedPad pad,
KeyboardLayout* layout) override;

Expand Down
2 changes: 2 additions & 0 deletions src/deluge/gui/ui/keyboard/column_controls/control_column.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class ControlColumn {
public:
virtual void renderColumn(RGB image[][kDisplayWidth + kSideBarWidth], int32_t column) = 0;
virtual bool handleVerticalEncoder(int8_t pad, int32_t offset) = 0;
virtual void handleLeavingColumn(ModelStackWithTimelineCounter* modelStackWithTimelineCounter,
KeyboardLayout* layout) = 0;
virtual void handlePad(ModelStackWithTimelineCounter* modelStackWithTimelineCounter, PressedPad pad,
KeyboardLayout* layout) = 0;
};
Expand Down
3 changes: 3 additions & 0 deletions src/deluge/gui/ui/keyboard/column_controls/dx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ bool DXColumn::handleVerticalEncoder(int8_t pad, int32_t offset) {
return false;
};

void DXColumn::handleLeavingColumn(ModelStackWithTimelineCounter* modelStackWithTimelineCounter,
KeyboardLayout* layout){};

void DXColumn::handlePad(ModelStackWithTimelineCounter* modelStackWithTimelineCounter, PressedPad pad,
KeyboardLayout* layout) {
DxPatch* patch = getCurrentDxPatch();
Expand Down
2 changes: 2 additions & 0 deletions src/deluge/gui/ui/keyboard/column_controls/dx.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class DXColumn : public ControlColumn {

void renderColumn(RGB image[][kDisplayWidth + kSideBarWidth], int32_t column) override;
bool handleVerticalEncoder(int8_t pad, int32_t offset) override;
void handleLeavingColumn(ModelStackWithTimelineCounter* modelStackWithTimelineCounter,
KeyboardLayout* layout) override;
void handlePad(ModelStackWithTimelineCounter* modelStackWithTimelineCounter, PressedPad pad,
KeyboardLayout* layout) override;

Expand Down
7 changes: 7 additions & 0 deletions src/deluge/gui/ui/keyboard/column_controls/mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ bool ModColumn::handleVerticalEncoder(int8_t pad, int32_t offset) {
return false;
};

void ModColumn::handleLeavingColumn(ModelStackWithTimelineCounter* modelStackWithTimelineCounter,
KeyboardLayout* layout) {
// Restore previously set Modwheel
modDisplay = mod32;
getCurrentInstrument()->processParamFromInputMIDIChannel(CC_NUMBER_Y_AXIS, mod32, modelStackWithTimelineCounter);
};

void ModColumn::handlePad(ModelStackWithTimelineCounter* modelStackWithTimelineCounter, PressedPad pad,
KeyboardLayout* layout) {

Expand Down
2 changes: 2 additions & 0 deletions src/deluge/gui/ui/keyboard/column_controls/mod.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class ModColumn : public ControlColumn {

void renderColumn(RGB image[][kDisplayWidth + kSideBarWidth], int32_t column) override;
bool handleVerticalEncoder(int8_t pad, int32_t offset) override;
void handleLeavingColumn(ModelStackWithTimelineCounter* modelStackWithTimelineCounter,
KeyboardLayout* layout) override;
void handlePad(ModelStackWithTimelineCounter* modelStackWithTimelineCounter, PressedPad pad,
KeyboardLayout* layout) override;

Expand Down
13 changes: 13 additions & 0 deletions src/deluge/gui/ui/keyboard/column_controls/scale_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ bool ScaleModeColumn::handleVerticalEncoder(int8_t pad, int32_t offset) {
return true;
};

void ScaleModeColumn::handleLeavingColumn(ModelStackWithTimelineCounter* modelStackWithTimelineCounter,
KeyboardLayout* layout) {
// Restore previously set scale
if (keyboardScreen.setScale(previousScale)) {
for (int32_t y = 0; y < kDisplayHeight; ++y) {
if (scaleModes[y] == previousScale) {
currentScalePad = y;
break;
}
}
}
};

void ScaleModeColumn::handlePad(ModelStackWithTimelineCounter* modelStackWithTimelineCounter, PressedPad pad,
KeyboardLayout* layout) {
if (pad.active) {
Expand Down
2 changes: 2 additions & 0 deletions src/deluge/gui/ui/keyboard/column_controls/scale_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class ScaleModeColumn : public ControlColumn {

void renderColumn(RGB image[][kDisplayWidth + kSideBarWidth], int32_t column) override;
bool handleVerticalEncoder(int8_t pad, int32_t offset) override;
void handleLeavingColumn(ModelStackWithTimelineCounter* modelStackWithTimelineCounter,
KeyboardLayout* layout) override;
void handlePad(ModelStackWithTimelineCounter* modelStackWithTimelineCounter, PressedPad pad,
KeyboardLayout* layout) override;

Expand Down
7 changes: 7 additions & 0 deletions src/deluge/gui/ui/keyboard/column_controls/velocity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ bool VelocityColumn::handleVerticalEncoder(int8_t pad, int32_t offset) {
return false;
};

void VelocityColumn::handleLeavingColumn(ModelStackWithTimelineCounter* modelStackWithTimelineCounter,
KeyboardLayout* layout) {
// Restore previously set Velocity
vDisplay = velocity32;
layout->velocity = (velocity32 + kHalfStep) >> kVelModShift;
};

void VelocityColumn::handlePad(ModelStackWithTimelineCounter* modelStackWithTimelineCounter, PressedPad pad,
KeyboardLayout* layout) {
if (pad.active) {
Expand Down
2 changes: 2 additions & 0 deletions src/deluge/gui/ui/keyboard/column_controls/velocity.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class VelocityColumn : public ControlColumn {

void renderColumn(RGB image[][kDisplayWidth + kSideBarWidth], int32_t column) override;
bool handleVerticalEncoder(int8_t pad, int32_t offset) override;
void handleLeavingColumn(ModelStackWithTimelineCounter* modelStackWithTimelineCounter,
KeyboardLayout* layout) override;
void handlePad(ModelStackWithTimelineCounter* modelStackWithTimelineCounter, PressedPad pad,
KeyboardLayout* layout) override;

Expand Down
28 changes: 8 additions & 20 deletions src/deluge/gui/ui/keyboard/layout/column_controls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,15 @@ void ColumnControlsKeyboard::evaluatePads(PressedPad presses[kMaxNumKeyboardPadP
if (pressed.active) {
leftColHeld = pressed.y;
}
else if (horizontalScrollingLeftCol && pressed.y == 7) {
leftColPrev->handlePad(modelStackWithTimelineCounter, pressed, this);
horizontalScrollingLeftCol = false;
continue;
}
if (!horizontalScrollingLeftCol && !pressed.dead) {
if (!pressed.dead) {
leftCol->handlePad(modelStackWithTimelineCounter, pressed, this);
}
}
else if (pressed.x == RIGHT_COL) {
if (pressed.active) {
rightColHeld = pressed.y;
}
else if (horizontalScrollingRightCol && pressed.y == 7) {
rightColPrev->handlePad(modelStackWithTimelineCounter, pressed, this);
horizontalScrollingRightCol = false;
continue;
}
if (!horizontalScrollingRightCol && !pressed.dead) {
if (!pressed.dead) {
rightCol->handlePad(modelStackWithTimelineCounter, pressed, this);
}
}
Expand Down Expand Up @@ -192,22 +182,20 @@ ControlColumn* ColumnControlsKeyboard::getColumnForFunc(ColumnControlFunction fu
}

bool ColumnControlsKeyboard::horizontalEncoderHandledByColumns(int32_t offset, bool shiftEnabled) {
char modelStackMemory[MODEL_STACK_MAX_SIZE];
ModelStack* modelStack = setupModelStackWithSong(modelStackMemory, currentSong);
ModelStackWithTimelineCounter* modelStackWithTimelineCounter = modelStack->addTimelineCounter(getCurrentClip());

if (leftColHeld == 7 && offset) {
if (!horizontalScrollingLeftCol) {
leftColPrev = leftCol;
}
horizontalScrollingLeftCol = true;
leftCol->handleLeavingColumn(modelStackWithTimelineCounter, this);
leftColFunc = (offset > 0) ? nextControlFunction(leftColFunc, rightColFunc)
: prevControlFunction(leftColFunc, rightColFunc);
display->displayPopup(functionNames[leftColFunc]);
leftCol = getColumnForFunc(leftColFunc);
return true;
}
else if (rightColHeld == 7 && offset) {
if (!horizontalScrollingRightCol) {
rightColPrev = rightCol;
}
horizontalScrollingRightCol = true;
rightCol->handleLeavingColumn(modelStackWithTimelineCounter, this);
rightColFunc = (offset > 0) ? nextControlFunction(rightColFunc, leftColFunc)
: prevControlFunction(rightColFunc, leftColFunc);
display->displayPopup(functionNames[rightColFunc]);
Expand Down
4 changes: 0 additions & 4 deletions src/deluge/gui/ui/keyboard/layout/column_controls.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,11 @@ class ColumnControlsKeyboard : public KeyboardLayout {
ColumnControlFunction leftColFunc = VELOCITY;
ColumnControlFunction rightColFunc = MOD;
bool rightColSetAtRuntime = false;
ControlColumn* leftColPrev = &velocityColumn;
ControlColumn* rightColPrev = &modColumn;
ControlColumn* leftCol = &velocityColumn;
ControlColumn* rightCol = &modColumn;

ControlColumn* getColumnForFunc(ColumnControlFunction func);

bool horizontalScrollingLeftCol = false;
bool horizontalScrollingRightCol = false;
int8_t leftColHeld = -1;
int8_t rightColHeld = -1;
};
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/value_scaling_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ TEST(ValueScalingTest, arpMidiCvGateValueScaling) {
int32_t currentValue = computeCurrentValueForArpMidiCvGate(finalValue);
CHECK_EQUAL(i, currentValue);
}
CHECK_EQUAL(INT32_MIN, computeFinalValueForArpMidiCvGate(0));
CHECK_EQUAL(-23, computeFinalValueForArpMidiCvGate(25));
CHECK_EQUAL(INT32_MIN, computeFinalValueForArpMidiCvGate(0));
CHECK_EQUAL(-23, computeFinalValueForArpMidiCvGate(25));
// As seen here, we diverge _slightly_ from the standard
// menu item scaling when computing final values, despite roundtripping
// and using the identical current value computation.
//
// See computeFinalValueForArpMidiCvGate()'s comment for possible
// motivation.
CHECK_EQUAL(INT32_MAX-45, computeFinalValueForArpMidiCvGate(50));
CHECK_EQUAL(INT32_MAX - 45, computeFinalValueForArpMidiCvGate(50));
}

0 comments on commit 548f470

Please sign in to comment.