Scale editor

This commit is contained in:
Dejvino
2026-02-21 23:19:51 +01:00
parent 36d3fd2e80
commit 4a3f2b8eb2
3 changed files with 190 additions and 13 deletions
+79
View File
@@ -119,6 +119,85 @@ void UIManager::draw(UIState currentState, int menuSelection,
display.setCursor(0, 50);
display.println(F(" (Press to confirm)"));
break;
case UI_SCALE_EDIT:
case UI_SCALE_NOTE_EDIT:
case UI_SCALE_TRANSPOSE:
display.println(F("EDIT SCALE"));
display.drawLine(0, 8, 128, 8, SSD1306_WHITE);
int totalItems = numScaleNotes + 5; // Back + Randomize + Notes + Add + Remove + Transpose
int startIdx = 0;
if (menuSelection >= 4) startIdx = menuSelection - 3;
int y = 12;
for (int i = startIdx; i < totalItems; i++) {
if (y > 54) break;
if (i == menuSelection) {
display.fillRect(0, y, 75, 9, SSD1306_WHITE);
display.setTextColor(SSD1306_BLACK, SSD1306_WHITE);
} else {
display.setTextColor(SSD1306_WHITE);
}
display.setCursor(2, y + 1);
if (i == 0) {
display.print(F("Back"));
} else if (i == 1) {
display.print(F("Randomize"));
} else if (i <= numScaleNotes + 1) {
int noteIdx = i - 2;
const char* noteNames[] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"};
display.print(noteNames[scaleNotes[noteIdx]]);
if (currentState == UI_SCALE_NOTE_EDIT && i == menuSelection) {
display.print(F(" <"));
}
} else if (i == numScaleNotes + 2) {
display.print(F("Transpose"));
if (currentState == UI_SCALE_TRANSPOSE) {
display.print(F(" < >"));
}
} else if (i == numScaleNotes + 3) {
display.print(F("Add Note"));
} else if (i == numScaleNotes + 4) {
display.print(F("Remove Note"));
}
y += 9;
}
// Piano Roll Preview
int px = 82;
int py = 20;
int wk_w = 5;
int wk_h = 20;
int bk_w = 4;
int bk_h = 12;
// White keys: C, D, E, F, G, A, B
int whiteNotes[] = {0, 2, 4, 5, 7, 9, 11};
for (int k = 0; k < 7; k++) {
bool active = false;
for (int j = 0; j < numScaleNotes; j++) {
if (scaleNotes[j] == whiteNotes[k]) { active = true; break; }
}
if (active) display.fillRect(px + k*6, py, wk_w, wk_h, SSD1306_WHITE);
else display.drawRect(px + k*6, py, wk_w, wk_h, SSD1306_WHITE);
}
// Black keys: C#, D#, F#, G#, A#
int blackNotes[] = {1, 3, 6, 8, 10};
int blackOffsets[] = {3, 9, 21, 27, 33};
for (int k = 0; k < 5; k++) {
bool active = false;
for (int j = 0; j < numScaleNotes; j++) {
if (scaleNotes[j] == blackNotes[k]) { active = true; break; }
}
int bx = px + blackOffsets[k];
display.fillRect(bx - 1, py - 1, bk_w + 2, bk_h + 2, SSD1306_BLACK);
if (active) display.fillRect(bx, py, bk_w, bk_h, SSD1306_WHITE);
else display.drawRect(bx, py, bk_w, bk_h, SSD1306_WHITE);
}
break;
}
display.display();
}