menu redesign: hierarchical entries

This commit is contained in:
Dejvino 2026-02-19 11:10:09 +01:00
parent 8ae1f5f501
commit d70e30d76f
6 changed files with 185 additions and 143 deletions

View File

@ -12,18 +12,42 @@ Step nextSequence[NUM_TRACKS][NUM_STEPS];
volatile bool sequenceChangeScheduled = false; volatile bool sequenceChangeScheduled = false;
volatile bool needsPanic = false; volatile bool needsPanic = false;
UIState currentState = UI_MENU_RANDOMIZE; UIState currentState = UI_MENU_MAIN;
// Menus // Menus
const char* mainMenu[] = { "Randomize", "Setup" }; MenuItem menuItems[] = {
extern const int mainMenuCount = sizeof(mainMenu) / sizeof(char*); { "Main", MENU_ID_GROUP_MAIN, true, true, 0 },
{ "Melody", MENU_ID_MELODY, false, false, 1 },
{ "Scale", MENU_ID_SCALE, false, false, 1 },
{ "Tempo", MENU_ID_TEMPO, false, false, 1 },
{ "Song Mode", MENU_ID_SONG_MODE, false, false, 1 },
{ "Track", MENU_ID_GROUP_TRACK, true, true, 0 },
{ "Track", MENU_ID_TRACK_SELECT, false, false, 1 },
{ "Mute", MENU_ID_MUTE, false, false, 1 },
{ "Flavour", MENU_ID_FLAVOUR, false, false, 1 },
{ "Mutation", MENU_ID_MUTATION, false, false, 1 },
{ "Theme 1", MENU_ID_THEME_1, false, false, 1 },
{ "Theme 2", MENU_ID_THEME_2, false, false, 1 },
{ "Theme 3", MENU_ID_THEME_3, false, false, 1 },
{ "Theme 4", MENU_ID_THEME_4, false, false, 1 },
{ "Theme 5", MENU_ID_THEME_5, false, false, 1 },
{ "Theme 6", MENU_ID_THEME_6, false, false, 1 },
{ "Theme 7", MENU_ID_THEME_7, false, false, 1 },
{ "Setup", MENU_ID_GROUP_SETUP, true, false, 0 },
{ "Channel", MENU_ID_CHANNEL, false, false, 1 },
{ "Reset", MENU_ID_RESET, false, false, 1 }
};
extern const int menuItemsCount = sizeof(menuItems) / sizeof(MenuItem);
const char* randomizeMenuPoly[] = { "Setup", "Melody", "Scale", "Tempo", "Song Mode", "Track", "Mute", "Flavour", "Mutation", "Theme 1", "Theme 2", "Theme 3", "Theme 4", "Theme 5", "Theme 6", "Theme 7" }; bool isItemVisible(int index) {
extern const int randomizeMenuPolyCount = sizeof(randomizeMenuPoly) / sizeof(char*); if (menuItems[index].indentLevel == 0) return true;
extern const int THEME_1_INDEX_POLY = 9; for (int i = index - 1; i >= 0; i--) {
if (menuItems[i].indentLevel < menuItems[index].indentLevel) {
const char* setupMenu[] = { "Back", "Channel", "Factory Reset" }; return menuItems[i].expanded;
extern const int setupMenuCount = sizeof(setupMenu) / sizeof(char*); }
}
return true;
}
int menuSelection = 0; int menuSelection = 0;
volatile bool trackMute[NUM_TRACKS]; volatile bool trackMute[NUM_TRACKS];

View File

