Debian Codegraph @

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

raw
1 // Listing 8.8 Jazz band:
2 // save as "flute.ck"
3
4 // Our famous headliner flute solo (with EFX)
5 Flute solo => JCRev rev => dac; // (1) Flute soloist through reverb...
6 0.1 => rev.mix;
7 solo => Delay d => d => rev; // (2) ...also through a delay line.
8 0.8 :: second => d.max => d.delay; // (3) Sets delay to 0.8 seconds.
9 0.5 => d.gain;
10 0.5 => solo.gain;
11
12 // jazz scale data
13 [41,43,45,48,50,51,53,60,63] @=> int scale[]; // (4) Jazz scale array.
14
15 // then our main loop headliner flute soloist
16 while (1) { // (5) Infinite loop.
17 // (6) Waits either 0.2, 0.4, 0.6, 0.8, or 1.0 seconds.
18 (Math.random2(1,5) * 0.2) :: second => now;
19 if (Math.random2(0,3) > 1) { // (7) Occasionally (50% of time)
20 Math.random2(0,scale.cap()-1) => int note; // picks a new note...
21 Math.mtof(24+scale[note])=> solo.freq;
22 Math.random2f(0.3,1.0) => solo.noteOn;
23 }
24 else 1 => solo.noteOff; // (8) ...otherwise turns note off.
25 }