Debian Codegraph @

examples/hid/kbhit/clix2.ck

raw
1 // name: clix2.ck
2 // desc: typing-based instrument, quantized, multi-channel
3 // author: Ge Wang and 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;
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 // period duration
32 N * T => dur period;
33
34 // last unen
35 UGen @ last;
36 // total number of channels
37 dac.channels() => int C;
38 // keep track of which
39 int which;
40
41 // time-loop
42 while( true )
43 {
44 // wait on event
45 kb => now;
46
47 // synch
48 T - (now%T) => now;
49
50 // loop through 1 or more keys
51 while( kb.more() )
52 {
53 // figure out period
54 (now % period / period * N) $ int => int index;
55 // generate impulse
56 mygains[index] => i.next;
57 // set filtre freq
58 kb.getchar() => int c => Std.mtof => f.pfreq;
59 // print int value
60 <<< "ascii:", c, "velocity:", mygains[index], "channel:", which >>>;
61
62 // disconnect from previous
63 if( last != NULL ) r =< last;
64 // the dac channel to connect
65 dac.chan(which) @=> last;
66 // the next channel
67 (which + 1) % C => which;
68 // connect revert to dac channel
69 r => last;
70
71 // open
72 e.keyOn();
73 // advance time
74 T-2::ms => now;
75 // close
76 e.keyOff();
77 2::ms => now;
78 }
79 }