Debian Codegraph @

examples/hid/kbhit/clix.ck

raw
1 // name: clix.ck
2 // desc: typing-based instrument, quantized
3 // author: Ge Wang + Perry Cook
4
5 // computer keyboard input via terminal
6 KBHit kb;
7
8 // time
9 4096::samp => dur T;
10
11 // patch
12 Impulse i => BiQuad f => Envelope e => JCRev r => dac;
13
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;
22
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[];
28
29 // capacity
30 mygains.size() => int N;
31 // total period
32 N * T => dur period;
33
34 // time-loop
35 while( true )
36 {
37 // wait on event
38 kb => now;
39
40 // synch
41 T - (now%T) => now;
42
43 // loop through 1 or more keys
44 while( kb.more() )
45 {
46 // figure out period
47 (now % period / period * N) $ int => int index;
48 // generate impulse
49 mygains[index] => i.next;
50 // set filtre freq
51 kb.getchar() => int c => Std.mtof => f.pfreq;
52 // print int value
53 <<< "ascii:", c, "velocity:", mygains[index] >>>;
54
55 // open
56 e.keyOn();
57 // advance time
58 T-2::ms => now;
59 // close
60 e.keyOff();
61 2::ms => now;
62 }
63 }