Debian Codegraph @

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

raw
1 // Listing 9.14 hihat.ck plays on all eighth notes except the last, synced to BPM
2 // hihat.ck
3 // on the fly drumming with global BPM conducting
4 SndBuf hat => dac;
5 0.3 => hat.gain;
6 me.dir(-1)+"/audio/hihat_02.wav" => hat.read;
7
8 // make a conductor for our tempo
9 // this is set and updated elsewhere
10 BPM tempo;
11 while (1) {
12 // update our basic beat each measure
13 tempo.eighthNote => dur eighth;
14 // play a measure of eighth notes
15 for (0 => int beat; beat < 8; beat++) {
16 // play mostly, but leave out last eighth
17 if (beat != 7) { // (1) Plays all eighths except the last one
18 0 => hat.pos; // (the anti-cowbell)
19 }
20 eighth => now;
21 }
22 }