Debian Codegraph @

examples/stk/mand-o-matic.ck

raw
1 //---------------|
2 // mand-o-matic!
3 // by: Ge Wang ([email protected])
4 // Perry R. Cook ([email protected])
5 //------------------|
6
7 // our patch
8 Mandolin mand => JCRev r => Echo a => Echo b => Echo c => dac;
9 // set the gain
10 .95 => r.gain;
11 // set the reverb mix
12 .05 => r.mix;
13 // set max delay for echo
14 1000::ms => a.max => b.max => c.max;
15 // set delay for echo
16 750::ms => a.delay => b.delay => c.delay;
17 // set the initial effect mix
18 0.0 => a.mix => b.mix => c.mix;
19
20 // scale
21 [ 0, 2, 4, 7, 9 ] @=> int scale[];
22
23 // shred to modulate the mix
24 fun void echo_Shred( )
25 {
26 0.0 => float decider => float mix => float old => float inc;
27
28 // time loop
29 while( true )
30 {
31 Math.random2f( 0, 1 ) => decider;
32 if( decider < .35 ) 0.0 => mix;
33 else if( decider < .55 ) .08 => mix;
34 else if( decider < .8 ) .5 => mix;
35 else .15 => mix;
36
37 // find the increment
38 (mix-old)/1000.0 => inc; 1000 => int n;
39 // time loop
40 while( n-- )
41 {
42 // set the mix for a, b, c
43 old + inc => old => a.mix => b.mix => c.mix;
44 1::ms => now;
45 }
46 // remember the old
47 mix => old;
48 // let time pass until the next iteration
49 Math.random2(2,6)::second => now;
50 }
51 }
52
53 // let echo shred go
54 spork ~ echo_Shred();
55
56 // our main loop
57 while( true )
58 {
59 // position
60 Math.random2f( 0.2, 0.8 ) => mand.pluckPos;
61 // frequency...
62 scale[Math.random2(0,scale.size()-1)] => int freq;
63 220.0 * Math.pow( 1.05946, (Math.random2(0,2)*12) + freq ) => mand.freq;
64 // pluck it!
65 Math.random2f( 0.2, 0.9 ) => mand.pluck;
66
67 // note: Math.randomf() returns value between 0 and 1
68 if( Math.randomf() > 0.9 )
69 { 500::ms => now; }
70 else if( Math.randomf() > .925 )
71 { 250::ms => now; }
72 else if( Math.randomf() > .05 )
73 { .125::second => now; }
74 else
75 {
76 1 => int i => int pick_dir;
77 // how many times
78 4 * Math.random2( 1, 5 ) => int pick;
79 0.0 => float pluck;
80 0.7 / pick => float inc;
81 // time loop
82 for( ; i < pick; i++ )
83 {
84 75::ms => now;
85 Math.random2f(.2,.3) + i*inc => pluck;
86 pluck + -.2 * pick_dir => mand.pluck;
87 // simulate pluck direction
88 !pick_dir => pick_dir;
89 }
90 // let time pass for final pluck
91 75::ms => now;
92 }
93 }