Skip to content

Commit ccc380b

Browse files
committed
Better chord control
1 parent 8493a69 commit ccc380b

2 files changed

Lines changed: 61 additions & 49 deletions

File tree

Applications/Note/NoteControlBar.cpp

Lines changed: 60 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -142,21 +142,12 @@ bool NoteControlBar::KeyEvent(Point xy, KeyInfo* keyInfo) {
142142
// Chord Mode
143143
else if(xy == Point(3, CTL_BAR_Y - 1)) {
144144
if(keyInfo->State() == PRESSED) {
145-
if(ShiftActive()) {
146-
// Shift click: Toggle the toggle mode (turn on chord mode if off)
147-
if(mode != CHORD_MODE) {
148-
mode = CHORD_MODE;
149-
}
150-
chordToggleMode = !chordToggleMode;
151-
ShiftEventOccured();
152-
}
153-
else if(mode == CHORD_MODE) {
145+
if(mode == CHORD_MODE) {
154146
// Already on: turn off
155147
mode = OFF_MODE;
156148
} else {
157149
// Off: turn on without toggle mode
158150
mode = CHORD_MODE;
159-
chordToggleMode = false;
160151
}
161152
}
162153
return true;
@@ -252,32 +243,36 @@ bool NoteControlBar::ChordControlKeyEvent(Point xy, KeyInfo* keyInfo) {
252243
ChordCombo combo = notePad[0]->rt->chordEffect.chordCombo;
253244

254245
if (keyInfo->State() == PRESSED) {
255-
bool chordTypes[4] = {combo.dim, combo.min, combo.maj, combo.sus};
256-
bool wasActive = chordTypes[xy.x];
257-
258-
// Clear all basic chord types
259-
combo.dim = false;
260-
combo.min = false;
261-
combo.maj = false;
262-
combo.sus = false;
263-
264-
// In toggle mode, only set if wasn't already active
265-
// In momentary mode, always set
266-
if (!chordToggleMode || !wasActive) {
246+
// Count how many chord types are currently on
247+
int typeCount = (combo.dim ? 1 : 0) + (combo.min ? 1 : 0) + (combo.maj ? 1 : 0) + (combo.sus ? 1 : 0);
248+
249+
// Check which chord type is currently active
250+
int activeChord = -1;
251+
if (combo.dim) activeChord = 0;
252+
else if (combo.min) activeChord = 1;
253+
else if (combo.maj) activeChord = 2;
254+
else if (combo.sus) activeChord = 3;
255+
256+
// If tapping the exact chord that's currently the only one on, disable it
257+
if (typeCount == 1 && activeChord == xy.x) {
258+
combo.dim = false;
259+
combo.min = false;
260+
combo.maj = false;
261+
combo.sus = false;
262+
} else {
263+
// Otherwise, clear all and set the new one
264+
combo.dim = false;
265+
combo.min = false;
266+
combo.maj = false;
267+
combo.sus = false;
268+
267269
switch(xy.x) {
268270
case 0: combo.dim = true; break;
269271
case 1: combo.min = true; break;
270272
case 2: combo.maj = true; break;
271273
case 3: combo.sus = true; break;
272274
}
273275
}
274-
} else if (keyInfo->State() == RELEASED && !ShiftActive() && !chordToggleMode) {
275-
switch(xy.x) {
276-
case 0: combo.dim = false; break;
277-
case 1: combo.min = false; break;
278-
case 2: combo.maj = false; break;
279-
case 3: combo.sus = false; break;
280-
}
281276
} else {
282277
return true;
283278
}
@@ -291,28 +286,45 @@ bool NoteControlBar::ChordControlKeyEvent(Point xy, KeyInfo* keyInfo) {
291286
ChordCombo combo = notePad[0]->rt->chordEffect.chordCombo;
292287

293288
if (keyInfo->State() == PRESSED) {
294-
if (chordToggleMode) {
295-
switch(xy.x) {
296-
case 0: combo.ext6 = !combo.ext6; break;
297-
case 1: combo.extMin7 = !combo.extMin7; break;
298-
case 2: combo.extMaj7 = !combo.extMaj7; break;
299-
case 3: combo.ext9 = !combo.ext9; break;
300-
}
289+
// Check if any extension key is already pressed
290+
bool anyKeyPressed = chordExtKeyOn[0] || chordExtKeyOn[1] || chordExtKeyOn[2] || chordExtKeyOn[3];
291+
292+
// Count how many extensions are currently on
293+
int extCount = (combo.ext6 ? 1 : 0) + (combo.extMin7 ? 1 : 0) + (combo.extMaj7 ? 1 : 0) + (combo.ext9 ? 1 : 0);
294+
295+
// Check which extension is currently active
296+
int activeExt = -1;
297+
if (combo.ext6) activeExt = 0;
298+
else if (combo.extMin7) activeExt = 1;
299+
else if (combo.extMaj7) activeExt = 2;
300+
else if (combo.ext9) activeExt = 3;
301+
302+
// If tapping the exact extension that's currently the only one on, disable it
303+
if (extCount == 1 && activeExt == xy.x) {
304+
combo.ext6 = false;
305+
combo.extMin7 = false;
306+
combo.extMaj7 = false;
307+
combo.ext9 = false;
301308
} else {
309+
// If no keys are pressed, clear all extensions before setting the new one
310+
if (!anyKeyPressed) {
311+
combo.ext6 = false;
312+
combo.extMin7 = false;
313+
combo.extMaj7 = false;
314+
combo.ext9 = false;
315+
}
316+
317+
// Set the pressed key's extension and mark it as pressed
302318
switch(xy.x) {
303-
case 0: combo.ext6 = true; break;
304-
case 1: combo.extMin7 = true; break;
305-
case 2: combo.extMaj7 = true; break;
306-
case 3: combo.ext9 = true; break;
319+
case 0: combo.ext6 = true; chordExtKeyOn[0] = true; break;
320+
case 1: combo.extMin7 = true; chordExtKeyOn[1] = true; break;
321+
case 2: combo.extMaj7 = true; chordExtKeyOn[2] = true; break;
322+
case 3: combo.ext9 = true; chordExtKeyOn[3] = true; break;
307323
}
308324
}
309-
} else if (keyInfo->State() == RELEASED && !ShiftActive() && !chordToggleMode) {
310-
switch(xy.x) {
311-
case 0: combo.ext6 = false; break;
312-
case 1: combo.extMin7 = false; break;
313-
case 2: combo.extMaj7 = false; break;
314-
case 3: combo.ext9 = false; break;
315-
}
325+
} else if (keyInfo->State() == RELEASED) {
326+
// Clear the pressed flag but don't turn off the extension
327+
chordExtKeyOn[xy.x] = false;
316328
} else {
317329
return true;
318330
}
@@ -459,7 +471,7 @@ bool NoteControlBar::Render(Point origin) {
459471

460472
Color chordColor;
461473
if(mode == CHORD_MODE) {
462-
chordColor = chordToggleMode ? Color(0x6060FF) : Color::White;
474+
chordColor = Color::White;
463475
} else {
464476
chordColor = Color(0x00FFFF);
465477
}

Applications/Note/NoteControlBar.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ class NoteControlBar : public UIComponent {
2424
bool shift_event[2];
2525
static const uint32_t hold_threshold = 500; // Define hold threshold
2626
NoteControlBarMode mode = OFF_MODE;
27-
bool chordToggleMode = false;
2827
bool keyOffsetMode = false;
2928
uint32_t pitch_down = 0;
3029
uint32_t pitch_up = 0;
30+
bool chordExtKeyOn[4] = {false, false, false, false}; // Track which extension keys are pressed
3131

3232
void SwapActiveConfig();
3333
bool ShiftActive();

0 commit comments

Comments
 (0)