Debian Codegraph @

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

raw
1 // Listing 5.13 Using the arrayAdder() function to convert a scale from minor to major
2
3 // make a mandolin and hook it to audio out
4 Mandolin mand => dac; // (1) Mandolin instrument.
5
6 // global scale array // (2) Scale array of note numbers.
7 [60,62,63,65,67,69,70,72] @=> int scale[];
8
9 // function to modify an element of an array
10 fun void arrayAdder( int temp[], int index)
11 { // (3) arrayAdder function definition.
12 1 +=> temp[index];
13 }
14
15 //play scale on mandolin
16 fun void playScale(int temp[]) { // (4) playScale function definition.
17 for (0 => int i; i < temp.cap(); i++)
18 {
19 Std.mtof(temp[i]) => mand.freq;
20 <<< i, temp[i] >>>;
21 1 => mand.noteOn;
22 0.4 :: second => now;
23 }
24 second => now;
25 }
26
27 // play our scale on our mandolin
28 <<< "Original Scale" >>>;
29 playScale(scale); // (5) Tests playScale.
30
31 // modify our scale
32 arrayAdder(scale,2); // (6) Call arrayAdder to change two elements.
33 arrayAdder(scale,6);
34
35 // play scale again, sounds different, huh?
36 <<< "Modified Scale:" >>>;
37 playScale(scale); // (7) When we call playScale again. It's different!