Debian Codegraph @

examples/book/digital-artists/chapter4/Listing4.11.ck

raw
1 // Listing 4.11 Using the modulo operator
2
3 // Modulo math for music
4 // by musical math dude, 11/11/11
5
6 // make and load a couple of SndBufs to "sonify" modulo
7 SndBuf clickhi => dac; // (1) Loads two different sound files
8 SndBuf clicklo => dac;
9 me.dir()+"/audio/click_02.wav" => clickhi.read;
10 me.dir()+"/audio/click_01.wav" => clicklo.read;
11
12 // define a number for our modulo
13 4 => int MOD; // (2) Modulo limit MOD
14
15 for (0 => int beat; beat < 24; beat++) { // (3) 24-beat "measure"
16 // print out beat and beat modulo MOD
17 <<< beat, "Modulo ", MOD, " is: ", beat % MOD >>>;
18
19 // click this on every beat
20 0 => clickhi.pos; // (4) High sound on every beat
21
22 // but only click this on every "MODth" beat
23 if (beat % MOD == 0) { // (5) Low sound only every MOD beat
24 0 => clicklo.pos;
25 }
26
27 0.5 :: second => now;
28 }