*** empty log message ***
[chuck-blob.git] / v2 / examples / stk / wurley3.ck
blobe46570b94958426f0d0e28f404936755a5ae7173
1 // polyphonic wurley's
2 // (also see ../midi/polyfony.ck for more polyfony)
4 // the size of the array should be the max number of wurlies
5 // you want to play simultaneously, at any point.
6 Wurley wurlies[3];
7 // variable to remember the last one played
8 int which;
10 // patch
11 Gain g => dac;
12 .4 => g.gain;
13 // connect the wurlies
14 for( int i; i < wurlies.cap(); i++ )
15     wurlies[i] => g;
17 // our notes
18 [ 61, 63, 65, 66, 68 ] @=> int notes[];
20 // infinite time-loop
21 while( true )
23     for( int i; i < notes.cap(); i++ )
24     {
25         play( notes[i], Std.rand2f( .3, .9 ) );
26         300::ms => now;
27     }
30 // basic play function (add more arguments as needed)
31 fun void play( float note, float velocity )
33     // first figure which to play
34     // round robin may work
35     ( which + 1 ) % wurlies.cap() => which;
37     // start the note
38     Std.mtof( note ) => wurlies[which].freq;
39     velocity => wurlies[which].noteOn;