/usr/share/SuperCollider/HelpSource/Classes/GeneralHIDSpec.schelp is in supercollider-common 1:3.6.6~repack-2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | class:: GeneralHIDSpec
summary:: Create access by names to slots of a GeneralHIDDevice
related:: Classes/HIDDeviceService, Classes/LID, Classes/GeneralHID, Classes/GeneralHIDDevice
categories:: External Control>HID
ClassMethods::
private::initClass
InstanceMethods::
method::add
define a key to a slot
method::at
get the slot
method::value
get or set the slot
method::action
set the action
method::bus
get the bus
method::createBus
create the bus
method::freeBus
free the bus
method:: freeAllBuses
free all buses
Examples::
code::
// Look for the devices that are attached:
GeneralHID.buildDeviceList;
// Get the list of devices:
d = GeneralHID.deviceList;
// Check which devices have been found:
GeneralHID.postDevices;
// Pick the 6th device and open it and create an instance of it:
a = GeneralHID.open( d[5] )
// Get info on the device to see if it is the right one:
a.info;
// Start eventloop:
GeneralHID.startEventLoop
// Get the capabilities of the device in a readable format:
a.caps;
// See if data is coming in:
a.debug_( true );
// make an instance of a spec:
b = GeneralHIDSpec.new( a );
( // defining the spec.
// trick: look at the debug output, by using each input thing on the gamepad and use the first two numbers posted as indexes
// example output of debug: [ 3, 2, 0.49803921568627, nil ]
// as a result of moving the y-axis of the right joystick.
// so we create this slot:
b.add( \ry, [3,2] );
// and so on...
b.add( \lx, [3,0] );
b.add( \ly, [3,1] );
b.add( \rx, [3,5] );
b.add( \b1, [1,288] );
b.add( \b2, [1,289] );
b.add( \b3, [1,290] );
b.add( \b4, [1,291] );
b.add( \b5, [1,292] );
b.add( \b6, [1,293] );
b.add( \b7, [1,294] );
b.add( \b8, [1,295] );
b.add( \b5, [1,292] );
b.add( \b6, [1,293] );
b.add( \b7, [1,294] );
b.add( \b8, [1,295] );
b.add( \cx, [3,16] );
b.add( \cy, [3,17] );
b.add( \bl, [1,296] );
b.add( \br, [1,297] );
b.add( \bj1, [1,298] );
b.add( \bj2, [1,299] );
)
// Stop it:
a.debug_( false );
// look at the map
b.map.postcs;
// store it with a name:
b.save( "Impact" );
// find matching, previously stored specs:
c = b.find;
// load from file:
b.fromFile( "Impact" );
// 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.
/// A GeneralHIDDevice automatically has a spec, so we can access it even faster:
a.spec;
// to find and set a spec:
a.findSpec;
a.setSpec( "Impact" );
// post the mapping
a.spec.map
// examples of use:
s = Server.local.boot;
// create a bus
b.createBus( \rx, s );
b.createBus( \b1, s );
// simple example:
(
SynthDef( \hidbus_help, { |out=0,amp=0.5|
Out.ar( out, SinOsc.ar( 300, 0, 0.2*(amp-0.5) ) );
}).add;
)
x = Synth.new( \hidbus_help );
x.map( \amp, b.at( \rx ).bus );
x.free;
( // a nicer version:
SynthDef( \hidbus_help, { |out=0,amp=0.5,amp2=0|
Out.ar( out, SinOsc.ar( 300, 0, 0.2*(amp-0.5).lag( 0.1 ) * amp2.lag(0.01,0.99) ) );
}).add;
)
x = Synth.new( \hidbus_help );
x.map( \amp, b.at( \rx ).bus );
x.map( \amp2, b.at( \b1 ).bus );
x.free;
( // an even nicer version:
SynthDef( \hidbus_help, { |out=0,freqadd=0,amp=0,fmmul=200|
Out.ar( out, SinOsc.ar( 300 + (freqadd.lag(0.2,1)*fmmul), 0, 0.2*amp.lag(0.01,0.99) ) );
}).add;
)
// if you want to have buses for all the things defined in the spec, you can use:
b.createAllBuses( s );
(
x = [ Synth.new( \hidbus_help ), Synth.new( \hidbus_help ) ];
x[0].map( \freqadd, b.bus( \ly ) );
x[0].map( \amp, b.bus( \b6 ) );
x[1].map( \freqadd, b.bus( \lx ) );
x[1].map( \amp, b.bus( \b7 ) );
y = [ Synth.new( \hidbus_help, [\fmmul,400] ), Synth.new( \hidbus_help, [\fmmul,400] ) ];
y[0].map( \freqadd, b.bus( \ry ) );
y[0].map( \amp, b.bus( \b5 ) );
y[1].map( \freqadd, b.bus( \rx ) );
y[1].map( \amp, b.bus( \b6 ) );
)
// see what's going on on the server
s.queryAllNodes( true );
// free the synths
y.do{ |it| it.free; }; x.do{ |it| it.free; };
// To free all buses
b.freeAllBuses;
// Close the device after use:
a.close;
GeneralHID.stopEventLoop
::
|