| 1 |
// Listing 8.3 Controlling different aspects of a single global object using concurrency |
| 2 |
|
| 3 |
// sound chain |
| 4 |
ModalBar modal => NRev reverb => dac; // (1) Modal bar through reverb to dac |
| 5 |
|
| 6 |
// set reverb mix |
| 7 |
.1 => reverb.mix; |
| 8 |
|
| 9 |
// modal bar parameters |
| 10 |
7 => modal.preset; |
| 11 |
.9 => modal.strikePosition; |
| 12 |
|
| 13 |
// spork detune() as a child shred |
| 14 |
// note: must do this before entering into infinite loop below! |
| 15 |
spork ~ detune(); // (2) Sporks a function called detune() |
| 16 |
|
| 17 |
// infinite time loop |
| 18 |
while( true ) |
| 19 |
{ |
| 20 |
// first note! then wait |
| 21 |
1 => modal.strike; // (3) Play notes (strike bar). |
| 22 |
250::ms => now; |
| 23 |
.7 => modal.strike; // another note! then wait |
| 24 |
250::ms => now; |
| 25 |
.9 => modal.strike; // one more note! then wait |
| 26 |
250::ms => now; |
| 27 |
repeat( 4 ) // now play four quick notes |
| 28 |
{ |
| 29 |
// note! and wait |
| 30 |
.5 => modal.strike; |
| 31 |
62.5::ms => now; |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
// function to vary tuning over time |
| 36 |
fun void detune() // (4) detune function definition. |
| 37 |
{ |
| 38 |
while( true ) // infinite loop |
| 39 |
{ |
| 40 |
// update frequency sinusoidally |
| 41 |
84 + Math.sin(now/second*.25*Math.PI) * 2 => Std.mtof => modal.freq; |
| 42 |
// advance time (controls update rate) |
| 43 |
5::ms => now; |
| 44 |
} |
| 45 |
} |