Debian Codegraph @

examples/stk/clarinet2.ck

raw
1 // STK Clarinet
2 // (also see examples/event/polyfony2.ck)
3
4 // patch
5 Clarinet clair => JCRev r => dac;
6 .75 => r.gain;
7 .1 => r.mix;
8
9 // our notes
10 [ 61, 63, 65, 66, 68, 66, 65, 63, 61 ] @=> int notes[];
11
12 // infinite time-loop
13 while( true )
14 {
15 Math.random2f( 64, 128 ) => float stiffness;
16 Math.random2f( 0, 128 ) => float noisegain;
17 Math.random2f( 0, 128 ) => float vibratofreq;
18 Math.random2f( 0, 128 ) => float vibratogain;
19 Math.random2f( 64, 128 ) => float pressure;
20
21 <<< "---", "" >>>;
22 <<< "reed stiffness:", stiffness >>>;
23 <<< "noise gain:", noisegain >>>;
24 <<< "vibrato freq:", vibratofreq >>>;
25 <<< "vibrato gain:", vibratogain >>>;
26 <<< "breath pressure:", pressure >>>;
27
28 // clear
29 clair.clear( 1.0 );
30
31 // reed stiffness
32 clair.controlChange( 2, stiffness );
33 // noise gain
34 clair.controlChange( 4, noisegain );
35 // vibrato freq
36 clair.controlChange( 11, vibratofreq );
37 // vibrato gain
38 clair.controlChange( 1, vibratogain );
39 // breath pressure
40 clair.controlChange( 128, pressure );
41
42 for( int i; i < notes.size(); i++ )
43 {
44 play( 12 + notes[i], Math.random2f( .6, .9 ) );
45 300::ms => now;
46 }
47 }
48
49 // basic play function (add more arguments as needed)
50 fun void play( float note, float velocity )
51 {
52 // start the note
53 Std.mtof( note ) => clair.freq;
54 velocity => clair.noteOn;
55 }