Debian Codegraph @

examples/stk/shake-o-matic.ck

raw
1 //---------------|
2 // shake-o-matic!
3 // by: Ge Wang ([email protected])
4 // Perry R. Cook ([email protected])
5 //------------------|
6
7 // our patch
8 Shakers shake => JCRev r => dac;
9 // set the gain
10 //.95 => r.gain;
11 // set the reverb mix
12 .025 => r.mix;
13
14 // our main loop
15 while( true )
16 {
17 // frequency..
18 // note: Math.randomf() returns value between 0 and 1
19 if( Math.randomf() > 0.625 )
20 {
21 Math.random2( 0, 22 ) => shake.which;
22 Std.mtof( Math.random2f( 0.0, 128.0 ) ) => shake.freq;
23 Math.random2f( 0, 128 ) => shake.objects;
24 <<< "instrument #:", shake.which(), shake.freq(), shake.objects() >>>;
25 }
26
27 // shake it!
28 Math.random2f( 0.8, 1.3 ) => shake.noteOn;
29
30 // note: Math.randomf() returns value between 0 and 1
31 if( Math.randomf() > 0.9 )
32 { 500::ms => now; }
33 else if( Math.randomf() > .925 )
34 { 250::ms => now; }
35 else if( Math.randomf() > .05 )
36 { .125::second => now; }
37 else
38 {
39 1 => int i => int pick_dir;
40 // how many times
41 4 * Math.random2( 1, 5 ) => int pick;
42 0.0 => float pluck;
43 0.7 / pick => float inc;
44 // time loop
45 for( ; i < pick; i++ )
46 {
47 75::ms => now;
48 Math.random2f(.2,.3) + i*inc => pluck;
49 pluck + -.2 * pick_dir => shake.noteOn;
50 // simulate pluck direction
51 !pick_dir => pick_dir;
52 }
53
54 // let time pass for final shake
55 75::ms => now;
56 }
57 }