Debian Codegraph @

examples/book/digital-artists/chapter7/Listing7.15.ck

raw
1 // Listing 7.15 Using the HevyMetl FM UGen to synthesize an electric guitar
2
3 // a brief FM electric guitar tribute
4 HevyMetl jimi => PRCRev r => dac; // (1) FM "guitar" through reverb...
5 jimi => Delay d => d => r; // (2) ...and a delay line (for big, outdoor sound)
6 0.3 => d.gain;
7 1.2 :: second => d.max => d.delay;
8
9 // sets us up for whammy bar bend later
10 0.5 => jimi.lfoSpeed;
11
12 // (3) Table of notes, durations, and modulations
13 [[70.0,0.8,0.0],[67.0,0.4,0.0],[63.0,1.2,0.0],
14 [67.0,1.2,0.0],[70.0,1.2,0.0],[75.0,2.4,0.2],
15 [79.0,0.8,0.0],[77.0,0.4,0.0],[75.0,1.2,0.0],
16 [67.0,1.2,0.1],[69.0,1.2,0.2]] @=> float banner[][];
17
18 // play through our data table first
19 0 => int i;
20 while (i < banner.cap()) { // (4) Plays all the notes in the table
21 banner[i][2] => jimi.lfoDepth;
22 pick(banner[i][0],banner[i][1]);
23 1 +=> i;
24 }
25
26 // play last note longer, then
27 Std.mtof(82) => jimi.freq;
28 1 => jimi.noteOn;
29 2.0 :: second => now;
30
31 // go nuts and sweep frequency downward
32 while (jimi.freq() > 100.0) { // (5) Big gliss (pitch sweep) downward
33 0.98 * jimi.freq() => jimi.freq;
34 0.01 :: second => now;
35 }
36 1.0 :: second => now;
37
38 1 => jimi.noteOff;
39 2.0 :: second => now;
40
41 // function to play a note for a duration
42 fun void pick(float note,float howLong) { // (6) Function to pick each note
43 Std.mtof(note) => jimi.freq;
44 1 => jimi.noteOn;
45 (howLong - 0.1) :: second => now;
46 1 => jimi.noteOff;
47 0.1 :: second => now;
48 }