Compare commits

..

No commits in common. "84ef40a55550ff83753ed294b3e16731191dc8a4" and "4e4ba0d0e44619cc0dee59052de6e70a8bc2efb3" have entirely different histories.

8 changed files with 83 additions and 158 deletions

View File

@ -4,7 +4,6 @@
#include "config.h" #include "config.h"
#include "SharedState.h" #include "SharedState.h"
static int local_numSteps[NUM_TRACKS];
static Step local_sequence[NUM_TRACKS][NUM_STEPS]; static Step local_sequence[NUM_TRACKS][NUM_STEPS];
static Step local_nextSequence[NUM_TRACKS][NUM_STEPS]; static Step local_nextSequence[NUM_TRACKS][NUM_STEPS];
@ -43,24 +42,16 @@ static void handlePlayback() {
midi.lock(); midi.lock();
memcpy(local_sequence, sequence, sizeof(local_sequence)); memcpy(local_sequence, sequence, sizeof(local_sequence));
memcpy(local_nextSequence, nextSequence, sizeof(local_nextSequence)); memcpy(local_nextSequence, nextSequence, sizeof(local_nextSequence));
for (int i = 0; i < NUM_TRACKS; i++) local_numSteps[i] = numSteps[i];
midi.unlock(); midi.unlock();
int master_len = 0;
for(int i=0; i<NUM_TRACKS; i++) {
if(local_numSteps[i] > master_len) master_len = local_numSteps[i];
}
if (master_len == 0) master_len = NUM_STEPS;
for(int t=0; t<NUM_TRACKS; t++) { for(int t=0; t<NUM_TRACKS; t++) {
int trackChannel = midiChannels[t]; int trackChannel = midiChannels[t];
int track_len = local_numSteps[t]; int nextStep = playbackStep + 1;
int current_step = playbackStep % track_len; if (nextStep >= numSteps) nextStep = 0;
int next_step = (playbackStep + 1) % track_len;
// Determine if we are tying to the next note // Determine if we are tying to the next note
bool isTied = local_sequence[t][current_step].tie && (local_sequence[t][next_step].note != -1); bool isTied = local_sequence[t][playbackStep].tie && (local_sequence[t][nextStep].note != -1);
int prevNote = local_sequence[t][current_step].note; int prevNote = local_sequence[t][playbackStep].note;
// Note Off for previous step (if NOT tied) // Note Off for previous step (if NOT tied)
if (!isTied && prevNote != -1) { if (!isTied && prevNote != -1) {
@ -70,8 +61,9 @@ static void handlePlayback() {
playbackStep++; playbackStep++;
bool justPanicked = false; bool justPanicked = false;
// When the global step counter completes a full cycle of the longest track if (playbackStep >= numSteps) {
if ((playbackStep > 0) && ((playbackStep % master_len) == 0)) { playbackStep = 0;
for (int i=0; i<NUM_TRACKS; i++) midi.panic(midiChannels[i]); for (int i=0; i<NUM_TRACKS; i++) midi.panic(midiChannels[i]);
justPanicked = true; justPanicked = true;
@ -122,18 +114,16 @@ static void handlePlayback() {
// Note On for new step // Note On for new step
for(int t=0; t<NUM_TRACKS; t++) { for(int t=0; t<NUM_TRACKS; t++) {
int trackChannel = midiChannels[t]; int trackChannel = midiChannels[t];
int track_len = local_numSteps[t]; int prevStep = (playbackStep == 0) ? numSteps - 1 : playbackStep - 1;
int current_step = playbackStep % track_len; bool wasTied = local_sequence[t][prevStep].tie && (local_sequence[t][playbackStep].note != -1);
int prev_step = (playbackStep == 0) ? track_len - 1 : (playbackStep - 1) % track_len; int prevNote = local_sequence[t][prevStep].note;
bool wasTied = local_sequence[t][prev_step].tie && (local_sequence[t][current_step].note != -1); int currentNote = local_sequence[t][playbackStep].note;
int prevNote = local_sequence[t][prev_step].note;
int currentNote = local_sequence[t][current_step].note;
// If tied to the SAME note, do not retrigger (sustain) // If tied to the SAME note, do not retrigger (sustain)
bool isContinuing = wasTied && (prevNote == currentNote) && !justPanicked; bool isContinuing = wasTied && (prevNote == currentNote) && !justPanicked;
if (!trackMute[t] && currentNote != -1 && !isContinuing) { if (!trackMute[t] && currentNote != -1 && !isContinuing) {
uint8_t velocity = local_sequence[t][current_step].accent ? 127 : 100; uint8_t velocity = local_sequence[t][playbackStep].accent ? 127 : 100;
midi.sendNoteOn(currentNote, velocity, trackChannel); midi.sendNoteOn(currentNote, velocity, trackChannel);
} }

View File

@ -62,12 +62,11 @@ void setup() {
EEPROM.begin(4096); EEPROM.begin(4096);
if (!loadSequence()) { if (!loadSequence()) {
Serial.println(F("Starting fresh instead.")); Serial.println(F("Starting fresh instead."));
numSteps = NUM_STEPS;
for(int i=0; i<NUM_TRACKS; i++) { for(int i=0; i<NUM_TRACKS; i++) {
midiChannels[i] = i + 1; midiChannels[i] = i + 1;
melodySeeds[i] = random(10000); melodySeeds[i] = random(10000);
randomSeed(melodySeeds[i]);
numSteps[i] = random(1, NUM_STEPS + 1);
currentStrategyIndices[i] = 0; currentStrategyIndices[i] = 0;
trackMute[i] = false; trackMute[i] = false;
} }

View File

@ -23,12 +23,12 @@ MenuItem menuItems[] = {
{ "Playback", MENU_ID_PLAYBACK, false, false, 1 }, { "Playback", MENU_ID_PLAYBACK, false, false, 1 },
{ "Melody", MENU_ID_MELODY, false, false, 1 }, { "Melody", MENU_ID_MELODY, false, false, 1 },
{ "Scale", MENU_ID_SCALE, false, false, 1 }, { "Scale", MENU_ID_SCALE, false, false, 1 },
{ "Steps", MENU_ID_STEPS, false, false, 1 },
{ "Tempo", MENU_ID_TEMPO, false, false, 1 }, { "Tempo", MENU_ID_TEMPO, false, false, 1 },
{ "Song Mode", MENU_ID_SONG_MODE, false, false, 1 }, { "Song Mode", MENU_ID_SONG_MODE, false, false, 1 },
{ "Track", MENU_ID_GROUP_TRACK, true, true, 0 }, { "Track", MENU_ID_GROUP_TRACK, true, true, 0 },
{ "Track", MENU_ID_TRACK_SELECT, false, false, 1 }, { "Track", MENU_ID_TRACK_SELECT, false, false, 1 },
{ "Mute", MENU_ID_MUTE, false, false, 1 }, { "Mute", MENU_ID_MUTE, false, false, 1 },
{ "Steps", MENU_ID_STEPS, false, false, 1 },
{ "Flavour", MENU_ID_FLAVOUR, false, false, 1 }, { "Flavour", MENU_ID_FLAVOUR, false, false, 1 },
{ "Intensity", MENU_ID_INTENSITY, false, false, 1 }, { "Intensity", MENU_ID_INTENSITY, false, false, 1 },
{ "Mutation", MENU_ID_MUTATION, false, false, 1 }, { "Mutation", MENU_ID_MUTATION, false, false, 1 },
@ -104,7 +104,7 @@ bool isItemVisible(int index) {
int menuSelection = 0; int menuSelection = 0;
volatile bool trackMute[NUM_TRACKS]; volatile bool trackMute[NUM_TRACKS];
int randomizeTrack = 0; int randomizeTrack = 0;
volatile int numSteps[NUM_TRACKS] = {NUM_STEPS, NUM_STEPS, NUM_STEPS, NUM_STEPS}; volatile int numSteps = NUM_STEPS;
volatile int playbackStep = 0; volatile int playbackStep = 0;
volatile int midiChannels[NUM_TRACKS]; volatile int midiChannels[NUM_TRACKS];
int scaleNotes[12]; int scaleNotes[12];

View File

@ -19,13 +19,13 @@ enum MenuItemID {
MENU_ID_PLAYBACK, MENU_ID_PLAYBACK,
MENU_ID_MELODY, MENU_ID_MELODY,
MENU_ID_SCALE, MENU_ID_SCALE,
MENU_ID_STEPS,
MENU_ID_TEMPO, MENU_ID_TEMPO,
MENU_ID_SONG_MODE, MENU_ID_SONG_MODE,
MENU_ID_GROUP_TRACK, MENU_ID_GROUP_TRACK,
MENU_ID_TRACK_SELECT, MENU_ID_TRACK_SELECT,
MENU_ID_MUTE, MENU_ID_MUTE,
MENU_ID_STEPS,
MENU_ID_FLAVOUR, MENU_ID_FLAVOUR,
MENU_ID_INTENSITY, MENU_ID_INTENSITY,
MENU_ID_MUTATION, MENU_ID_MUTATION,
@ -65,7 +65,7 @@ bool isItemVisible(int index);
extern int menuSelection; extern int menuSelection;
extern volatile bool trackMute[NUM_TRACKS]; extern volatile bool trackMute[NUM_TRACKS];
extern int randomizeTrack; extern int randomizeTrack;
extern volatile int numSteps[NUM_TRACKS]; extern volatile int numSteps;
extern volatile int playbackStep; extern volatile int playbackStep;
extern volatile int midiChannels[NUM_TRACKS]; extern volatile int midiChannels[NUM_TRACKS];
extern int scaleNotes[12]; extern int scaleNotes[12];

View File

@ -7,10 +7,8 @@
#define SCREEN_HEIGHT 64 #define SCREEN_HEIGHT 64
#define OLED_RESET -1 #define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C #define SCREEN_ADDRESS 0x3C
#define PIN_NEOPIXEL 6 #define PIN_NEOPIXEL 2
#define NEOPIXELS_X 16 #define NUM_PIXELS 64
#define NEOPIXELS_Y 8
#define NUM_PIXELS 64*2 // 8x8 LEDs in 2 panels
UIManager ui; UIManager ui;
@ -52,7 +50,7 @@ void UIManager::showMessage(const char* msg) {
void UIManager::draw(UIState currentState, int menuSelection, void UIManager::draw(UIState currentState, int menuSelection,
int midiChannel, int tempo, MelodyStrategy* currentStrategy, int midiChannel, int tempo, MelodyStrategy* currentStrategy,
int queuedTheme, int currentThemeIndex, int queuedTheme, int currentThemeIndex,
int numScaleNotes, const int* scaleNotes, int melodySeed, int currentTrackNumSteps, int numScaleNotes, const int* scaleNotes, int melodySeed, int numSteps,
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,
int randomizeTrack, const bool* trackMute, const int* trackIntensities) { int randomizeTrack, const bool* trackMute, const int* trackIntensities) {
@ -64,7 +62,7 @@ void UIManager::draw(UIState currentState, int menuSelection,
switch(currentState) { switch(currentState) {
case UI_MENU_MAIN: case UI_MENU_MAIN:
drawMenu(menuSelection, currentState, midiChannel, tempo, currentStrategy->getName(), queuedTheme, currentThemeIndex, numScaleNotes, scaleNotes, melodySeed, currentTrackNumSteps, mutationEnabled, songModeEnabled, isPlaying, randomizeTrack, trackMute, trackIntensities); drawMenu(menuSelection, currentState, midiChannel, tempo, currentStrategy->getName(), queuedTheme, currentThemeIndex, numScaleNotes, scaleNotes, melodySeed, numSteps, mutationEnabled, songModeEnabled, isPlaying, randomizeTrack, trackMute, trackIntensities);
break; break;
case UI_SETUP_CHANNEL_EDIT: case UI_SETUP_CHANNEL_EDIT:
display.println(F("SET MIDI CHANNEL")); display.println(F("SET MIDI CHANNEL"));
@ -95,7 +93,7 @@ void UIManager::draw(UIState currentState, int menuSelection,
display.setCursor(20, 25); display.setCursor(20, 25);
display.setTextSize(2); display.setTextSize(2);
display.print(F("LEN: ")); display.print(F("LEN: "));
display.print(currentTrackNumSteps); display.print(numSteps);
display.setTextSize(1); display.setTextSize(1);
display.setCursor(0, 50); display.setCursor(0, 50);
display.println(F(" (Press to confirm)")); display.println(F(" (Press to confirm)"));
@ -234,7 +232,7 @@ void UIManager::drawNumberEditor(const char* title, int value, int minVal, int m
void UIManager::drawMenu(int selection, UIState currentState, int midiChannel, int tempo, const char* flavourName, void UIManager::drawMenu(int selection, 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, int currentTrackNumSteps, bool mutationEnabled, const int* scaleNotes, int melodySeed, int numSteps, bool mutationEnabled,
bool songModeEnabled, bool isPlaying, int randomizeTrack, const bool* trackMute, const int* trackIntensities) { bool songModeEnabled, bool isPlaying, int randomizeTrack, const bool* trackMute, const int* trackIntensities) {
// Calculate visual cursor position and scroll offset // Calculate visual cursor position and scroll offset
@ -294,7 +292,7 @@ void UIManager::drawMenu(int selection, UIState currentState, int midiChannel, i
} }
} }
} else if (id == MENU_ID_TEMPO) { display.print(F(": ")); display.print(tempo); } } else if (id == MENU_ID_TEMPO) { display.print(F(": ")); display.print(tempo); }
else if (id == MENU_ID_STEPS) { display.print(F(": ")); display.print(currentTrackNumSteps); } else if (id == MENU_ID_STEPS) { display.print(F(": ")); display.print(numSteps); }
else if (id == MENU_ID_SONG_MODE) { 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 (id == MENU_ID_TRACK_SELECT) { display.print(F(": ")); display.print(randomizeTrack + 1); } else if (id == MENU_ID_TRACK_SELECT) { display.print(F(": ")); display.print(randomizeTrack + 1); }
else if (id == MENU_ID_MUTE) { 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")); }
@ -334,66 +332,57 @@ uint32_t UIManager::getNoteColor(int note, bool dim) {
} }
int UIManager::getPixelIndex(int x, int y) { int UIManager::getPixelIndex(int x, int y) {
// [i] Here you can adjust the mapping from "logical" pixel coordinates return y * 8 + x;
// to your physical NeoPixel layout. It depends on how you connected it.
return NEOPIXELS_Y * x + (NEOPIXELS_Y - 1 - 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 selectedTrack, const int* numSteps, int numScaleNotes, const int* scaleNotes, const bool* trackMute) { int selectedTrack, int numSteps, 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);
const uint32_t COLOR_PLAYHEAD_DIM = pixels.Color(0, 32, 0); const uint32_t COLOR_PLAYHEAD_DIM = pixels.Color(0, 32, 0);
const uint32_t COLOR_MUTED_PLAYHEAD = pixels.Color(0, 0, 255); const uint32_t COLOR_MUTED_PLAYHEAD = pixels.Color(0, 0, 255);
const uint32_t COLOR_CURSOR = pixels.Color(255, 100, 100); const uint32_t COLOR_CURSOR = pixels.Color(255, 255, 255);
const uint32_t COLOR_CURSOR_DIM = pixels.Color(32, 0, 0); const uint32_t COLOR_CURSOR_DIM = pixels.Color(32, 0, 0);
if(playMode == MODE_POLY) { if(playMode == MODE_POLY) {
for(int t=0; t<NUM_TRACKS; t++) { for(int t=0; t<NUM_TRACKS; t++) {
int currentTrackSteps = numSteps[t];
for(int s=0; s<NUM_STEPS; s++) { for(int s=0; s<NUM_STEPS; s++) {
int col = s; // Each step is a column if (s >= numSteps) continue;
// --- First row of track pair: Notes --- int row = t * 2 + (s / 8);
int note_row = t * 2; int col = s % 8;
uint32_t note_color = 0;
if (s < currentTrackSteps) { uint32_t color = 0;
int note = sequence[t][s].note; int note = sequence[t][s].note;
if (note != -1) {
note_color = getNoteColor(note, !sequence[t][s].accent);
}
}
pixels.setPixelColor(getPixelIndex(col, note_row), note_color);
// --- Second row of track pair: Steps & Playhead --- if (note != -1) {
int step_row = t * 2 + 1; color = getNoteColor(note, !sequence[t][s].accent);
uint32_t step_color = 0; // Off by default for steps > currentTrackSteps }
if (s < currentTrackSteps) {
step_color = COLOR_PLAYHEAD_DIM; // It's a valid step if (isPlaying && s == playbackStep) {
if (isPlaying && (s == (playbackStep % currentTrackSteps))) {
if (trackMute[t]) { if (trackMute[t]) {
step_color = COLOR_MUTED_PLAYHEAD; color = COLOR_MUTED_PLAYHEAD;
} else { } else {
step_color = COLOR_PLAYHEAD; color = (note != -1) ? COLOR_PLAYHEAD : COLOR_PLAYHEAD_DIM;
} }
} }
}
pixels.setPixelColor(getPixelIndex(col, step_row), step_color); pixels.setPixelColor(getPixelIndex(col, row), color);
} }
} }
} else { } else {
// --- Mono Mode (original) --- // --- Mono Mode (original) ---
const Step* trackSequence = sequence[selectedTrack]; const Step* trackSequence = sequence[selectedTrack];
for (int s = 0; s < NUM_STEPS; s++) { for (int s = 0; s < NUM_STEPS; s++) {
if (s >= numSteps[selectedTrack]) continue; if (s >= numSteps) continue;
int x = s % NUM_STEPS; int x = s % 8;
int yBase = (s / NUM_STEPS) * 2; int yBase = (s / 8) * 4;
uint32_t color = 0, dimColor = 0; uint32_t color = 0, dimColor = 0;
bool isCursorHere = (isPlaying && s == (playbackStep % numSteps[selectedTrack])); bool isCursorHere = (isPlaying && s == playbackStep);
if (trackSequence[s].note != -1) { if (trackSequence[s].note != -1) {
color = getNoteColor(trackSequence[s].note, trackSequence[s].tie); color = getNoteColor(trackSequence[s].note, trackSequence[s].tie);
dimColor = getNoteColor(trackSequence[s].note, true); dimColor = getNoteColor(trackSequence[s].note, true);
@ -408,9 +397,9 @@ void UIManager::updateLeds(const Step sequence[][NUM_STEPS], int playbackStep, b
uint32_t cursorColor = pixels.Color(0, 0, 50); uint32_t cursorColor = pixels.Color(0, 0, 50);
if (isPlaying) { if (isPlaying) {
cursorColor = pixels.Color(0, 50, 0); cursorColor = pixels.Color(0, 50, 0);
if (songModeEnabled && s >= NUM_STEPS) { if (songModeEnabled && s >= 8) {
int repeats = min(songRepeatsRemaining, NUM_STEPS); int repeats = min(songRepeatsRemaining, 8);
if (x >= (NUM_STEPS - repeats)) cursorColor = (songRepeatsRemaining == 1 && x == 7 && (millis()/250)%2) ? pixels.Color(255, 200, 0) : pixels.Color(100, 220, 40); if (x >= (8 - repeats)) cursorColor = (songRepeatsRemaining == 1 && x == 7 && (millis()/250)%2) ? pixels.Color(255, 200, 0) : pixels.Color(100, 220, 40);
} }
} }
@ -426,39 +415,6 @@ void UIManager::updateLeds(const Step sequence[][NUM_STEPS], int playbackStep, b
} }
for(int i=0; i<4; i++) pixels.setPixelColor(getPixelIndex(x, yBase + i), c[i]); for(int i=0; i<4; i++) pixels.setPixelColor(getPixelIndex(x, yBase + i), c[i]);
} }
// --- Overview of all tracks on bottom 4 rows ---
for(int t=0; t<NUM_TRACKS; t++) {
int row = 4 + t;
int currentTrackSteps = numSteps[t];
for(int s=0; s<NUM_STEPS; s++) {
if (s >= currentTrackSteps) continue;
uint32_t pixelColor = 0;
// Background for active track
if (t == selectedTrack) {
pixelColor = COLOR_CURSOR_DIM;
}
else if (sequence[t][s].note != -1) // Note
{
pixelColor = getNoteColor(sequence[t][s].note, !sequence[t][s].accent);
}
// Playhead
if (isPlaying && (s == (playbackStep % currentTrackSteps))) {
if (t == selectedTrack) {
pixelColor = COLOR_CURSOR;
} else if (trackMute[t]) {
pixelColor = COLOR_MUTED_PLAYHEAD;
} else {
pixelColor = COLOR_PLAYHEAD;
}
}
pixels.setPixelColor(getPixelIndex(s, row), pixelColor);
}
}
} }
if (sequenceChangeScheduled && (millis() / 125) % 2) pixels.setPixelColor(NUM_PIXELS - 1, pixels.Color(127, 50, 0)); if (sequenceChangeScheduled && (millis() / 125) % 2) pixels.setPixelColor(NUM_PIXELS - 1, pixels.Color(127, 50, 0));
pixels.show(); pixels.show();

View File

@ -17,7 +17,7 @@ public:
void draw(UIState currentState, int menuSelection, void draw(UIState currentState, int menuSelection,
int midiChannel, int tempo, MelodyStrategy* currentStrategy, int midiChannel, int tempo, MelodyStrategy* currentStrategy,
int queuedTheme, int currentThemeIndex, int queuedTheme, int currentThemeIndex,
int numScaleNotes, const int* scaleNotes, int melodySeed, int currentTrackNumSteps, int numScaleNotes, const int* scaleNotes, int melodySeed, int numSteps,
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,
int randomizeTrack, const bool* trackMute, const int* trackIntensities); int randomizeTrack, const bool* trackMute, const int* trackIntensities);
@ -25,15 +25,16 @@ public:
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 selectedTrack, const int* numSteps, int numScaleNotes, const int* scaleNotes, const bool* trackMute); int selectedTrack, int numSteps, 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
void drawMenu(int selection, UIState currentState, int midiChannel, int tempo, const char* flavourName, void drawMenu(int selection, 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 currentTrackNumSteps, int numScaleNotes, const int* scaleNotes, int melodySeed, int numSteps,
bool mutationEnabled, bool songModeEnabled, bool isPlaying, int randomizeTrack, const bool* trackMute, const int* trackIntensities); bool mutationEnabled, bool songModeEnabled, bool isPlaying, int randomizeTrack, const bool* trackMute, const int* trackIntensities);
void drawNumberEditor(const char* title, int value, int minVal, int maxVal); void drawNumberEditor(const char* title, int value, int minVal, int maxVal);

View File

@ -44,11 +44,9 @@ void saveSequence(bool quiet) {
EEPROM.put(addr, mutes); addr += sizeof(mutes); EEPROM.put(addr, mutes); addr += sizeof(mutes);
EEPROM.put(addr, (int)tempo); addr += sizeof(int); EEPROM.put(addr, (int)tempo); addr += sizeof(int);
int intensities[NUM_TRACKS]; int intensities[NUM_TRACKS];
for(int i=0; i<NUM_TRACKS; i++) intensities[i] = (int)trackIntensity[i]; for(int i=0; i<NUM_TRACKS; i++) intensities[i] = trackIntensity[i];
EEPROM.put(addr, intensities); addr += sizeof(intensities); EEPROM.put(addr, intensities); addr += sizeof(intensities);
int steps[NUM_TRACKS]; EEPROM.put(addr, (int)numSteps); addr += sizeof(int);
for(int i=0; i<NUM_TRACKS; i++) steps[i] = numSteps[i];
EEPROM.put(addr, steps); addr += sizeof(steps);
EEPROM.put(addr, numScaleNotes); addr += sizeof(numScaleNotes); EEPROM.put(addr, numScaleNotes); addr += sizeof(numScaleNotes);
for (int i = 0; i<12; i++) { for (int i = 0; i<12; i++) {
@ -98,14 +96,9 @@ bool loadSequence() {
if (trackIntensity[i] < 1) trackIntensity[i] = 1; if (trackIntensity[i] < 1) trackIntensity[i] = 1;
if (trackIntensity[i] > 10) trackIntensity[i] = 10; if (trackIntensity[i] > 10) trackIntensity[i] = 10;
} }
int steps[NUM_TRACKS]; EEPROM.get(addr, t); addr += sizeof(int);
EEPROM.get(addr, steps); addr += sizeof(steps); numSteps = t;
for(int i=0; i<NUM_TRACKS; i++) { if (numSteps <= 0 || numSteps >= NUM_STEPS) numSteps = NUM_STEPS;
numSteps[i] = steps[i];
if (numSteps[i] <= 0 || numSteps[i] > NUM_STEPS) {
numSteps[i] = NUM_STEPS;
}
}
EEPROM.get(addr, numScaleNotes); addr += sizeof(numScaleNotes); EEPROM.get(addr, numScaleNotes); addr += sizeof(numScaleNotes);
if (numScaleNotes < 0 || numScaleNotes > 12) numScaleNotes = 0; if (numScaleNotes < 0 || numScaleNotes > 12) numScaleNotes = 0;
@ -131,9 +124,7 @@ static void savePatch(int bank, int slot) {
} }
EEPROM.put(addr, currentStrategyIndices); addr += sizeof(currentStrategyIndices); EEPROM.put(addr, currentStrategyIndices); addr += sizeof(currentStrategyIndices);
EEPROM.put(addr, melodySeeds); addr += sizeof(melodySeeds); EEPROM.put(addr, melodySeeds); addr += sizeof(melodySeeds);
int steps[NUM_TRACKS]; EEPROM.put(addr, (int)numSteps); addr += sizeof(int);
for(int i=0; i<NUM_TRACKS; i++) steps[i] = numSteps[i];
EEPROM.put(addr, steps); addr += sizeof(steps);
bool mutes[NUM_TRACKS]; bool mutes[NUM_TRACKS];
for(int i=0; i<NUM_TRACKS; i++) mutes[i] = trackMute[i]; for(int i=0; i<NUM_TRACKS; i++) mutes[i] = trackMute[i];
EEPROM.put(addr, mutes); addr += sizeof(mutes); EEPROM.put(addr, mutes); addr += sizeof(mutes);
@ -162,14 +153,10 @@ static void loadPatch(int bank, int slot) {
if (currentStrategyIndices[i] < 0 || currentStrategyIndices[i] >= numStrategies) currentStrategyIndices[i] = 0; if (currentStrategyIndices[i] < 0 || currentStrategyIndices[i] >= numStrategies) currentStrategyIndices[i] = 0;
} }
EEPROM.get(addr, melodySeeds); addr += sizeof(melodySeeds); EEPROM.get(addr, melodySeeds); addr += sizeof(melodySeeds);
int steps[NUM_TRACKS]; int t;
EEPROM.get(addr, steps); addr += sizeof(steps); EEPROM.get(addr, t); addr += sizeof(int);
for(int i=0; i<NUM_TRACKS; i++) { numSteps = t;
numSteps[i] = steps[i]; if (numSteps <= 0 || numSteps >= NUM_STEPS) numSteps = NUM_STEPS;
if (numSteps[i] <= 0 || numSteps[i] > NUM_STEPS) {
numSteps[i] = NUM_STEPS;
}
}
bool mutes[NUM_TRACKS]; bool mutes[NUM_TRACKS];
EEPROM.get(addr, mutes); addr += sizeof(mutes); EEPROM.get(addr, mutes); addr += sizeof(mutes);
@ -208,7 +195,7 @@ void factoryReset() {
static void generateTrackData(int track, int themeType, Step (*target)[NUM_STEPS]) { static void generateTrackData(int track, int themeType, Step (*target)[NUM_STEPS]) {
randomSeed(melodySeeds[track] + themeType * 12345); randomSeed(melodySeeds[track] + themeType * 12345);
strategies[currentStrategyIndices[track]]->generate(target, track, numSteps[track], scaleNotes, numScaleNotes, melodySeeds[track] + themeType * 12345, trackIntensity[track]); strategies[currentStrategyIndices[track]]->generate(target, track, numSteps, scaleNotes, numScaleNotes, melodySeeds[track] + themeType * 12345, trackIntensity[track]);
} }
void generateRandomScale() { void generateRandomScale() {
@ -242,11 +229,7 @@ void generateTheme(int themeType) {
} }
void mutateSequence(Step (*target)[NUM_STEPS]) { void mutateSequence(Step (*target)[NUM_STEPS]) {
for(int i=0; i<NUM_TRACKS; i++) { for(int i=0; i<NUM_TRACKS; i++) strategies[currentStrategyIndices[i]]->mutate(target, i, numSteps, scaleNotes, numScaleNotes, trackIntensity[i]);
if (random(100) < (trackIntensity[i] * 10)) {
strategies[currentStrategyIndices[i]]->mutate(target, i, numSteps[i], scaleNotes, numScaleNotes, trackIntensity[i]);
}
}
} }
static void handleInput() { static void handleInput() {
@ -285,9 +268,9 @@ static void handleInput() {
if (tempo > 240) tempo = 240; if (tempo > 240) tempo = 240;
break; break;
case UI_EDIT_STEPS: case UI_EDIT_STEPS:
numSteps[randomizeTrack] += delta; numSteps += delta;
if (numSteps[randomizeTrack] < 1) numSteps[randomizeTrack] = 1; if (numSteps < 1) numSteps = 1;
if (numSteps[randomizeTrack] > NUM_STEPS) numSteps[randomizeTrack] = NUM_STEPS; if (numSteps > NUM_STEPS) numSteps = NUM_STEPS;
break; break;
case UI_EDIT_FLAVOUR: case UI_EDIT_FLAVOUR:
{ {
@ -387,10 +370,6 @@ static void handleInput() {
case MENU_ID_MELODY: case MENU_ID_MELODY:
midi.lock(); midi.lock();
melodySeeds[randomizeTrack] = random(10000); melodySeeds[randomizeTrack] = random(10000);
randomSeed(melodySeeds[randomizeTrack]);
for (int i = 0; i < NUM_TRACKS; i++) {
numSteps[i] = random(1, NUM_STEPS + 1);
}
if (isPlaying) { if (isPlaying) {
int theme = (queuedTheme != -1) ? queuedTheme : currentThemeIndex; int theme = (queuedTheme != -1) ? queuedTheme : currentThemeIndex;
if (!sequenceChangeScheduled) { if (!sequenceChangeScheduled) {
@ -591,7 +570,7 @@ static void drawUI() {
// to avoid holding the lock during slow display operations. // to avoid holding the lock during slow display operations.
UIState local_currentState; UIState local_currentState;
int local_menuSelection, local_randomizeTrack, local_tempo, local_currentThemeIndex, local_queuedTheme, local_numScaleNotes; int local_menuSelection, local_randomizeTrack, local_tempo, local_currentThemeIndex, local_queuedTheme, local_numScaleNotes;
int local_melodySeed, local_currentTrackNumSteps; int local_melodySeed, local_numSteps;
bool local_mutationEnabled, local_songModeEnabled, local_isPlaying; bool local_mutationEnabled, local_songModeEnabled, local_isPlaying;
bool local_trackMute[NUM_TRACKS]; bool local_trackMute[NUM_TRACKS];
int local_midiChannel; int local_midiChannel;
@ -611,7 +590,7 @@ static void drawUI() {
} }
local_midiChannel = midiChannels[local_randomizeTrack]; local_midiChannel = midiChannels[local_randomizeTrack];
local_tempo = tempo; local_tempo = tempo;
local_currentTrackNumSteps = numSteps[local_randomizeTrack]; local_numSteps = numSteps;
local_strategy = strategies[currentStrategyIndices[local_randomizeTrack]]; local_strategy = strategies[currentStrategyIndices[local_randomizeTrack]];
local_queuedTheme = queuedTheme; local_queuedTheme = queuedTheme;
local_currentThemeIndex = currentThemeIndex; local_currentThemeIndex = currentThemeIndex;
@ -629,7 +608,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_currentTrackNumSteps, local_queuedTheme, local_currentThemeIndex, local_numScaleNotes, local_scaleNotes, local_melodySeed, local_numSteps,
local_mutationEnabled, local_songModeEnabled, (const Step (*)[NUM_STEPS])local_sequence, local_playbackStep, local_isPlaying, local_randomizeTrack, (const bool*)local_trackMute, (const int*)local_trackIntensities); local_mutationEnabled, local_songModeEnabled, (const Step (*)[NUM_STEPS])local_sequence, local_playbackStep, local_isPlaying, local_randomizeTrack, (const bool*)local_trackMute, (const int*)local_trackIntensities);
} }
@ -644,8 +623,8 @@ static void updateLeds() {
int local_songRepeatsRemaining; int local_songRepeatsRemaining;
bool local_sequenceChangeScheduled; bool local_sequenceChangeScheduled;
PlayMode local_playMode; PlayMode local_playMode;
int local_numScaleNotes; int local_numScaleNotes, local_numSteps;
int local_scaleNotes[12], local_numSteps[NUM_TRACKS]; int local_scaleNotes[12];
bool local_trackMute[NUM_TRACKS]; bool local_trackMute[NUM_TRACKS];
int local_randomizeTrack; int local_randomizeTrack;
@ -660,7 +639,7 @@ static void updateLeds() {
local_sequenceChangeScheduled = sequenceChangeScheduled; local_sequenceChangeScheduled = sequenceChangeScheduled;
local_playMode = playMode; local_playMode = playMode;
local_numScaleNotes = numScaleNotes; local_numScaleNotes = numScaleNotes;
for (int i = 0; i < NUM_TRACKS; i++) local_numSteps[i] = numSteps[i]; local_numSteps = numSteps;
local_randomizeTrack = randomizeTrack; 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));
@ -675,7 +654,7 @@ static void updateLeds() {
// 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;
} }
} else if (local_currentState == UI_EDIT_STEPS || local_currentState == UI_EDIT_FLAVOUR || local_currentState == UI_RANDOMIZE_TRACK_EDIT || local_currentState == UI_SCALE_EDIT || local_currentState == UI_SCALE_NOTE_EDIT || local_currentState == UI_SCALE_TRANSPOSE) { } else if (local_currentState == UI_EDIT_FLAVOUR || local_currentState == UI_RANDOMIZE_TRACK_EDIT || local_currentState == UI_SCALE_EDIT || local_currentState == UI_SCALE_NOTE_EDIT || local_currentState == UI_SCALE_TRANSPOSE) {
// These are entered from TRACK section items // These are entered from TRACK section items
ledDisplayMode = MODE_MONO; ledDisplayMode = MODE_MONO;
} }

View File

@ -16,7 +16,7 @@
#define ENC_SW 14 #define ENC_SW 14
// --- TRACKER DATA --- // --- TRACKER DATA ---
#define NUM_STEPS 16 #define NUM_STEPS 8
#define NUM_TRACKS 4 #define NUM_TRACKS 4
#define MIDI_DEBUG #define MIDI_DEBUG