Debian Codegraph @

examples/book/digital-artists/chapter8/Listing8.5.ck

raw
1 // Listing 8.5 Jazz band:
2 // save as "piano.ck"
3 // sound chain
4 Rhodey piano[4]; // (1) Four notes' worth of electric piano
5
6 piano[0] => dac.left; // (2) Connects them to left...
7 piano[1] => dac; // ...and center...
8 piano[2] => dac;
9 piano[3] => dac.right; // (3) ...and right dac channels.
10
11 // chord 2D array // (4) Array to hold two chords of four notes each.
12 [[53,57,60,64],[51,55,60,63]] @=> int chordz[][];
13
14 // loop
15 while( true ) // (5) Infinite loop
16 {
17 // build first chord
18 for( 0 => int i; i < 4; i++ )
19 { // (6) Plays first chord...
20 Std.mtof(chordz[0][i]) => piano[i].freq;
21 Math.random2f(0.3,.7) => piano[i].noteOn;
22 }
23 1.0 :: second => now;
24 // build second chord
25 for( 0 => int i; i < 4; i++ )
26 { // (7) ...then second chord
27 Math.mtof(chordz[1][i]) => piano[i].freq;
28 Math.random2f(0.3,.7) => piano[i].noteOn;
29 }
30 1.4 :: second => now;
31 }