Skip to content

Commit

Permalink
Fix scale sidebar column UI inconsistencies (SynthstromAudible#2090)
Browse files Browse the repository at this point in the history
* Fix scale sidebar column UI inconsistencies

* Remove unneeded import
  • Loading branch information
soymonitus committed Jun 3, 2024
1 parent e7eed7c commit 0e096f8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
37 changes: 31 additions & 6 deletions src/deluge/gui/ui/keyboard/column_controls/scale_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ void ScaleModeColumn::renderColumn(RGB image[][kDisplayWidth + kSideBarWidth], i
uint8_t otherChannels = 0;
for (int32_t y = 0; y < kDisplayHeight; ++y) {
bool mode_selected = scaleModes[y] == currentScale;
if (currentScalePad == -1 && mode_selected) {
// fill currentScalePad with the current matching scale if not set yet
currentScalePad = y;
}
uint8_t mode_available = y < NUM_PRESET_SCALES ? 0x7f : 0;
otherChannels = mode_selected ? 0xf0 : 0;
uint8_t base = mode_selected ? 0xff : mode_available;
Expand All @@ -36,9 +40,23 @@ void ScaleModeColumn::renderColumn(RGB image[][kDisplayWidth + kSideBarWidth], i
}

bool ScaleModeColumn::handleVerticalEncoder(int8_t pad, int32_t offset) {
int32_t newScale = ((int32_t)scaleModes[pad] + offset) % NUM_PRESET_SCALES;
if (newScale < 0) {
newScale = NUM_PRESET_SCALES - 1;
int32_t newScale = scaleModes[pad];
bool newScaleNotSelectedYet = true;
while (newScaleNotSelectedYet) {
newScale = (newScale + offset) % NUM_PRESET_SCALES;
if (newScale < 0) {
newScale = NUM_PRESET_SCALES - 1;
}
bool scaleFoundInPads = false;
for (int32_t y = 0; y < kDisplayHeight; ++y) {
if (scaleModes[y] == newScale) {
scaleFoundInPads = true;
break;
}
}
if (!scaleFoundInPads) {
newScaleNotSelectedYet = false;
}
}
scaleModes[pad] = newScale;
return true;
Expand All @@ -47,21 +65,28 @@ bool ScaleModeColumn::handleVerticalEncoder(int8_t pad, int32_t offset) {
void ScaleModeColumn::handlePad(ModelStackWithTimelineCounter* modelStackWithTimelineCounter, PressedPad pad,
KeyboardLayout* layout) {
if (pad.active) {
previousScale = currentSong->getCurrentPresetScale();
if (keyboardScreen.setScale(scaleModes[pad.y])) {
currentScalePad = pad.y;
}
}
else if (!pad.padPressHeld) {
// Pad released after short press
if (keyboardScreen.setScale(scaleModes[pad.y])) {
previousScalePad = pad.y;
previousScale = scaleModes[pad.y];
currentScalePad = pad.y;
}
}
else {
// Pad released after long press
if (keyboardScreen.setScale(scaleModes[previousScalePad])) {
currentScalePad = previousScalePad;

if (keyboardScreen.setScale(previousScale)) {
for (int32_t y = 0; y < kDisplayHeight; ++y) {
if (scaleModes[y] == previousScale) {
currentScalePad = y;
break;
}
}
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/deluge/gui/ui/keyboard/column_controls/scale_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class ScaleModeColumn : public ControlColumn {
KeyboardLayout* layout) override;

private:
int32_t currentScalePad = currentSong->getCurrentPresetScale();
int32_t previousScalePad = currentSong->getCurrentPresetScale();
int32_t currentScalePad = -1;
int32_t previousScale = currentSong->getCurrentPresetScale();
uint8_t scaleModes[8] = {0, 1, 2, 3, 4, 5, 6, 7};
};

Expand Down

0 comments on commit 0e096f8

Please sign in to comment.