*** empty log message ***
[chuck-blob.git] / v2 / examples / event / clix3.ck
blob0385a1e1531639d243bfdbe81c99da2a2cfb5906
1 // name: clix.ck
2 // desc: typing-based instrument, quantized, multi-channel
3 // author: Ge Wang + Perry Cook
5 // computer keyboard input via terminal
6 KBHit kb;
8 // time
9 4096::samp => dur T;
11 // patch
12 Impulse i => BiQuad f => Envelope e => JCRev r => dac;
14 // set the filter's pole radius
15 .99 => f.prad;
16 // set equal gain zeros
17 1 => f.eqzs;
18 // envelope rise/fall time
19 1::ms => e.duration;
20 // reverb mix
21 .01 => r.mix;
23 // strengths
24 [ 1.0, 0.2, 0.3, 0.2, 0.4, 0.1, 0.2, 0.1,
25   0.5, 0.1, 0.3, 0.2, 0.4, 0.1, 0.2, 0.1,
26   0.8, 0.1, 0.3, 0.2, 0.5, 0.1, 0.2, 0.1,
27   0.4, 0.1, 0.3, 0.2, 0.3, 0.1, 0.2, 0.1 ] @=> float mygains[];
29 // capacity
30 mygains.cap() => int N;
31 // total period
32 N * T => dur period;
34 // time-loop
35 while( true )
37     // wait on event
38     kb => now;
40     // synch
41     T - (now%T) => now;
43     // loop through 1 or more keys
44     while( kb.more() )
45     {
46         // get char
47         kb.getchar() => int c;
49         // space
50         if( c == 32 )
51         {
52             <<< "skipping...", "" >>>;
53             T => now;
54             continue;
55         }
57         // figure out period
58         (now % period / period * N) $ int => int index;
59         // generate impulse
60         mygains[index] => i.next;
61         // set filtre freq
62         c => Std.mtof => f.pfreq;
63         // print int value
64         <<< "ascii:", c, "velocity:", mygains[index] >>>;
66         // open
67         e.keyOn();
68         // advance time
69         T-2::ms => now;
70         // close
71         e.keyOff();
72         2::ms => now;
73     }