More harmony through chord notes

This commit is contained in:
Dejvino
2026-03-10 21:58:03 +01:00
parent f34f960358
commit aa51e1e95a
13 changed files with 269 additions and 242 deletions
+25 -21
View File
@@ -6,30 +6,34 @@
class ArpStrategy : public MelodyStrategy {
public:
void generate(Step (*sequence)[NUM_STEPS], int track, int numSteps, int* scaleNotes, int numScaleNotes, int seed, int intensity) override {
void generate(Step (*sequence)[NUM_STEPS], int track, int numSteps, int* scaleNotes, int numScaleNotes, int* chordNotes, int numChordNotes, int seed, int intensity) 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<numScaleNotes; i++) indices[i] = i;
// Shuffle indices
for(int i=0; i<numScaleNotes; i++) {
int r = random(numScaleNotes);
int temp = indices[i];
indices[i] = indices[r];
indices[r] = temp;
}
// Pick subset
for(int i=0; i<subsetSize; i++) {
subset[i] = scaleNotes[indices[i]];
int subsetSize = 0;
// Prioritize chord notes for the arpeggio
if (numChordNotes > 0) {
subsetSize = numChordNotes;
for (int i = 0; i < subsetSize; i++) {
subset[i] = chordNotes[i];
}
} else {
// Fallback to a random subset of the scale if no chord notes are available
subsetSize = random(2, numScaleNotes + 1);
if (subsetSize > 12) subsetSize = 12;
int indices[12];
for(int i=0; i<numScaleNotes; i++) indices[i] = i;
for(int i=0; i<numScaleNotes; i++) {
int r = random(numScaleNotes);
int temp = indices[i];
indices[i] = indices[r];
indices[r] = temp;
}
for(int i=0; i<subsetSize; i++) {
subset[i] = scaleNotes[indices[i]];
}
}
sortArray(subset, subsetSize);
@@ -111,7 +115,7 @@ public:
sortArray(scaleNotes, numScaleNotes);
}
void mutate(Step (*sequence)[NUM_STEPS], int track, int numSteps, int* scaleNotes, int numScaleNotes, int intensity) override {
void mutate(Step (*sequence)[NUM_STEPS], int track, int numSteps, int* scaleNotes, int numScaleNotes, int* chordNotes, int numChordNotes, int intensity) override {
// Swap two notes
int s1 = random(numSteps);
int s2 = random(numSteps);