| 1 |
// ChucK global event to wait on |
| 2 |
global Event the_nextNote; |
| 3 |
// ChucK global int to get pitch index |
| 4 |
global float the_frequency; |
| 5 |
|
| 6 |
// patch |
| 7 |
Blit s => ADSR e => JCRev r => dac; |
| 8 |
.5 => s.gain; |
| 9 |
.05 => r.mix; |
| 10 |
|
| 11 |
// set adsr |
| 12 |
e.set( 5::ms, 3::ms, .5, 5::ms ); |
| 13 |
|
| 14 |
// an array |
| 15 |
[ 0, 2, 4, 7, 9, 11 ] @=> int hi[]; |
| 16 |
|
| 17 |
// infinite time loop |
| 18 |
while( true ) |
| 19 |
{ |
| 20 |
// frequency |
| 21 |
Std.mtof( 33 + Math.random2(0,3) * 12 + |
| 22 |
hi[Math.random2(0,hi.size()-1)] ) => s.freq; |
| 23 |
// copy to global |
| 24 |
s.freq() => the_frequency; |
| 25 |
|
| 26 |
// harmonics |
| 27 |
Math.random2( 1, 5 ) => s.harmonics; |
| 28 |
|
| 29 |
// key on |
| 30 |
e.keyOn(); |
| 31 |
// wait on event |
| 32 |
the_nextNote => now; |
| 33 |
// key off |
| 34 |
e.keyOff(); |
| 35 |
// advance time for release |
| 36 |
5::ms => now; |
| 37 |
} |