#ifndef ISORHYTHM_STRATEGY_H #define ISORHYTHM_STRATEGY_H #include "MelodyStrategy.h" #include class IsorhythmStrategy : public MelodyStrategy { public: void generate(Step (*sequence)[NUM_STEPS], int track, int numSteps, int* scaleNotes, int numScaleNotes, int seed, int intensity) override { randomSeed(seed); if (numScaleNotes == 0) return; // 1. Create the Color (pitch pattern) // Intensity affects color length. Higher intensity = longer, more complex color. int colorLength = 2 + random(intensity + 2); // 2 to intensity+3 notes if (colorLength > numScaleNotes) colorLength = numScaleNotes; if (colorLength > 8) colorLength = 8; // Keep it reasonable int color[8]; // Pick unique notes from the scale for the color int scaleIndices[12]; for(int i=0; i numSteps) taleaLength = numSteps; bool talea[NUM_STEPS]; int pulses = 2 + random(taleaLength - 2); // At least 2 pulses // Euclidean distribution for a nice rhythm int bucket = 0; for(int i=0; i= taleaLength) { bucket -= taleaLength; talea[i] = true; } else { talea[i] = false; } } // 3. Apply Color and Talea to the sequence int colorIdx = 0; for (int i = 0; i < numSteps; i++) { int taleaIdx = i % taleaLength; if (talea[taleaIdx]) { int octave = 3 + random(3); int noteScaleIndex = color[colorIdx % colorLength]; sequence[track][i].note = 12 * octave + scaleNotes[noteScaleIndex]; sequence[track][i].accent = (i % 4 == 0); // Accent on downbeats sequence[track][i].tie = false; colorIdx++; } else { sequence[track][i].note = -1; sequence[track][i].accent = false; sequence[track][i].tie = false; } } randomSeed(micros()); } void generateScale(int* scaleNotes, int& numScaleNotes) override { numScaleNotes = random(5, 8); for (int i = 0; i < 12; i++) scaleNotes[i] = i; for (int i = 0; i < 12; i++) { int j = random(12); int temp = scaleNotes[i]; scaleNotes[i] = scaleNotes[j]; scaleNotes[j] = temp; } sortArray(scaleNotes, numScaleNotes); } void mutate(Step (*sequence)[NUM_STEPS], int track, int numSteps, int* scaleNotes, int numScaleNotes, int intensity) override { // Mutation: rotate the talea (rhythmic displacement) int rotation = random(1, numSteps); Step temp[NUM_STEPS]; for(int i=0; i