Debian Codegraph @

examples/hid/keyboard-organ.ck

raw
1 //-----------------------------------------------------------------------------
2 // name: keyboard-organ.ck
3 // desc: play your computer keyboard like an organ
4 //
5 // note: select between keyboards by specifying the device number;
6 // to see a list of devices and their numbers, either...
7 // 1) view the Device Browser window in miniAudicle (select
8 // "Human Interface Devices" in the drop-down menu)
9 // OR 2) from the command line:
10 // > chuck --probe
11 //
12 // author: Ge Wang (https://ccrma.stanford.edu/~ge/)
13 //-----------------------------------------------------------------------------
14
15 // HID input and HID message
16 Hid hi;
17 HidMsg msg;
18
19 // which keyboard
20 0 => int device;
21 // get from command line
22 if( me.args() ) me.arg(0) => Std.atoi => device;
23
24 // open keyboard (get device number from command line)
25 if( !hi.openKeyboard( device ) ) me.exit();
26 <<< "keyboard '" + hi.name() + "' ready", "" >>>;
27
28 // patch
29 BeeThree organ => JCRev r => Echo e => Echo e2 => dac;
30 r => dac;
31
32 // set delays
33 240::ms => e.max => e.delay;
34 480::ms => e2.max => e2.delay;
35 // set gains
36 .6 => e.gain;
37 .3 => e2.gain;
38 .05 => r.mix;
39 0 => organ.gain;
40
41 // infinite event loop
42 while( true )
43 {
44 // wait for event
45 hi => now;
46
47 // get message
48 while( hi.recv( msg ) )
49 {
50 // check
51 if( msg.isButtonDown() )
52 {
53 Std.mtof( msg.which + 45 ) => float freq;
54 if( freq > 20000 ) continue;
55
56 freq => organ.freq;
57 .5 => organ.gain;
58 1 => organ.noteOn;
59
60 80::ms => now;
61 }
62 else
63 {
64 0 => organ.noteOff;
65 }
66 }
67 }