| 1 |
// Listing 5.18 Recursive drum roll using only an Impulse UGen |
| 2 |
|
| 3 |
Impulse imp => dac; // (1) Impulse (click) generator to dac. |
| 4 |
|
| 5 |
fun int impRoll(int index) { // (2) impRoll function definition. |
| 6 |
if (index >=1) |
| 7 |
{ |
| 8 |
1.0 => imp.next; |
| 9 |
index::ms => now; // (3) Duration is the recursion variable. |
| 10 |
return impRoll(index-1); // (4) Recursive call from impRoll to impRoll. |
| 11 |
} |
| 12 |
else { |
| 13 |
return 0; |
| 14 |
} |
| 15 |
} |
| 16 |
|
| 17 |
impRoll(20); // (5) Tests all with different starting durations. |
| 18 |
second => now; |
| 19 |
|
| 20 |
impRoll(40); |
| 21 |
second => now; |
| 22 |
|
| 23 |
impRoll(60); |
| 24 |
second => now; |