Debian Codegraph @

examples/stk/saxofony.ck

raw
1 // STK Saxofony
2
3 // patch
4 Saxofony sax => JCRev r => dac;
5 .5 => r.gain;
6 .05 => r.mix;
7
8 // our notes
9 [ 61, 63, 65, 66, 68 ] @=> int notes[];
10
11 // infinite time-loop
12 while( true )
13 {
14 // set
15 Math.random2f( 0, 1 ) => sax.stiffness;
16 Math.random2f( 0, 1 ) => sax.aperture;
17 Math.random2f( 0, 1 ) => sax.noiseGain;
18 Math.random2f( 0, 1 ) => sax.blowPosition;
19 Math.random2f( 0, 12 ) => sax.vibratoFreq;
20 Math.random2f( 0, 1 ) => sax.vibratoGain;
21 Math.random2f( 0, 1 ) => sax.pressure;
22
23 // print
24 <<< "---", "" >>>;
25 <<< "stiffness:", sax.stiffness() >>>;
26 <<< "aperture:", sax.aperture() >>>;
27 <<< "noiseGain:", sax.noiseGain() >>>;
28 <<< "blowPosition:", sax.blowPosition() >>>;
29 <<< "vibratoFreq:", sax.vibratoFreq() >>>;
30 <<< "vibratoGain:", sax.vibratoGain() >>>;
31 <<< "pressure:", sax.pressure() >>>;
32
33 // factor
34 Math.random2f( .75, 2 ) => float factor;
35
36 for( int i; i < notes.size(); i++ )
37 {
38 play( 12 + notes[i], Math.random2f( .6, .9 ) );
39 300::ms * factor => now;
40 }
41 }
42
43 // basic play function (add more arguments as needed)
44 fun void play( float note, float velocity )
45 {
46 // start the note
47 Std.mtof( note ) => sax.freq;
48 velocity => sax.noteOn;
49 }