Debian Codegraph @

examples/book/digital-artists/chapter9/DrumMachine/Listing9.16.ck

raw
1 // Listing 9.16 score.ck controls individual players and tempo via BPM
2 // score.ck, on the fly drumming with global BPM conducting
3 // Here we make our BPM instance that controls tempo
4 BPM tempo; // (1) Makes a global BPM to control from here.
5 tempo.tempo(120.0);
6
7 // Add in instruments one at a time, musically
8 Machine.add(me.dir()+"/kick.ck") => int kickID; // (2) Adds instruments one at a time.
9
10 8.0 * tempo.quarterNote => now;
11
12 Machine.add(me.dir()+"/snare.ck") => int snareID;
13
14 8.0 * tempo.quarterNote => now;
15
16 Machine.add(me.dir()+"/hihat.ck") => int hatID;
17 Machine.add(me.dir()+"/cowbell.ck") => int cowID;
18
19 8.0 * tempo.quarterNote => now;
20
21 Machine.add(me.dir()+"/clap.ck") => int clapID;
22
23 8.0 * tempo.quarterNote => now;
24
25 // now have some fun with tempo
26 <<< "Set tempo to 80BPM" >>>;
27 80.0 => float newtempo; // (3) Changes tempo to 80 BPM...
28
29 tempo.tempo(newtempo);
30 8.0 * tempo.quarterNote => now;
31
32 <<< "Now set tempo to 160BPM" >>>;
33 160.0 => newtempo; // (4) then changes it to 160 BPM.
34 tempo.tempo(newtempo);
35 8.0 * tempo.quarterNote => now;
36
37 /* if you want to run OTFBPM.ck to change tempo
38 as these run, then comment out the lines below */
39
40 <<< "Gradually decrease tempo" >>>;
41 while (newtempo > 60.0) { // (5) Gradually moves tempo down.
42
43 newtempo - 20 => newtempo;
44 tempo.tempo(newtempo);
45 <<< "tempo = ", newtempo >>>;
46 4.0 * tempo.quarterNote => now;
47 }
48
49 // bring out the instruments, gradually
50 Machine.remove(kickID); // (6) Pulls out instruments one at a time
51
52 8.0 * tempo.quarterNote => now;
53 Machine.remove(snareID);
54 Machine.remove(hatID);
55
56 8.0 * tempo.quarterNote => now;
57 Machine.remove(cowID);
58
59 8.0 * tempo.quarterNote => now;
60 Machine.remove(clapID);