Drop mono mode

This commit is contained in:
Dejvino 2026-02-19 10:48:55 +01:00
parent 4ec306b8b9
commit 8ae1f5f501
5 changed files with 77 additions and 112 deletions

View File

@ -11,12 +11,11 @@ bool wasPlaying = false;
static void handlePlayback() {
bool nowPlaying = isPlaying;
int tracksToPlay = (playMode == MODE_POLY) ? NUM_TRACKS : 1;
if (!wasPlaying && nowPlaying) {
midi.sendRealtime(0xFA); // MIDI Start
} else if (wasPlaying && !nowPlaying) {
midi.sendRealtime(0xFC); // MIDI Stop
for (int i=0; i<tracksToPlay; i++) midi.panic(midiChannels[i]);
for (int i=0; i<NUM_TRACKS; i++) midi.panic(midiChannels[i]);
}
wasPlaying = nowPlaying;
@ -45,8 +44,8 @@ static void handlePlayback() {
memcpy(local_nextSequence, nextSequence, sizeof(local_nextSequence));
midi.unlock();
for(int t=0; t<tracksToPlay; t++) {
int trackChannel = playMode == MODE_POLY ? midiChannels[t] : midiChannels[0];
for(int t=0; t<NUM_TRACKS; t++) {
int trackChannel = midiChannels[t];
int nextStep = playbackStep + 1;
if (nextStep >= NUM_STEPS) nextStep = 0;
@ -83,7 +82,7 @@ static void handlePlayback() {
midi.unlock();
}
for (int i=0; i<tracksToPlay; i++) midi.panic(midiChannels[i]);
for (int i=0; i<NUM_TRACKS; i++) midi.panic(midiChannels[i]);
if (sequenceChangeScheduled) {
memcpy(local_sequence, local_nextSequence, sizeof(local_sequence));
@ -111,8 +110,8 @@ static void handlePlayback() {
}
// Note On for new step
for(int t=0; t<tracksToPlay; t++) {
int trackChannel = playMode == MODE_POLY ? midiChannels[t] : midiChannels[0];
for(int t=0; t<NUM_TRACKS; t++) {
int trackChannel = midiChannels[t];
if (!trackMute[t] && local_sequence[t][playbackStep].note != -1) {
uint8_t velocity = local_sequence[t][playbackStep].accent ? 127 : 100;
midi.sendNoteOn(local_sequence[t][playbackStep].note, velocity, trackChannel);
@ -131,10 +130,8 @@ static void handlePlayback() {
void loopPlayback() {
if (needsPanic) {
if (playMode == MODE_POLY) {
for (int i=0; i<NUM_TRACKS; i++) midi.panic(midiChannels[i]);
} else {
midi.panic(midiChannels[0]);
for (int i=0; i<NUM_TRACKS; i++) {
midi.panic(midiChannels[i]);
}
needsPanic = false;
}

View File

@ -18,15 +18,11 @@ UIState currentState = UI_MENU_RANDOMIZE;
const char* mainMenu[] = { "Randomize", "Setup" };
extern const int mainMenuCount = sizeof(mainMenu) / sizeof(char*);
const char* randomizeMenuMono[] = { "Setup", "Melody", "Flavour", "Scale", "Tempo", "Mutation", "Song Mode", "Theme 1", "Theme 2", "Theme 3", "Theme 4", "Theme 5", "Theme 6", "Theme 7" };
extern const int randomizeMenuMonoCount = sizeof(randomizeMenuMono) / sizeof(char*);
extern const int THEME_1_INDEX_MONO = 7;
const char* randomizeMenuPoly[] = { "Setup", "Track", "Mute", "Melody", "Flavour", "Scale", "Tempo", "Mutation", "Song Mode", "Theme 1", "Theme 2", "Theme 3", "Theme 4", "Theme 5", "Theme 6", "Theme 7" };
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" };
extern const int randomizeMenuPolyCount = sizeof(randomizeMenuPoly) / sizeof(char*);
extern const int THEME_1_INDEX_POLY = 9;
const char* setupMenu[] = { "Back", "Play Mode", "Channel", "Factory Reset" };
const char* setupMenu[] = { "Back", "Channel", "Factory Reset" };
extern const int setupMenuCount = sizeof(setupMenu) / sizeof(char*);
int menuSelection = 0;
@ -47,7 +43,7 @@ MelodyStrategy* strategies[] = {
extern const int numStrategies = 6;
int currentStrategyIndices[NUM_TRACKS];
volatile PlayMode playMode = MODE_MONO;
volatile PlayMode playMode = MODE_POLY;
volatile bool mutationEnabled = false;
volatile bool songModeEnabled = false;
volatile int songRepeatsRemaining = 0;

View File

@ -16,9 +16,6 @@ extern UIState currentState;
// Menus
extern const char* mainMenu[];
extern const int mainMenuCount;
extern const char* randomizeMenuMono[];
extern const int randomizeMenuMonoCount;
extern const int THEME_1_INDEX_MONO;
extern const char* randomizeMenuPoly[];
extern const int randomizeMenuPolyCount;
extern const int THEME_1_INDEX_POLY;

View File

@ -66,7 +66,14 @@ void UIManager::draw(UIState currentState, int menuSelection,
drawMenu("MAIN MENU", mainMenu, mainMenuCount, menuSelection, currentState, midiChannel, tempo, currentStrategy->getName(), queuedTheme, currentThemeIndex, numScaleNotes, scaleNotes, melodySeed, mutationEnabled, songModeEnabled, theme1Index, playMode, randomizeTrack, trackMute);
break;
case UI_MENU_RANDOMIZE:
drawMenu("PLAY", randomizeMenu, randomizeMenuCount, menuSelection, currentState, midiChannel, tempo, currentStrategy->getName(), queuedTheme, currentThemeIndex, numScaleNotes, scaleNotes, melodySeed, mutationEnabled, songModeEnabled, theme1Index, playMode, randomizeTrack, trackMute);
{
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);
@ -154,17 +161,8 @@ void UIManager::drawMenu(const char* title, const char* items[], int count, int
display.print(items[i]);
if (currentState == UI_MENU_SETUP && i == 1) {
display.print(F(": ")); display.print(playMode == MODE_MONO ? "Mono" : "Poly");
}
if (currentState == UI_MENU_SETUP && i == 2) {
display.print(F(": ")); display.print(midiChannel);
}
if (currentState == UI_MENU_RANDOMIZE && playMode == MODE_POLY && i == 1) {
display.print(F(": ")); display.print(randomizeTrack + 1);
}
if (currentState == UI_MENU_RANDOMIZE && playMode == MODE_POLY && i == 2) {
display.print(F(": ")); display.print(trackMute[randomizeTrack] ? F("YES") : F("NO"));
}
if (currentState == UI_MENU_RANDOMIZE && i >= theme1Index && queuedTheme == (i - theme1Index + 1)) {
display.print(F(" [NEXT]"));
}
@ -172,12 +170,9 @@ void UIManager::drawMenu(const char* title, const char* items[], int count, int
display.print(F(" *"));
}
if (currentState == UI_MENU_RANDOMIZE) {
int track_offset = (playMode == MODE_POLY) ? 2 : 0;
if (i == 1 + track_offset) { // Melody
if (i == 1) { // Melody
display.print(F(": ")); display.print(melodySeed);
} else if (i == 2 + track_offset) { // Flavour
display.print(F(": ")); display.print(flavourName);
} else if (i == 3 + track_offset) { // Scale
} else if (i == 2) { // Scale
display.print(F(": "));
if (numScaleNotes > 0) {
const char* noteNames[] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"};
@ -186,9 +181,12 @@ void UIManager::drawMenu(const char* title, const char* items[], int count, int
if (j < min(numScaleNotes, 6) - 1) display.print(F(" "));
}
}
} else if (i == 4 + track_offset) { display.print(F(": ")); display.print(tempo); }
else if (i == 5 + track_offset) { display.print(F(": ")); display.print(mutationEnabled ? F("ON") : F("OFF")); }
else if (i == 6 + track_offset) { display.print(F(": ")); display.print(songModeEnabled ? F("ON") : F("OFF")); }
} else if (i == 3) { display.print(F(": ")); display.print(tempo); }
else if (i == 4) { display.print(F(": ")); display.print(songModeEnabled ? F("ON") : F("OFF")); }
else if (i == 5) { display.print(F(": ")); display.print(randomizeTrack + 1); }
else if (i == 6) { display.print(F(": ")); display.print(trackMute[randomizeTrack] ? F("YES") : F("NO")); }
else if (i == 7) { display.print(F(": ")); display.print(flavourName); }
else if (i == 8) { display.print(F(": ")); display.print(mutationEnabled ? F("ON") : F("OFF")); }
}
y += 9;
}
@ -219,8 +217,8 @@ void UIManager::updateLeds(const Step sequence[][NUM_STEPS], int playbackStep, b
if(playMode == MODE_POLY) {
for(int t=0; t<NUM_TRACKS; t++) {
for(int s=0; s<NUM_STEPS; s++) {
int col = t * 2 + (s / 8);
int row = s % 8;
int row = t * 2 + (s / 8);
int col = s % 8;
uint32_t color = 0;
int note = sequence[t][s].note;

View File

@ -36,7 +36,6 @@ void saveSequence(bool quiet) {
for(int i=0; i<NUM_TRACKS; i++) mutes[i] = trackMute[i];
EEPROM.put(addr, mutes); addr += sizeof(mutes);
EEPROM.put(addr, (int)tempo); addr += sizeof(int);
EEPROM.put(addr, (int)playMode); addr += sizeof(int);
EEPROM.put(addr, numScaleNotes); addr += sizeof(numScaleNotes);
for (int i = 0; i<12; i++) {
@ -67,8 +66,6 @@ bool loadSequence() {
int t;
EEPROM.get(addr, t); addr += sizeof(int);
tempo = t;
EEPROM.get(addr, t); addr += sizeof(int);
playMode = (PlayMode)t;
EEPROM.get(addr, numScaleNotes); addr += sizeof(numScaleNotes);
for (int i = 0; i<12; i++) {
@ -121,11 +118,7 @@ void generateTheme(int themeType) {
}
void mutateSequence(Step (*target)[NUM_STEPS]) {
if (playMode == MODE_POLY) {
for(int i=0; i<NUM_TRACKS; i++) strategies[currentStrategyIndices[i]]->mutate(target, i, NUM_STEPS, scaleNotes, numScaleNotes);
} else {
strategies[currentStrategyIndices[0]]->mutate(target, 0, NUM_STEPS, scaleNotes, numScaleNotes);
}
for(int i=0; i<NUM_TRACKS; i++) strategies[currentStrategyIndices[i]]->mutate(target, i, NUM_STEPS, scaleNotes, numScaleNotes);
}
static void handleInput() {
@ -146,9 +139,8 @@ static void handleInput() {
case UI_MENU_RANDOMIZE:
{
menuSelection += (delta > 0 ? 1 : -1);
int count = (playMode == MODE_POLY) ? randomizeMenuPolyCount : randomizeMenuMonoCount;
if (menuSelection < 0) menuSelection = count - 1;
if (menuSelection >= count) menuSelection = 0;
if (menuSelection < 0) menuSelection = randomizeMenuPolyCount - 1;
if (menuSelection >= randomizeMenuPolyCount) menuSelection = 0;
}
break;
case UI_MENU_SETUP:
@ -158,10 +150,9 @@ static void handleInput() {
break;
case UI_SETUP_CHANNEL_EDIT:
{
int trackToEdit = (playMode == MODE_POLY) ? randomizeTrack : 0;
midiChannels[trackToEdit] += (delta > 0 ? 1 : -1);
if (midiChannels[trackToEdit] < 1) midiChannels[trackToEdit] = 16;
if (midiChannels[trackToEdit] > 16) midiChannels[trackToEdit] = 1;
midiChannels[randomizeTrack] += (delta > 0 ? 1 : -1);
if (midiChannels[randomizeTrack] < 1) midiChannels[randomizeTrack] = 16;
if (midiChannels[randomizeTrack] > 16) midiChannels[randomizeTrack] = 1;
}
break;
case UI_EDIT_TEMPO:
@ -171,15 +162,11 @@ static void handleInput() {
break;
case UI_EDIT_FLAVOUR:
{
int trackToEdit = playMode == MODE_POLY ? randomizeTrack : 0;
currentStrategyIndices[trackToEdit] += (delta > 0 ? 1 : -1);
if (currentStrategyIndices[trackToEdit] < 0) currentStrategyIndices[trackToEdit] = numStrategies - 1;
if (currentStrategyIndices[trackToEdit] >= numStrategies) currentStrategyIndices[trackToEdit] = 0;
currentStrategyIndices[randomizeTrack] += (delta > 0 ? 1 : -1);
if (currentStrategyIndices[randomizeTrack] < 0) currentStrategyIndices[randomizeTrack] = numStrategies - 1;
if (currentStrategyIndices[randomizeTrack] >= numStrategies) currentStrategyIndices[randomizeTrack] = 0;
}
break;
case UI_SETUP_PLAYMODE_EDIT:
playMode = (playMode == MODE_MONO) ? MODE_POLY : MODE_MONO;
break;
}
if (currentState == UI_RANDOMIZE_TRACK_EDIT) {
randomizeTrack += (delta > 0 ? 1 : -1);
@ -216,32 +203,24 @@ static void handleInput() {
break;
case UI_MENU_RANDOMIZE:
{
int track_offset = (playMode == MODE_POLY) ? 2 : 0;
int theme_1_index = (playMode == MODE_POLY) ? THEME_1_INDEX_POLY : THEME_1_INDEX_MONO;
if (menuSelection == 0) { currentState = UI_MENU_SETUP; menuSelection = 0; break; }
if (playMode == MODE_POLY) {
if (menuSelection == 1) { currentState = UI_RANDOMIZE_TRACK_EDIT; break; }
if (menuSelection == 2) { trackMute[randomizeTrack] = !trackMute[randomizeTrack]; break; }
}
if (menuSelection == 1 + track_offset) { // Melody
int track = playMode == MODE_POLY ? randomizeTrack : 0;
if (menuSelection == 1) { // Melody
midi.lock();
melodySeeds[track] = random(10000);
melodySeeds[randomizeTrack] = random(10000);
if (isPlaying) {
int theme = (queuedTheme != -1) ? queuedTheme : currentThemeIndex;
if (!sequenceChangeScheduled) {
memcpy(nextSequence, sequence, sizeof(sequence));
}
generateTrackData(track, theme, nextSequence);
generateTrackData(randomizeTrack, theme, nextSequence);
sequenceChangeScheduled = true;
}
midi.unlock();
saveSequence(true);
break;
}
if (menuSelection == 2 + track_offset) { currentState = UI_EDIT_FLAVOUR; break; } // Flavour
if (menuSelection == 3 + track_offset) { // Scale
if (menuSelection == 2) { // Scale
generateRandomScale();
if (isPlaying) {
int theme = (queuedTheme != -1) ? queuedTheme : currentThemeIndex;
@ -254,17 +233,22 @@ static void handleInput() {
saveSequence(true);
break;
}
if (menuSelection == 4 + track_offset) { currentState = UI_EDIT_TEMPO; break; }
if (menuSelection == 5 + track_offset) { mutationEnabled = !mutationEnabled; break; }
if (menuSelection == 6 + track_offset) {
if (menuSelection == 3) { currentState = UI_EDIT_TEMPO; break; } // Tempo
if (menuSelection == 4) { // Song Mode
songModeEnabled = !songModeEnabled;
if (songModeEnabled) {
songModeNeedsNext = true;
}
break;
}
if (menuSelection >= theme_1_index) { // Themes
const int selectedTheme = menuSelection - theme_1_index + 1;
if (menuSelection == 5) { currentState = UI_RANDOMIZE_TRACK_EDIT; break; } // Track
if (menuSelection == 6) { trackMute[randomizeTrack] = !trackMute[randomizeTrack]; break; } // Mute
if (menuSelection == 7) { currentState = UI_EDIT_FLAVOUR; break; } // Flavour
if (menuSelection == 8) { mutationEnabled = !mutationEnabled; break; } // Mutation
if (menuSelection >= THEME_1_INDEX_POLY) { // Themes
const int selectedTheme = menuSelection - THEME_1_INDEX_POLY + 1;
if (isPlaying) {
queuedTheme = selectedTheme;
midi.lock();
@ -280,9 +264,8 @@ static void handleInput() {
break;
case UI_MENU_SETUP:
if (menuSelection == 0) { currentState = UI_MENU_RANDOMIZE; menuSelection = 0; break; }
if (menuSelection == 1) { currentState = UI_SETUP_PLAYMODE_EDIT; break; }
if (menuSelection == 2) { currentState = UI_SETUP_CHANNEL_EDIT; break; }
if (menuSelection == 3) { factoryReset(); break; }
if (menuSelection == 1) { currentState = UI_SETUP_CHANNEL_EDIT; break; }
if (menuSelection == 2) { factoryReset(); break; }
break;
case UI_SETUP_CHANNEL_EDIT:
currentState = UI_MENU_SETUP;
@ -296,21 +279,16 @@ static void handleInput() {
currentState = UI_MENU_RANDOMIZE;
if (isPlaying) {
int theme = (queuedTheme != -1) ? queuedTheme : currentThemeIndex;
int track = playMode == MODE_POLY ? randomizeTrack : 0;
midi.lock();
if (!sequenceChangeScheduled) {
memcpy(nextSequence, sequence, sizeof(sequence));
}
generateTrackData(track, theme, nextSequence);
generateTrackData(randomizeTrack, theme, nextSequence);
sequenceChangeScheduled = true;
midi.unlock();
}
saveSequence(true);
break;
case UI_SETUP_PLAYMODE_EDIT:
currentState = UI_MENU_SETUP;
saveSequence(true);
break;
case UI_RANDOMIZE_TRACK_EDIT:
currentState = UI_MENU_RANDOMIZE;
saveSequence(true);
@ -338,14 +316,9 @@ static void handleInput() {
}
static void drawUI() {
const char **randMenu;
int randMenuCount;
int themeIndex;
// Make local copies of shared data inside a critical section
// to avoid holding the lock during slow display operations.
UIState local_currentState;
PlayMode local_playMode;
int local_menuSelection, local_randomizeTrack, local_tempo, local_currentThemeIndex, local_queuedTheme, local_numScaleNotes;
int local_melodySeed;
bool local_mutationEnabled, local_songModeEnabled, local_isPlaying;
@ -356,30 +329,18 @@ static void drawUI() {
int local_scaleNotes[12];
midi.lock();
local_playMode = playMode;
local_randomizeTrack = randomizeTrack;
int ui_track = (local_playMode == MODE_POLY) ? local_randomizeTrack : 0;
if (local_playMode == MODE_POLY) {
randMenu = randomizeMenuPoly;
randMenuCount = randomizeMenuPolyCount;
themeIndex = THEME_1_INDEX_POLY;
} else {
randMenu = randomizeMenuMono;
randMenuCount = randomizeMenuMonoCount;
themeIndex = THEME_1_INDEX_MONO;
}
local_currentState = currentState;
local_menuSelection = menuSelection;
local_midiChannel = midiChannels[ui_track];
local_midiChannel = midiChannels[local_randomizeTrack];
local_tempo = tempo;
local_strategy = strategies[currentStrategyIndices[ui_track]];
local_strategy = strategies[currentStrategyIndices[local_randomizeTrack]];
local_queuedTheme = queuedTheme;
local_currentThemeIndex = currentThemeIndex;
local_numScaleNotes = numScaleNotes;
memcpy(local_scaleNotes, scaleNotes, sizeof(local_scaleNotes));
local_melodySeed = melodySeeds[ui_track];
local_melodySeed = melodySeeds[local_randomizeTrack];
local_mutationEnabled = mutationEnabled;
local_songModeEnabled = songModeEnabled;
memcpy(local_sequence, sequence, sizeof(local_sequence));
@ -392,8 +353,8 @@ static void drawUI() {
local_midiChannel, local_tempo, local_strategy,
local_queuedTheme, local_currentThemeIndex, local_numScaleNotes, local_scaleNotes, local_melodySeed,
local_mutationEnabled, local_songModeEnabled, (const Step (*)[NUM_STEPS])local_sequence, local_playbackStep, local_isPlaying,
mainMenu, mainMenuCount, randMenu, randMenuCount, setupMenu, setupMenuCount,
themeIndex, local_playMode, 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() {
@ -402,6 +363,7 @@ static void updateLeds() {
int local_playbackStep;
bool local_isPlaying;
UIState local_currentState;
int local_menuSelection;
bool local_songModeEnabled;
int local_songRepeatsRemaining;
bool local_sequenceChangeScheduled;
@ -415,6 +377,7 @@ static void updateLeds() {
local_playbackStep = playbackStep;
local_isPlaying = isPlaying;
local_currentState = currentState;
local_menuSelection = menuSelection;
local_songModeEnabled = songModeEnabled;
local_songRepeatsRemaining = songRepeatsRemaining;
local_sequenceChangeScheduled = sequenceChangeScheduled;
@ -424,9 +387,23 @@ static void updateLeds() {
memcpy(local_trackMute, (const void*)trackMute, sizeof(local_trackMute));
midi.unlock();
PlayMode ledDisplayMode = MODE_POLY; // Default to POLY (MAIN section view)
if (local_currentState == UI_MENU_RANDOMIZE) {
// Main section items: Setup(0), Melody(1), Scale(2), Tempo(3), Song Mode(4)
bool isMainSection = (local_menuSelection <= 4);
if (!isMainSection) {
// It's a TRACK section item (Track, Mute, Flavour, Mutation, Themes)
ledDisplayMode = MODE_MONO;
}
} else if (local_currentState == UI_EDIT_FLAVOUR || local_currentState == UI_RANDOMIZE_TRACK_EDIT) {
// These are entered from TRACK section items
ledDisplayMode = MODE_MONO;
}
ui.updateLeds((const Step (*)[NUM_STEPS])local_sequence, local_playbackStep, local_isPlaying,
local_currentState, local_songModeEnabled, local_songRepeatsRemaining,
local_sequenceChangeScheduled, local_playMode, local_numScaleNotes,
local_sequenceChangeScheduled, ledDisplayMode, local_numScaleNotes,
local_scaleNotes, (const bool*)local_trackMute);
}