Debian Codegraph @

examples/hid/kbhit/clix3.ck

raw
1 // name: clix.ck
2 // desc: typing-based instrument, quantized, multi-channel
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 // get char
47 kb.getchar() => int c;
48
49 // space
50 if( c == 32 )
51 {
52 <<< "skipping...", "" >>>;
53 T => now;
54 continue;
55 }
56
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] >>>;
65
66 // open
67 e.keyOn();
68 // advance time
69 T-2::ms => now;
70 // close
71 e.keyOff();
72 2::ms => now;
73 }
74 }