@ -14,13 +14,42 @@ extern volatile bool needsPanic;
extern UIState currentState; extern UIState currentState;
// Menus // Menus
extern const char* mainMenu[]; enum MenuItemID {
extern const int mainMenuCount; MENU_ID_GROUP_MAIN,
extern const char* randomizeMenuPoly[]; MENU_ID_MELODY,
extern const int randomizeMenuPolyCount; MENU_ID_SCALE,
extern const int THEME_1_INDEX_POLY; MENU_ID_TEMPO,
extern const char* setupMenu[]; MENU_ID_SONG_MODE,
extern const int setupMenuCount;
MENU_ID_GROUP_TRACK,
MENU_ID_TRACK_SELECT,
MENU_ID_MUTE,
MENU_ID_FLAVOUR,
MENU_ID_MUTATION,
MENU_ID_THEME_1,
MENU_ID_THEME_2,
MENU_ID_THEME_3,
MENU_ID_THEME_4,
MENU_ID_THEME_5,
MENU_ID_THEME_6,
MENU_ID_THEME_7,
MENU_ID_GROUP_SETUP,
MENU_ID_CHANNEL,
MENU_ID_RESET
};
struct MenuItem {
const char* label;
MenuItemID id;
bool isGroup;
bool expanded;
int indentLevel;
};
extern MenuItem menuItems[];
extern const int menuItemsCount;
bool isItemVisible(int index);
extern int menuSelection; extern int menuSelection;
extern volatile bool trackMute[NUM_TRACKS]; extern volatile bool trackMute[NUM_TRACKS];

View File

