Skip to content

Commit 6e5bcfe

Browse files
committed
Chord Control Bar reworked
1 parent 75d5fa6 commit 6e5bcfe

3 files changed

Lines changed: 61 additions & 48 deletions

File tree

Applications/Note/ChordEffect.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,21 @@ void ChordEffect::SetEnabled(bool state) {
139139
}
140140
}
141141

142+
void ChordEffect::ClearChord() {
143+
chordCombo = {
144+
.dim = false,
145+
.min = false,
146+
.maj = false,
147+
.sus = false,
148+
.ext6 = false,
149+
.extMin7 = false,
150+
.extMaj7 = false,
151+
.ext9 = false
152+
};
153+
chordChanged = true;
154+
}
155+
156+
142157
void ChordEffect::SetChordCombo(ChordCombo combo) {
143158
if (chordCombo != combo) {
144159
chordCombo = combo;

Applications/Note/ChordEffect.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class ChordEffect : public MidiEffect {
5353
void Tick(deque<MidiPacket>& input, deque<MidiPacket>& output) override;
5454
void Reset() override;
5555
void SetEnabled(bool state) override;
56+
void ClearChord();
5657
void SetChordCombo(ChordCombo combo);
5758
void ReleaseAllChords(deque<MidiPacket>& output);
5859
void UpdateChords(deque<MidiPacket>& output);

Applications/Note/NoteControlBar.cpp

Lines changed: 45 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -240,27 +240,14 @@ bool NoteControlBar::ChordControlKeyEvent(Point xy, KeyInfo* keyInfo) {
240240

241241
// Section 1: Top left 4 buttons (CTL_BAR_Y - 3, x0-x3) - Basic chord types
242242
if (xy.y == CTL_BAR_Y - 3 && xy.x <= 3) {
243-
ChordCombo combo = notePad[0]->rt->chordEffect.chordCombo;
244-
245243
if (keyInfo->State() == PRESSED) {
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
244+
if(ShiftActive())
245+
{
246+
notePad[0]->rt->chordEffect.ClearChord();
247+
}
248+
else
249+
{
250+
ChordCombo combo = notePad[0]->rt->chordEffect.chordCombo;
264251
combo.dim = false;
265252
combo.min = false;
266253
combo.maj = false;
@@ -272,40 +259,30 @@ bool NoteControlBar::ChordControlKeyEvent(Point xy, KeyInfo* keyInfo) {
272259
case 2: combo.maj = true; break;
273260
case 3: combo.sus = true; break;
274261
}
262+
notePad[0]->rt->chordEffect.SetChordCombo(combo);
275263
}
276-
} else {
277-
return true;
278264
}
279265

280-
notePad[0]->rt->chordEffect.SetChordCombo(combo);
281266
return true;
282267
}
283268

284269
// Section 2: Bottom left 4 buttons (CTL_BAR_Y - 2, x0-x3) - Extensions
285270
if (xy.y == CTL_BAR_Y - 2 && xy.x <= 3) {
286-
ChordCombo combo = notePad[0]->rt->chordEffect.chordCombo;
287-
288271
if (keyInfo->State() == PRESSED) {
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;
308-
} else {
272+
if(ShiftActive())
273+
{
274+
notePad[0]->rt->chordEffect.ClearChord();
275+
}
276+
else
277+
{
278+
ChordCombo combo = notePad[0]->rt->chordEffect.chordCombo;
279+
280+
// Check if any extension key is already pressed
281+
bool anyKeyPressed = chordExtKeyOn[0] || chordExtKeyOn[1] || chordExtKeyOn[2] || chordExtKeyOn[3];
282+
283+
// Count how many extensions are currently on
284+
int extCount = (combo.ext6 ? 1 : 0) + (combo.extMin7 ? 1 : 0) + (combo.extMaj7 ? 1 : 0) + (combo.ext9 ? 1 : 0);
285+
309286
// If no keys are pressed, clear all extensions before setting the new one
310287
if (!anyKeyPressed) {
311288
combo.ext6 = false;
@@ -321,19 +298,26 @@ bool NoteControlBar::ChordControlKeyEvent(Point xy, KeyInfo* keyInfo) {
321298
case 2: combo.extMaj7 = true; chordExtKeyOn[2] = true; break;
322299
case 3: combo.ext9 = true; chordExtKeyOn[3] = true; break;
323300
}
301+
notePad[0]->rt->chordEffect.SetChordCombo(combo);
324302
}
325303
} else if (keyInfo->State() == RELEASED) {
326304
// Clear the pressed flag but don't turn off the extension
327305
chordExtKeyOn[xy.x] = false;
328306
} else {
329307
return true;
330308
}
309+
return true;
310+
}
331311

332-
notePad[0]->rt->chordEffect.SetChordCombo(combo);
312+
313+
// Section 3: Chord Clear Button
314+
if (xy.x == 7 && xy.y == (CTL_BAR_Y - 2) && keyInfo->State() == PRESSED) {
315+
notePad[0]->rt->chordEffect.ClearChord();
333316
return true;
334317
}
335318

336-
// Section 3: Right 8 buttons (x4-x7 on both rows) - Inversion controls (0-7)
319+
320+
// Section 4: Right 8 buttons (x4-x7 on both rows) - Inversion controls (0-7)
337321
if (xy.x >= 4 && xy.x <= 7 && keyInfo->State() == PRESSED) {
338322
uint8_t inversion;
339323
if (xy.y == CTL_BAR_Y - 3) {
@@ -506,6 +490,7 @@ void NoteControlBar::RenderChordControl(Point origin) {
506490
Color baseColor = Color(0xFF00FF);
507491
Color extColor = Color(0x00FFFF);
508492
Color inversionColor = Color(0xFFFF00);
493+
Color clearColor = Color(0xFF0000);
509494

510495
// Row 0
511496
// x0: Dim, x1: min, x2: maj, x3: sus
@@ -531,7 +516,19 @@ void NoteControlBar::RenderChordControl(Point origin) {
531516
MatrixOS::LED::SetColor(origin + Point(4, CTL_BAR_Y - 2), inversionColor.DimIfNot(currentInversion >= 4));
532517
MatrixOS::LED::SetColor(origin + Point(5, CTL_BAR_Y - 2), inversionColor.DimIfNot(currentInversion >= 5));
533518
MatrixOS::LED::SetColor(origin + Point(6, CTL_BAR_Y - 2), inversionColor.DimIfNot(currentInversion >= 6));
534-
MatrixOS::LED::SetColor(origin + Point(7, CTL_BAR_Y - 2), inversionColor.DimIfNot(currentInversion >= 7));
519+
520+
// Clear Button
521+
bool chordOn =
522+
notePad[0]->rt->chordEffect.chordCombo.dim ||
523+
notePad[0]->rt->chordEffect.chordCombo.min ||
524+
notePad[0]->rt->chordEffect.chordCombo.maj ||
525+
notePad[0]->rt->chordEffect.chordCombo.sus ||
526+
notePad[0]->rt->chordEffect.chordCombo.ext6 ||
527+
notePad[0]->rt->chordEffect.chordCombo.extMin7 ||
528+
notePad[0]->rt->chordEffect.chordCombo.extMaj7 ||
529+
notePad[0]->rt->chordEffect.chordCombo.ext9;
530+
531+
MatrixOS::LED::SetColor(origin + Point(7, CTL_BAR_Y - 2), clearColor.DimIfNot(chordOn));
535532
}
536533

537534
void NoteControlBar::RenderArpControl(Point origin) {

0 commit comments

Comments
 (0)