More harmony through chord notes
This commit is contained in:
+11
-7
@@ -29,9 +29,13 @@ const uint8_t numRuleSets = sizeof(ruleSets) / sizeof(RuleSet);
|
||||
|
||||
class LSystemStrategy : 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) {
|
||||
|
||||
int* sourceNotes = (numChordNotes > 0) ? chordNotes : scaleNotes;
|
||||
int sourceNoteCount = (numChordNotes > 0) ? numChordNotes : numScaleNotes;
|
||||
|
||||
if (sourceNoteCount == 0) {
|
||||
// Fill with silence if no scale
|
||||
for (int i = 0; i < numSteps; i++) {
|
||||
sequence[track][i].note = -1;
|
||||
@@ -68,7 +72,7 @@ public:
|
||||
|
||||
// 2. Interpret the string to create the sequence
|
||||
int stepIndex = 0;
|
||||
int noteIndex = random(numScaleNotes);
|
||||
int noteIndex = random(sourceNoteCount);
|
||||
int octave = 4;
|
||||
|
||||
// Stack for branching rules
|
||||
@@ -86,16 +90,16 @@ public:
|
||||
|
||||
switch(c) {
|
||||
case 'F': case 'G': case 'A': case 'B': // Characters that draw notes
|
||||
sequence[track][stepIndex].note = 12 * octave + scaleNotes[noteIndex];
|
||||
sequence[track][stepIndex].note = 12 * octave + sourceNotes[noteIndex];
|
||||
sequence[track][stepIndex].accent = (random(100) < accentChance);
|
||||
sequence[track][stepIndex].tie = (random(100) < tieChance);
|
||||
stepIndex++;
|
||||
break;
|
||||
case '+': // Go up in scale
|
||||
noteIndex = (noteIndex + 1) % numScaleNotes;
|
||||
noteIndex = (noteIndex + 1) % sourceNoteCount;
|
||||
break;
|
||||
case '-': // Go down in scale
|
||||
noteIndex = (noteIndex - 1 + numScaleNotes) % numScaleNotes;
|
||||
noteIndex = (noteIndex - 1 + sourceNoteCount) % sourceNoteCount;
|
||||
break;
|
||||
case '[': // Push current state
|
||||
if(stack_ptr < 8) {
|
||||
@@ -140,7 +144,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 non-rest steps to create a variation
|
||||
int s1 = random(numSteps);
|
||||
int s2 = random(numSteps);
|
||||
|
||||
Reference in New Issue
Block a user