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
+14 -5
View File
@@ -6,7 +6,7 @@
class DroneStrategy : 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;
@@ -30,8 +30,12 @@ public:
// Pick a note from the scale
// Prefer lower octaves for drones (3 and 4)
int octave = 3 + random(2);
int noteIndex = random(numScaleNotes);
int note = 12 * octave + scaleNotes[noteIndex];
int note;
if (numChordNotes > 0) {
note = 12 * octave + chordNotes[random(numChordNotes)];
} else {
note = 12 * octave + scaleNotes[random(numScaleNotes)];
}
for (int k = 0; k < duration; k++) {
int stepIndex = currentStep + k;
@@ -65,7 +69,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 {
// Mutate by shifting the pitch of a random segment
int s = random(numSteps);
if (sequence[track][s].note != -1) {
@@ -83,7 +87,12 @@ public:
// Pick a new note
int octave = 3 + random(2);
int newNote = 12 * octave + scaleNotes[random(numScaleNotes)];
int newNote;
if (numChordNotes > 0) {
newNote = 12 * octave + chordNotes[random(numChordNotes)];
} else {
newNote = 12 * octave + scaleNotes[random(numScaleNotes)];
}
for (int i = start; i <= end; i++) {
sequence[track][i].note = newNote;