Debian Codegraph @

examples/book/digital-artists/chapter5/Listing5.19.ck

raw
1 // Listing 5.19 Playing chords on an array of SinOsc UGens, using a function
2
3 // Sound Network
4 SinOsc chord[3]; // (1) Three oscillators for a chord
5
6 for (0 => int i; i < chord.cap(); i++)
7 {
8 // connect each element of our array to dac
9 chord[i] => dac; // (2) Connects them all to the dac...
10
11 // adjust gain so we don't overload
12 1.0/chord.cap() => chord[i].gain; // (3) ...and sets their gains so you don't overload.
13 }
14
15 fun void playChord(int root, string quality, dur howLong)
16 {
17 // set root of chord
18 Std.mtof(root) => chord[0].freq; // (4) Root of chord.
19
20 // set fifth of chord
21 Std.mtof(root+7) => chord[2].freq; // (5) Fifth of chord.
22
23 // third sets quality, major or minor
24 if (quality == "major")
25 {
26 Std.mtof(root+4) => chord[1].freq; // (6) Major chord.
27 }
28 else if (quality == "minor") {
29 Std.mtof(root+3) => chord[1].freq; // (7) Minor chord.
30 }
31 else
32 {
33 <<< "You must specify major or minor!!" >>>;
34 }
35 howLong => now;
36 }
37
38 <<< "This code makes no sound.", "Run Listing 5.20 to test and hear it!!" >>>;
39