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
+17 -14
View File
@@ -6,28 +6,31 @@
class IsorhythmStrategy : 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;
int* sourceNotes = (numChordNotes > 0) ? chordNotes : scaleNotes;
int sourceNoteCount = (numChordNotes > 0) ? numChordNotes : numScaleNotes;
if (sourceNoteCount == 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 > sourceNoteCount) colorLength = sourceNoteCount;
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<numScaleNotes; i++) scaleIndices[i] = i;
for(int i=0; i<numScaleNotes; i++) { // shuffle
int r = random(numScaleNotes);
int temp = scaleIndices[i];
scaleIndices[i] = scaleIndices[r];
scaleIndices[r] = temp;
int indices[12];
for(int i=0; i<sourceNoteCount; i++) indices[i] = i;
for(int i=0; i<sourceNoteCount; i++) { // shuffle
int r = random(sourceNoteCount);
int temp = indices[i];
indices[i] = indices[r];
indices[r] = temp;
}
for(int i=0; i<colorLength; i++) {
color[i] = scaleIndices[i];
color[i] = sourceNotes[indices[i]];
}
// 2. Create the Talea (rhythmic pattern)
@@ -56,8 +59,8 @@ public:
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];
int noteValue = color[colorIdx % colorLength];
sequence[track][i].note = 12 * octave + noteValue;
sequence[track][i].accent = (i % 4 == 0); // Accent on downbeats
sequence[track][i].tie = false;
colorIdx++;
@@ -82,7 +85,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 {
// Mutation: rotate the talea (rhythmic displacement)
int rotation = random(1, numSteps);
Step temp[NUM_STEPS];