Debian Codegraph @

examples/hid/joy-shake.ck

raw
1 //-----------------------------------------------------------------------------
2 // name: joy-shake.ck
3 // desc: using joystick to control STK Shakers!
4 //
5 // note: select between joysticks by specifying 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 joystick
20 0 => int device;
21 // get from command line
22 if( me.args() ) me.arg(0) => Std.atoi => device;
23
24 // open joystick 0, exit on fail
25 if( !hi.openJoystick( device ) ) me.exit();
26
27 // patch
28 Shakers s => JCRev r => dac;
29 .02 => r.mix;
30
31 int which;
32
33 // infinite event loop
34 while( true )
35 {
36 // wait on HidIn as event
37 hi => now;
38
39 // messages received
40 while( hi.recv( msg ) )
41 {
42 // axis
43 if( msg.isAxisMotion() )
44 {
45 if( msg.which == 0 ) (msg.axisPosition+1) / 2.0 => s.energy;
46 if( msg.which == 1 ) (msg.axisPosition+1) * 64 => s.objects;
47 if( msg.which == 2 ) 5 + (msg.axisPosition+1) * 300 => s.freq;
48 if( msg.which == 3 ) (msg.axisPosition+1) / 2.0 => s.decay;
49 //<<< "freq:", s.freq(), "objects:", s.objects(), "energy:", s.energy(), "decay:", s.decay(), "preset:", s.preset() >>>;
50 }
51
52 // button down
53 if( msg.isButtonDown() )
54 {
55 if( msg.which == 0 ) s.noteOn( .8 );
56 if( msg.which == 2 ) { which++; (which % 22) => s.preset; }
57 if( msg.which == 3 ) { which--; (which % 22) => s.preset; }
58 //<<< "freq:", s.freq(), "objects:", s.objects(), "energy:", s.energy(), "decay:", s.decay(), "preset:", s.preset() >>>;
59 }
60 }
61 }