#ifndef CELLULAR_AUTOMATA_STRATEGY_H #define CELLULAR_AUTOMATA_STRATEGY_H #include "MelodyStrategy.h" #include class CellularAutomataStrategy : public MelodyStrategy { public: void generate(Step (*sequence)[NUM_STEPS], int track, int numSteps, int* scaleNotes, int numScaleNotes, int seed) override { randomSeed(seed); if (numScaleNotes == 0) return; // 1. Setup CA // Pick a rule. Some rules are more musical (structured chaos) than others. // Rule 30, 90, 110, 184 are classics. Random is fun too. uint8_t rule = random(256); bool cells[NUM_STEPS]; bool next_cells[NUM_STEPS]; // Init: 50% chance of single center seed, 50% random noise if (random(2) == 0) { for(int i=0; i> pattern) & 1; } for(int i=0; i> pattern) & 1; if (alive) { if (center) { // Survived: Keep note next_seq[i] = sequence[track][i]; } else { // Born: New note int octave = 3 + random(3); next_seq[i].note = 12 * octave + scaleNotes[random(numScaleNotes)]; next_seq[i].accent = (random(100) < 30); next_seq[i].tie = false; } } else { // Died next_seq[i].note = -1; next_seq[i].accent = false; next_seq[i].tie = false; } } for(int i=0; i