@ -17,8 +17,6 @@ enum PlayMode {
enum UIState { enum UIState {
UI_MENU_MAIN, UI_MENU_MAIN,
UI_MENU_RANDOMIZE,
UI_MENU_SETUP,
UI_SETUP_CHANNEL_EDIT, UI_SETUP_CHANNEL_EDIT,
UI_EDIT_TEMPO, UI_EDIT_TEMPO,
UI_EDIT_FLAVOUR, UI_EDIT_FLAVOUR,

View File

@ -1,5 +1,6 @@
#include "UIManager.h" #include "UIManager.h"
#include "config.h" #include "config.h"
#include "SharedState.h"
// --- HARDWARE CONFIGURATION --- // --- HARDWARE CONFIGURATION ---
#define SCREEN_WIDTH 128 #define SCREEN_WIDTH 128
@ -51,10 +52,7 @@ void UIManager::draw(UIState currentState, int menuSelection,
int numScaleNotes, const int* scaleNotes, int melodySeed, int numScaleNotes, const int* scaleNotes, int melodySeed,
bool mutationEnabled, bool songModeEnabled, bool mutationEnabled, bool songModeEnabled,
const Step sequence[][NUM_STEPS], int playbackStep, bool isPlaying, const Step sequence[][NUM_STEPS], int playbackStep, bool isPlaying,
const char* mainMenu[], int mainMenuCount, int randomizeTrack, const bool* trackMute) {
const char* randomizeMenu[], int randomizeMenuCount,
const char* setupMenu[], int setupMenuCount, int theme1Index,
PlayMode playMode, int randomizeTrack, const bool* trackMute) {
display.clearDisplay(); display.clearDisplay();
display.setTextSize(1); display.setTextSize(1);
@ -63,20 +61,7 @@ void UIManager::draw(UIState currentState, int menuSelection,
switch(currentState) { switch(currentState) {
case UI_MENU_MAIN: case UI_MENU_MAIN:
drawMenu("MAIN MENU", mainMenu, mainMenuCount, menuSelection, currentState, midiChannel, tempo, currentStrategy->getName(), queuedTheme, currentThemeIndex, numScaleNotes, scaleNotes, melodySeed, mutationEnabled, songModeEnabled, theme1Index, playMode, randomizeTrack, trackMute); drawMenu(menuSelection, currentState, midiChannel, tempo, currentStrategy->getName(), queuedTheme, currentThemeIndex, numScaleNotes, scaleNotes, melodySeed, mutationEnabled, songModeEnabled, randomizeTrack, trackMute);
break;
case UI_MENU_RANDOMIZE:
{
const char* title = "TRACK";
// Main section items: Setup(0), Melody(1), Scale(2), Tempo(3), Song Mode(4)
if (menuSelection <= 4) {
title = "MAIN";
}
drawMenu(title, randomizeMenu, randomizeMenuCount, menuSelection, currentState, midiChannel, tempo, currentStrategy->getName(), queuedTheme, currentThemeIndex, numScaleNotes, scaleNotes, melodySeed, mutationEnabled, songModeEnabled, theme1Index, playMode, randomizeTrack, trackMute);
}
break;
case UI_MENU_SETUP:
drawMenu("SETUP", setupMenu, setupMenuCount, menuSelection, currentState, midiChannel, tempo, currentStrategy->getName(), queuedTheme, currentThemeIndex, numScaleNotes, scaleNotes, melodySeed, mutationEnabled, songModeEnabled, theme1Index, playMode, randomizeTrack, trackMute);
break; break;
case UI_SETUP_CHANNEL_EDIT: case UI_SETUP_CHANNEL_EDIT:
display.println(F("SET MIDI CHANNEL")); display.println(F("SET MIDI CHANNEL"));
@ -111,16 +96,6 @@ void UIManager::draw(UIState currentState, int menuSelection,
display.setCursor(0, 50); display.setCursor(0, 50);
display.println(F(" (Press to confirm)")); display.println(F(" (Press to confirm)"));
break; break;
case UI_SETUP_PLAYMODE_EDIT:
display.println(F("SET PLAY MODE"));
display.drawLine(0, 8, 128, 8, SSD1306_WHITE);
display.setCursor(20, 25);
display.setTextSize(2);
display.print(playMode == MODE_MONO ? "Mono" : "Poly");
display.setTextSize(1);
display.setCursor(0, 50);
display.println(F(" (Press to confirm)"));
break;
case UI_RANDOMIZE_TRACK_EDIT: case UI_RANDOMIZE_TRACK_EDIT:
display.println(F("SET TRACK")); display.println(F("SET TRACK"));
display.drawLine(0, 8, 128, 8, SSD1306_WHITE); display.drawLine(0, 8, 128, 8, SSD1306_WHITE);
@ -136,43 +111,58 @@ void UIManager::draw(UIState currentState, int menuSelection,
display.display(); display.display();
} }
void UIManager::drawMenu(const char* title, const char* items[], int count, int selection, void UIManager::drawMenu(int selection, UIState currentState, int midiChannel, int tempo, const char* flavourName,
UIState currentState, int midiChannel, int tempo, const char* flavourName,
int queuedTheme, int currentThemeIndex, int numScaleNotes, int queuedTheme, int currentThemeIndex, int numScaleNotes,
const int* scaleNotes, int melodySeed, bool mutationEnabled, const int* scaleNotes, int melodySeed, bool mutationEnabled,
bool songModeEnabled, int theme1Index, PlayMode playMode, int randomizeTrack, const bool* trackMute) { bool songModeEnabled, int randomizeTrack, const bool* trackMute) {
display.println(title);
display.drawLine(0, 8, 128, 8, SSD1306_WHITE);
int start = 0; // Calculate visual cursor position and scroll offset
if (selection >= 5) start = selection - 4; int visualCursor = 0;
for(int i=0; i<selection; i++) {
if(isItemVisible(i)) visualCursor++;
}
const int MAX_LINES = 7; // No title, so we have more space
int startVisualIndex = 0;
if (visualCursor >= MAX_LINES) {
startVisualIndex = visualCursor - (MAX_LINES - 1);
}
int currentVisualIndex = 0;
int y = 0;
int y = 10; for (int i = 0; i < menuItemsCount; i++) {
for (int i = start; i < count; i++) { if (!isItemVisible(i)) continue;
if (y > 55) break;
if (currentVisualIndex >= startVisualIndex) {
if (y > 55) break;
if (i == selection) { if (i == selection) {
display.fillRect(0, y, 128, 8, SSD1306_WHITE); display.fillRect(0, y, 128, 9, SSD1306_WHITE);
display.setTextColor(SSD1306_BLACK, SSD1306_WHITE); display.setTextColor(SSD1306_BLACK, SSD1306_WHITE);
} else { } else {
display.setTextColor(SSD1306_WHITE); display.setTextColor(SSD1306_WHITE);
} }
display.setCursor(2, y);
display.print(items[i]); int x = 2 + (menuItems[i].indentLevel * 6);
display.setCursor(x, y + 1);
if (menuItems[i].isGroup) {
display.print(menuItems[i].expanded ? F("v ") : F("> "));
}
display.print(menuItems[i].label);
if (currentState == UI_MENU_SETUP && i == 1) { MenuItemID id = menuItems[i].id;
if (id == MENU_ID_CHANNEL) {
display.print(F(": ")); display.print(midiChannel); display.print(F(": ")); display.print(midiChannel);
} }
if (currentState == UI_MENU_RANDOMIZE && i >= theme1Index && queuedTheme == (i - theme1Index + 1)) {
display.print(F(" [NEXT]")); // Dynamic values
} if (id == MENU_ID_MELODY) {
if (currentState == UI_MENU_RANDOMIZE && i >= theme1Index && currentThemeIndex == (i - theme1Index + 1)) {
display.print(F(" *"));
}
if (currentState == UI_MENU_RANDOMIZE) {
if (i == 1) { // Melody
display.print(F(": ")); display.print(melodySeed); display.print(F(": ")); display.print(melodySeed);
} else if (i == 2) { // Scale } else if (id == MENU_ID_SCALE) {
display.print(F(": ")); display.print(F(": "));
if (numScaleNotes > 0) { if (numScaleNotes > 0) {
const char* noteNames[] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"}; const char* noteNames[] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"};
@ -181,14 +171,23 @@ void UIManager::drawMenu(const char* title, const char* items[], int count, int
if (j < min(numScaleNotes, 6) - 1) display.print(F(" ")); if (j < min(numScaleNotes, 6) - 1) display.print(F(" "));
} }
} }
} else if (i == 3) { display.print(F(": ")); display.print(tempo); } } else if (id == MENU_ID_TEMPO) { display.print(F(": ")); display.print(tempo); }
else if (i == 4) { display.print(F(": ")); display.print(songModeEnabled ? F("ON") : F("OFF")); } else if (id == MENU_ID_SONG_MODE) { display.print(F(": ")); display.print(songModeEnabled ? F("ON") : F("OFF")); }
else if (i == 5) { display.print(F(": ")); display.print(randomizeTrack + 1); } else if (id == MENU_ID_TRACK_SELECT) { display.print(F(": ")); display.print(randomizeTrack + 1); }
else if (i == 6) { display.print(F(": ")); display.print(trackMute[randomizeTrack] ? F("YES") : F("NO")); } else if (id == MENU_ID_MUTE) { display.print(F(": ")); display.print(trackMute[randomizeTrack] ? F("YES") : F("NO")); }
else if (i == 7) { display.print(F(": ")); display.print(flavourName); } else if (id == MENU_ID_FLAVOUR) { display.print(F(": ")); display.print(flavourName); }
else if (i == 8) { display.print(F(": ")); display.print(mutationEnabled ? F("ON") : F("OFF")); } else if (id == MENU_ID_MUTATION) { display.print(F(": ")); display.print(mutationEnabled ? F("ON") : F("OFF")); }
}
if (id >= MENU_ID_THEME_1 && id <= MENU_ID_THEME_7) {
int themeIdx = id - MENU_ID_THEME_1 + 1;
if (queuedTheme == themeIdx) display.print(F(" [NEXT]"));
if (currentThemeIndex == themeIdx) display.print(F(" *"));
}
y += 9; y += 9;
}
currentVisualIndex++;
} }
} }
@ -205,7 +204,7 @@ int UIManager::getPixelIndex(int x, int y) {
void UIManager::updateLeds(const Step sequence[][NUM_STEPS], int playbackStep, bool isPlaying, void UIManager::updateLeds(const Step sequence[][NUM_STEPS], int playbackStep, bool isPlaying,
UIState currentState, bool songModeEnabled, UIState currentState, bool songModeEnabled,
int songRepeatsRemaining, bool sequenceChangeScheduled, PlayMode playMode, int songRepeatsRemaining, bool sequenceChangeScheduled, PlayMode playMode,
int numScaleNotes, const int* scaleNotes, const bool* trackMute) { int selectedTrack, int numScaleNotes, const int* scaleNotes, const bool* trackMute) {
pixels.clear(); pixels.clear();
const uint32_t COLOR_PLAYHEAD = pixels.Color(0, 255, 0); const uint32_t COLOR_PLAYHEAD = pixels.Color(0, 255, 0);
@ -240,21 +239,22 @@ void UIManager::updateLeds(const Step sequence[][NUM_STEPS], int playbackStep, b
} }
} else { } else {
// --- Mono Mode (original) --- // --- Mono Mode (original) ---
const Step* trackSequence = sequence[selectedTrack];
for (int s = 0; s < NUM_STEPS; s++) { for (int s = 0; s < NUM_STEPS; s++) {
int x = s % 8; int x = s % 8;
int yBase = (s / 8) * 4; int yBase = (s / 8) * 4;
uint32_t color = 0, dimColor = 0; uint32_t color = 0, dimColor = 0;
bool isCursorHere = (isPlaying && s == playbackStep); bool isCursorHere = (isPlaying && s == playbackStep);
if (sequence[0][s].note != -1) { if (trackSequence[s].note != -1) {
color = getNoteColor(sequence[0][s].note, sequence[0][s].tie); color = getNoteColor(trackSequence[s].note, trackSequence[s].tie);
dimColor = getNoteColor(sequence[0][s].note, true); dimColor = getNoteColor(trackSequence[s].note, true);
} }
uint32_t c[4] = {0}; uint32_t c[4] = {0};
if (sequence[0][s].note != -1) { if (trackSequence[s].note != -1) {
int octave = sequence[0][s].note / 12; int octave = trackSequence[s].note / 12;
if (octave > 4) { c[0] = color; if (sequence[0][s].accent) c[1] = dimColor; } if (octave > 4) { c[0] = color; if (trackSequence[s].accent) c[1] = dimColor; }
else if (octave < 4) { c[2] = color; if (sequence[0][s].accent) c[1] = dimColor; } else if (octave < 4) { c[2] = color; if (trackSequence[s].accent) c[1] = dimColor; }
else { c[1] = color; if (sequence[0][s].accent) { c[0] = dimColor; c[2] = dimColor; } } else { c[1] = color; if (trackSequence[s].accent) { c[0] = dimColor; c[2] = dimColor; } }
} }
uint32_t cursorColor = pixels.Color(0, 0, 50); uint32_t cursorColor = pixels.Color(0, 0, 50);
if (isPlaying) { if (isPlaying) {

View File

@ -20,26 +20,22 @@ public:
int numScaleNotes, const int* scaleNotes, int melodySeed, int numScaleNotes, const int* scaleNotes, int melodySeed,
bool mutationEnabled, bool songModeEnabled, bool mutationEnabled, bool songModeEnabled,
const Step sequence[][NUM_STEPS], int playbackStep, bool isPlaying, const Step sequence[][NUM_STEPS], int playbackStep, bool isPlaying,
const char* mainMenu[], int mainMenuCount, int randomizeTrack, const bool* trackMute);
const char* randomizeMenu[], int randomizeMenuCount,
const char* setupMenu[], int setupMenuCount, int theme1Index,
PlayMode playMode, int randomizeTrack, const bool* trackMute);
void updateLeds(const Step sequence[][NUM_STEPS], int playbackStep, bool isPlaying, void updateLeds(const Step sequence[][NUM_STEPS], int playbackStep, bool isPlaying,
UIState currentState, bool songModeEnabled, UIState currentState, bool songModeEnabled,
int songRepeatsRemaining, bool sequenceChangeScheduled, PlayMode playMode, int songRepeatsRemaining, bool sequenceChangeScheduled, PlayMode playMode,
int numScaleNotes, const int* scaleNotes, const bool* trackMute); int selectedTrack, int numScaleNotes, const int* scaleNotes, const bool* trackMute);
private: private:
Adafruit_SSD1306 display; Adafruit_SSD1306 display;
Adafruit_NeoPixel pixels; Adafruit_NeoPixel pixels;
uint32_t leds_buffer[8][8]; // For piano roll uint32_t leds_buffer[8][8]; // For piano roll
void drawMenu(const char* title, const char* items[], int count, int selection, void drawMenu(int selection, UIState currentState, int midiChannel, int tempo, const char* flavourName,
UIState currentState, int midiChannel, int tempo, const char* flavourName,
int queuedTheme, int currentThemeIndex, int queuedTheme, int currentThemeIndex,
int numScaleNotes, const int* scaleNotes, int melodySeed, int numScaleNotes, const int* scaleNotes, int melodySeed,
bool mutationEnabled, bool songModeEnabled, int theme1Index, PlayMode playMode, int randomizeTrack, const bool* trackMute); bool mutationEnabled, bool songModeEnabled, int randomizeTrack, const bool* trackMute);
uint32_t getNoteColor(int note, bool dim); uint32_t getNoteColor(int note, bool dim);
int getPixelIndex(int x, int y); int getPixelIndex(int x, int y);

View File

@ -132,22 +132,18 @@ static void handleInput() {
if (delta != 0) { if (delta != 0) {
switch(currentState) { switch(currentState) {
case UI_MENU_MAIN: case UI_MENU_MAIN:
menuSelection += (delta > 0 ? 1 : -1);
if (menuSelection < 0) menuSelection = mainMenuCount - 1;
if (menuSelection >= mainMenuCount) menuSelection = 0;
break;
case UI_MENU_RANDOMIZE:
{ {
menuSelection += (delta > 0 ? 1 : -1); int next = menuSelection;
if (menuSelection < 0) menuSelection = randomizeMenuPolyCount - 1; int count = 0;
if (menuSelection >= randomizeMenuPolyCount) menuSelection = 0; do {
next += (delta > 0 ? 1 : -1);
if (next < 0) next = menuItemsCount - 1;
if (next >= menuItemsCount) next = 0;
count++;
} while (!isItemVisible(next) && count < menuItemsCount);
menuSelection = next;
} }
break; break;
case UI_MENU_SETUP:
menuSelection += (delta > 0 ? 1 : -1);
if (menuSelection < 0) menuSelection = setupMenuCount - 1;
if (menuSelection >= setupMenuCount) menuSelection = 0;
break;
case UI_SETUP_CHANNEL_EDIT: case UI_SETUP_CHANNEL_EDIT:
{ {
midiChannels[randomizeTrack] += (delta > 0 ? 1 : -1); midiChannels[randomizeTrack] += (delta > 0 ? 1 : -1);
@ -198,14 +194,13 @@ static void handleInput() {
if (!buttonConsumed) { // Short press action if (!buttonConsumed) { // Short press action
switch(currentState) { switch(currentState) {
case UI_MENU_MAIN: case UI_MENU_MAIN:
if (menuSelection == 0) { currentState = UI_MENU_RANDOMIZE; menuSelection = 0; break; } if (menuItems[menuSelection].isGroup) {
if (menuSelection == 1) { currentState = UI_MENU_SETUP; menuSelection = 0; break; } menuItems[menuSelection].expanded = !menuItems[menuSelection].expanded;
break; break;
case UI_MENU_RANDOMIZE: }
{
if (menuSelection == 0) { currentState = UI_MENU_SETUP; menuSelection = 0; break; } switch(menuItems[menuSelection].id) {
case MENU_ID_MELODY:
if (menuSelection == 1) { // Melody
midi.lock(); midi.lock();
melodySeeds[randomizeTrack] = random(10000); melodySeeds[randomizeTrack] = random(10000);
if (isPlaying) { if (isPlaying) {
@ -219,8 +214,8 @@ static void handleInput() {
midi.unlock(); midi.unlock();
saveSequence(true); saveSequence(true);
break; break;
}
if (menuSelection == 2) { // Scale case MENU_ID_SCALE:
generateRandomScale(); generateRandomScale();
if (isPlaying) { if (isPlaying) {
int theme = (queuedTheme != -1) ? queuedTheme : currentThemeIndex; int theme = (queuedTheme != -1) ? queuedTheme : currentThemeIndex;
@ -232,23 +227,27 @@ static void handleInput() {
} }
saveSequence(true); saveSequence(true);
break; break;
}
if (menuSelection == 3) { currentState = UI_EDIT_TEMPO; break; } // Tempo case MENU_ID_TEMPO: currentState = UI_EDIT_TEMPO; break;
if (menuSelection == 4) { // Song Mode
case MENU_ID_SONG_MODE:
songModeEnabled = !songModeEnabled; songModeEnabled = !songModeEnabled;
if (songModeEnabled) { if (songModeEnabled) {
songModeNeedsNext = true; songModeNeedsNext = true;
} }
break; break;
}
if (menuSelection == 5) { currentState = UI_RANDOMIZE_TRACK_EDIT; break; } // Track case MENU_ID_TRACK_SELECT: currentState = UI_RANDOMIZE_TRACK_EDIT; break;
if (menuSelection == 6) { trackMute[randomizeTrack] = !trackMute[randomizeTrack]; break; } // Mute case MENU_ID_MUTE: trackMute[randomizeTrack] = !trackMute[randomizeTrack]; break;
if (menuSelection == 7) { currentState = UI_EDIT_FLAVOUR; break; } // Flavour case MENU_ID_FLAVOUR: currentState = UI_EDIT_FLAVOUR; break;
if (menuSelection == 8) { mutationEnabled = !mutationEnabled; break; } // Mutation case MENU_ID_MUTATION: mutationEnabled = !mutationEnabled; break;
case MENU_ID_CHANNEL: currentState = UI_SETUP_CHANNEL_EDIT; break;
case MENU_ID_RESET: factoryReset(); break;
if (menuSelection >= THEME_1_INDEX_POLY) { // Themes default:
const int selectedTheme = menuSelection - THEME_1_INDEX_POLY + 1; if (menuItems[menuSelection].id >= MENU_ID_THEME_1 && menuItems[menuSelection].id <= MENU_ID_THEME_7) {
const int selectedTheme = menuItems[menuSelection].id - MENU_ID_THEME_1 + 1;
if (isPlaying) { if (isPlaying) {
queuedTheme = selectedTheme; queuedTheme = selectedTheme;
midi.lock(); midi.lock();
@ -260,23 +259,19 @@ static void handleInput() {
} }
break; break;
} }
break;
} }
break; break;
case UI_MENU_SETUP:
if (menuSelection == 0) { currentState = UI_MENU_RANDOMIZE; menuSelection = 0; break; }
if (menuSelection == 1) { currentState = UI_SETUP_CHANNEL_EDIT; break; }
if (menuSelection == 2) { factoryReset(); break; }
break;
case UI_SETUP_CHANNEL_EDIT: case UI_SETUP_CHANNEL_EDIT:
currentState = UI_MENU_SETUP; currentState = UI_MENU_MAIN;
saveSequence(true); saveSequence(true);
break; break;
case UI_EDIT_TEMPO: case UI_EDIT_TEMPO:
currentState = UI_MENU_RANDOMIZE; currentState = UI_MENU_MAIN;
saveSequence(true); saveSequence(true);
break; break;
case UI_EDIT_FLAVOUR: case UI_EDIT_FLAVOUR:
currentState = UI_MENU_RANDOMIZE; currentState = UI_MENU_MAIN;
if (isPlaying) { if (isPlaying) {
int theme = (queuedTheme != -1) ? queuedTheme : currentThemeIndex; int theme = (queuedTheme != -1) ? queuedTheme : currentThemeIndex;
midi.lock(); midi.lock();
@ -290,7 +285,7 @@ static void handleInput() {
saveSequence(true); saveSequence(true);
break; break;
case UI_RANDOMIZE_TRACK_EDIT: case UI_RANDOMIZE_TRACK_EDIT:
currentState = UI_MENU_RANDOMIZE; currentState = UI_MENU_MAIN;
saveSequence(true); saveSequence(true);
break; break;
} }
@ -352,9 +347,7 @@ static void drawUI() {
ui.draw(local_currentState, local_menuSelection, ui.draw(local_currentState, local_menuSelection,
local_midiChannel, local_tempo, local_strategy, local_midiChannel, local_tempo, local_strategy,
local_queuedTheme, local_currentThemeIndex, local_numScaleNotes, local_scaleNotes, local_melodySeed, local_queuedTheme, local_currentThemeIndex, local_numScaleNotes, local_scaleNotes, local_melodySeed,
local_mutationEnabled, local_songModeEnabled, (const Step (*)[NUM_STEPS])local_sequence, local_playbackStep, local_isPlaying, local_mutationEnabled, local_songModeEnabled, (const Step (*)[NUM_STEPS])local_sequence, local_playbackStep, local_isPlaying, local_randomizeTrack, (const bool*)local_trackMute);
mainMenu, mainMenuCount, randomizeMenuPoly, randomizeMenuPolyCount, setupMenu, setupMenuCount,
THEME_1_INDEX_POLY, MODE_POLY, local_randomizeTrack, (const bool*)local_trackMute);
} }
static void updateLeds() { static void updateLeds() {
@ -371,6 +364,7 @@ static void updateLeds() {
int local_numScaleNotes; int local_numScaleNotes;
int local_scaleNotes[12]; int local_scaleNotes[12];
bool local_trackMute[NUM_TRACKS]; bool local_trackMute[NUM_TRACKS];
int local_randomizeTrack;
midi.lock(); midi.lock();
memcpy(local_sequence, sequence, sizeof(local_sequence)); memcpy(local_sequence, sequence, sizeof(local_sequence));
@ -383,16 +377,17 @@ static void updateLeds() {
local_sequenceChangeScheduled = sequenceChangeScheduled; local_sequenceChangeScheduled = sequenceChangeScheduled;
local_playMode = playMode; local_playMode = playMode;
local_numScaleNotes = numScaleNotes; local_numScaleNotes = numScaleNotes;
local_randomizeTrack = randomizeTrack;
memcpy(local_scaleNotes, scaleNotes, sizeof(local_scaleNotes)); memcpy(local_scaleNotes, scaleNotes, sizeof(local_scaleNotes));
memcpy(local_trackMute, (const void*)trackMute, sizeof(local_trackMute)); memcpy(local_trackMute, (const void*)trackMute, sizeof(local_trackMute));
midi.unlock(); midi.unlock();
PlayMode ledDisplayMode = MODE_POLY; // Default to POLY (MAIN section view) PlayMode ledDisplayMode = MODE_POLY; // Default to POLY (MAIN section view)
if (local_currentState == UI_MENU_RANDOMIZE) { if (local_currentState == UI_MENU_MAIN) {
// Main section items: Setup(0), Melody(1), Scale(2), Tempo(3), Song Mode(4) MenuItemID id = menuItems[local_menuSelection].id;
bool isMainSection = (local_menuSelection <= 4); // Check if we are in the Track group (IDs between TRACK_SELECT and THEME_7)
if (!isMainSection) { if (id >= MENU_ID_TRACK_SELECT && id <= MENU_ID_THEME_7) {
// It's a TRACK section item (Track, Mute, Flavour, Mutation, Themes) // It's a TRACK section item (Track, Mute, Flavour, Mutation, Themes)
ledDisplayMode = MODE_MONO; ledDisplayMode = MODE_MONO;
} }
@ -403,7 +398,7 @@ static void updateLeds() {
ui.updateLeds((const Step (*)[NUM_STEPS])local_sequence, local_playbackStep, local_isPlaying, ui.updateLeds((const Step (*)[NUM_STEPS])local_sequence, local_playbackStep, local_isPlaying,
local_currentState, local_songModeEnabled, local_songRepeatsRemaining, local_currentState, local_songModeEnabled, local_songRepeatsRemaining,
local_sequenceChangeScheduled, ledDisplayMode, local_numScaleNotes, local_sequenceChangeScheduled, ledDisplayMode, local_randomizeTrack, local_numScaleNotes,
local_scaleNotes, (const bool*)local_trackMute); local_scaleNotes, (const bool*)local_trackMute);
} }