Debian Codegraph @

examples/book/digital-artists/chapter9/DrumMachine/cowbell.ck

raw
1 // Listing 9.13 cowbell.ck plays only on last eighth note of measures, conducted by BPM
2 // cowbell.ck
3 // on the fly drumming with global BPM conducting
4 SndBuf cow => dac;
5 0.3 => cow.gain;
6 me.dir(-1)+"/audio/cowbell_01.wav" => cow.read;
7
8 // make a conductor for our tempo
9 // this is set and updated elsewhere
10 BPM tempo;
11
12 while (1) {
13 // update our basic beat each measure
14 tempo.eighthNote => dur eighth; // (1) Synchronizes on eighth notes.
15 // play measure of eighths
16 for (0 => int beat; beat < 8; beat++) { // (2) Measure is 8 total eighth notes.
17 // but only play on the last 8th
18 if (beat == 7) { // (3) Plays only on the last eighth note.
19 0 => cow.pos;
20 }
21 eighth => now; // (4) Advance time by eighth.
22 }
23 }