| 1 |
// Listing 9.15 clap.ck claps hands on random sixteenth notes, synced to BPM |
| 2 |
// clap.ck |
| 3 |
// on the fly drumming with global BPM conducting |
| 4 |
SndBuf clap => dac; |
| 5 |
0.3 => clap.gain; |
| 6 |
me.dir(-1)+"/audio/clap_01.wav" => clap.read; |
| 7 |
|
| 8 |
// make a conductor |
| 9 |
// this is set and controlled elsewhere |
| 10 |
BPM tempo; |
| 11 |
while (1) { |
| 12 |
// our basic beat for this instrument |
| 13 |
// update this every measure |
| 14 |
tempo.sixteenthNote => dur sixteenth; |
| 15 |
// play a whole measure of 16 16th notes |
| 16 |
for (0 => int beat; beat < 16; beat++) { |
| 17 |
// clap randomly on 16th notes |
| 18 |
if (Math.random2(0,7) < 3) { // (1) Random claps (3/8 probability)... |
| 19 |
0 => clap.pos; |
| 20 |
} |
| 21 |
sixteenth => now; // (2) ...on sixteenth notes |
| 22 |
} |
| 23 |
} |
| 24 |
|