2 summary:: Create access by names to slots of a GeneralHIDDevice
3 related:: Classes/HIDDeviceService, Classes/LID, Classes/GeneralHID, Classes/GeneralHIDDevice
13 define a key to a slot
39 // Look for the devices that are attached:
40 GeneralHID.buildDeviceList;
42 // Get the list of devices:
43 d = GeneralHID.deviceList;
45 // Check which devices have been found:
46 GeneralHID.postDevices;
48 // Pick the 6th device and open it and create an instance of it:
49 a = GeneralHID.open( d[5] )
51 // Get info on the device to see if it is the right one:
55 GeneralHID.startEventLoop
57 // Get the capabilities of the device in a readable format:
60 // See if data is coming in:
63 // make an instance of a spec:
64 b = GeneralHIDSpec.new( a );
66 ( // defining the spec.
67 // trick: look at the debug output, by using each input thing on the gamepad and use the first two numbers posted as indexes
68 // example output of debug: [ 3, 2, 0.49803921568627, nil ]
69 // as a result of moving the y-axis of the right joystick.
70 // so we create this slot:
78 b.add( \b1, [1,288] );
79 b.add( \b2, [1,289] );
80 b.add( \b3, [1,290] );
81 b.add( \b4, [1,291] );
82 b.add( \b5, [1,292] );
83 b.add( \b6, [1,293] );
84 b.add( \b7, [1,294] );
85 b.add( \b8, [1,295] );
87 b.add( \b5, [1,292] );
88 b.add( \b6, [1,293] );
89 b.add( \b7, [1,294] );
90 b.add( \b8, [1,295] );
95 b.add( \bl, [1,296] );
96 b.add( \br, [1,297] );
98 b.add( \bj1, [1,298] );
99 b.add( \bj2, [1,299] );
108 // store it with a name:
111 // find matching, previously stored specs:
115 b.fromFile( "Impact" );
117 // the loading and storing mechanism works across SC sessions, as they are stored to file, and GeneralHIDSpec loads the device info of all stored specs at startup of the language.
119 /// A GeneralHIDDevice automatically has a spec, so we can access it even faster:
123 // to find and set a spec:
125 a.setSpec( "Impact" );
131 s = Server.local.boot;
134 b.createBus( \rx, s );
135 b.createBus( \b1, s );
140 SynthDef( \hidbus_help, { |out=0,amp=0.5|
141 Out.ar( out, SinOsc.ar( 300, 0, 0.2*(amp-0.5) ) );
145 x = Synth.new( \hidbus_help );
146 x.map( \amp, b.at( \rx ).bus );
149 ( // a nicer version:
150 SynthDef( \hidbus_help, { |out=0,amp=0.5,amp2=0|
151 Out.ar( out, SinOsc.ar( 300, 0, 0.2*(amp-0.5).lag( 0.1 ) * amp2.lag(0.01,0.99) ) );
155 x = Synth.new( \hidbus_help );
156 x.map( \amp, b.at( \rx ).bus );
157 x.map( \amp2, b.at( \b1 ).bus );
160 ( // an even nicer version:
161 SynthDef( \hidbus_help, { |out=0,freqadd=0,amp=0,fmmul=200|
162 Out.ar( out, SinOsc.ar( 300 + (freqadd.lag(0.2,1)*fmmul), 0, 0.2*amp.lag(0.01,0.99) ) );
167 // if you want to have buses for all the things defined in the spec, you can use:
168 b.createAllBuses( s );
171 x = [ Synth.new( \hidbus_help ), Synth.new( \hidbus_help ) ];
172 x[0].map( \freqadd, b.bus( \ly ) );
173 x[0].map( \amp, b.bus( \b6 ) );
175 x[1].map( \freqadd, b.bus( \lx ) );
176 x[1].map( \amp, b.bus( \b7 ) );
178 y = [ Synth.new( \hidbus_help, [\fmmul,400] ), Synth.new( \hidbus_help, [\fmmul,400] ) ];
179 y[0].map( \freqadd, b.bus( \ry ) );
180 y[0].map( \amp, b.bus( \b5 ) );
182 y[1].map( \freqadd, b.bus( \rx ) );
183 y[1].map( \amp, b.bus( \b6 ) );
186 // see what's going on on the server
187 s.queryAllNodes( true );
190 y.do{ |it| it.free; }; x.do{ |it| it.free; };
197 // Close the device after use:
201 GeneralHID.stopEventLoop