-
-
Save zeffii/7646068 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//arpeggiator with beat | |
Gain master[3]; | |
SawOsc mel => Pan2 panmel => master[1]; | |
SinOsc mel2 => Pan2 panmel2 => master[1]; | |
master[0] => dac.left; | |
master[1] => dac; | |
master[2] => dac.right; | |
0=> mel.gain; | |
0=> mel2.gain; | |
TriOsc chord[4]; | |
for( 0 => int i; i < chord.cap(); i++) | |
{ | |
chord[i] => master[1] => dac; | |
0 => chord[i].gain; | |
} | |
// I didn't use many of these chord qualities, but the idea is I could reuse this function for other pieces. | |
fun void playChord(int root, string quality, float chordGain, int chordTone) | |
{ | |
Std.mtof(root) => chord[0].freq; | |
if (quality == "major7") | |
{ | |
Std.mtof(root+4) => chord[1].freq; | |
Std.mtof(root+7) => chord[2].freq; | |
Std.mtof(root+11) => chord[3].freq; | |
} | |
if (quality == "major") | |
{ | |
Std.mtof(root+4) => chord[1].freq; | |
Std.mtof(root+7) => chord[2].freq; | |
Std.mtof(root+12) => chord[3].freq; | |
} | |
if (quality == "dominant") | |
{ | |
Std.mtof(root+4) => chord[1].freq; | |
Std.mtof(root+7) => chord[2].freq; | |
Std.mtof(root+10) => chord[3].freq; | |
} | |
if (quality == "minor") | |
{ | |
Std.mtof(root+3) => chord[1].freq; | |
Std.mtof(root+7) => chord[2].freq; | |
Std.mtof(root+10) => chord[3].freq; | |
} | |
if (quality == "minor7") | |
{ | |
Std.mtof(root+3) => chord[1].freq; | |
Std.mtof(root+7) => chord[2].freq; | |
Std.mtof(root+10) => chord[3].freq; | |
} | |
if (quality == "minormajor7") | |
{ | |
Std.mtof(root+3) => chord[1].freq; | |
Std.mtof(root+7) => chord[2].freq; | |
Std.mtof(root+11) => chord[3].freq; | |
} | |
if (quality == "dim7") | |
{ | |
Std.mtof(root+3) => chord[1].freq; | |
Std.mtof(root+6) => chord[2].freq; | |
Std.mtof(root+9) => chord[3].freq; | |
} | |
for( 0 => int i; i < chord.cap(); i++) | |
{ | |
0 => chord[i].gain; | |
} | |
chordGain => chord[chordTone].gain; | |
<<<chord[0].gain(), chord[1].gain(), chord[2].gain(), chord[3].gain()>>>; | |
} | |
//generated arpeggiated patterns | |
fun void arpeggiator(int root, string quality, float chordGain, int pattern, int i) | |
{ | |
if (pattern == 1) | |
{ | |
i % 4 => int chordTone; | |
playChord(root, quality, chordGain, chordTone); | |
} | |
else if (pattern == 2) | |
{ | |
(i + 2) %4 => int chordTone; | |
playChord(root, quality, chordGain, chordTone); | |
} | |
else if (pattern == 3) | |
{ | |
(3- (i%4)) =>int chordTone; | |
playChord(root, quality, chordGain, chordTone); | |
} | |
else if (pattern == 4) | |
{ | |
math.random2(0,3) => int chordTone; | |
playChord(root, quality, chordGain, chordTone); | |
} | |
} | |
// Drumbeat and form | |
for(0=>int i; i < 64; i++) | |
{ | |
arpeggiator(60, "minormajor7", .2, math.random2(1, 4), i); | |
.2::second => now; | |
for (0=> int j; j< chord.cap(); j++) | |
{ | |
0 => chord[j].gain; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment