Debian Codegraph @

examples/stk/wurley3.ck

raw
1 // polyphonic wurley's
2 // (also see ../midi/polyfony.ck for more polyfony)
3
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;
9
10 // patch
11 Gain g => dac;
12 .4 => g.gain;
13 // connect the wurlies
14 for( int i; i < wurlies.size(); i++ )
15 wurlies[i] => g;
16
17 // our notes
18 [ 61, 63, 65, 66, 68 ] @=> int notes[];
19
20 // infinite time-loop
21 while( true )
22 {
23 for( int i; i < notes.size(); i++ )
24 {
25 play( notes[i], Math.random2f( .3, .9 ) );
26 300::ms => now;
27 }
28 }
29
30 // basic play function (add more arguments as needed)
31 fun void play( float note, float velocity )
32 {
33 // first figure which to play
34 // round robin may work
35 ( which + 1 ) % wurlies.size() => which;
36
37 // start the note
38 Std.mtof( note ) => wurlies[which].freq;
39 velocity => wurlies[which].noteOn;
40 }