#ifndef ARP_STRATEGY_H #define ARP_STRATEGY_H #include "MelodyStrategy.h" #include class ArpStrategy : 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. Select Subset int subsetSize = random(2, numScaleNotes + 1); if (subsetSize > 12) subsetSize = 12; int subset[12]; // Create indices to shuffle int indices[12]; for(int i=0; i= totalNotes) currentIndex = 0; } else if (mode == 1) { // Down currentIndex--; if (currentIndex < 0) currentIndex = totalNotes - 1; } else { // Up/Down currentIndex += direction; if (currentIndex >= totalNotes) { currentIndex = max(0, totalNotes - 2); direction = -1; } else if (currentIndex < 0) { currentIndex = min(totalNotes - 1, 1); direction = 1; } } } // 3. Fill Sequence for (int i = 0; i < numSteps; i++) { sequence[track][i] = arpPattern[i % arpLength]; } randomSeed(micros()); } void generateScale(int* scaleNotes, int& numScaleNotes) override { numScaleNotes = random(3, 13); // 3 to 12 notes for (int i = 0; i < 12; i++) { scaleNotes[i] = i; // Fill with all notes } // Shuffle 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) override { // Swap two notes int s1 = random(numSteps); int s2 = random(numSteps); if (sequence[track][s1].note != -1 && sequence[track][s2].note != -1) { int8_t temp = sequence[track][s1].note; sequence[track][s1].note = sequence[track][s2].note; sequence[track][s2].note = temp; } } const char* getName() override { return "Arp"; } }; #endif