/usr/share/SuperCollider/HelpSource/Classes/HIDdef.schelp is in supercollider-common 1:3.8.0~repack-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 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | TITLE:: HIDdef
summary:: HID response reference definition
categories:: External Control>HID
related:: Classes/HID, Classes/HIDFunc, Classes/OSCdef, Classes/MIDIdef, Guides/Working_with_HID
DESCRIPTION::
HIDdef provides a global reference to the functionality of its superclass HIDFunc. Essentially it stores itself at a key within a global dictionary, allowing replacement at any time. Most methods are inherited from its superclass.
CLASSMETHODS::
PRIVATE:: initClass
METHOD:: all
Get the global dictionary of all HIDdefs.
returns:: An LINK::Classes/IdentityDictionary::
METHOD:: freeAll
Clears and deactivates all HIDdefs from the global collection.
METHOD:: new
Access an existing HIDdef. This is a shortcut to access an HIDdef created with one of the methods below, and allows to change its function, or call free on it.
ARGUMENT:: key
The key at which to store this HIDdef in the global collection. Generally this will be a link::Classes/Symbol::.
ARGUMENT:: func
A link::Classes/Function:: or similar object which will respond to the incoming message. It will be passed...
METHOD:: usage
Create a new, enabled HIDdef. If an HIDdef already exists at this key, its parameters will be replaced with the ones provided (args for which nil is passed will use the old values).
A convenience method to filter an incoming HID value based on the name of its control usage. E.g. the name of an X-axis of a joystick or the horizontal movement of a mouse has the name code::\X::. These usage names are standardized by manufacturers and are looked up in usage tables based on the information coming from the device. If you have an open HID device, you can look up the available usages with: code::~hid.postUsages::.
ARGUMENT:: key
The key at which to store this HIDdef in the global collection. Generally this will be a link::Classes/Symbol::.
ARGUMENT:: func
A link::Classes/Function:: or similar object which will respond to the incoming message. It will be passed...
ARGUMENT:: elUsageName
The name of the usage to look for. This can be one usage name, or an array of usage names.
ARGUMENT:: devUsageName
The name of the device usage to look for, e.g. code::\GamePad:: or code::\Mouse::. If left blank, the code::HIDdef:: will match any device.
ARGUMENT:: deviceInfo
An link::Classes/IdentityDictionary:: with a more detailed filtering for a device.
ARGUMENT:: argTemplate
This should be an object that implements the method code::matchItem::. Depending on the code::argTemplateType::, it will be passed either the rawValue of the value of the element to be matched.
ARGUMENT:: argTemplateType
If the argTemplateType is code::\rawValue:: (the default) then the matching is done based on the incoming raw value of the element (not mapped according to the logical min and max). Otherwise the matching is done according to the mapped value.
ARGUMENT:: dispatcher
An optional instance of an appropriate subclass of link::Classes/AbstractDispatcher::. This can be used to allow for customised dispatching. Normally this should not be needed. The default for this type of code::HIDdef:: is code::HIDUsageDispatcher::
returns:: A new instance of HIDdef which responds to a specific element usage and device type.
METHOD:: device
Create a new, enabled HIDdef. If an HIDdef already exists at this key, its parameters will be replaced with the ones provided (args for which nil is passed will use the old values).
A convenience method to filter an incoming HID value based on the name of the device. This type of HIDdef differs from code::HIDdef.usage:: in that it filter specifically by device name, rather than device usage, otherwise the arguments are the same.
ARGUMENT:: key
The key at which to store this HIDdef in the global collection. Generally this will be a link::Classes/Symbol::.
ARGUMENT:: func
A link::Classes/Function:: or similar object which will respond to the incoming message. It will be passed...
ARGUMENT:: elUsageName
The name of the usage to look for. This can be one usage name, or an array of usage names.
ARGUMENT:: deviceName
The name of the device to look for, note that this has to match the string as returned by the device exactly. You can look this string up in the device list: code::HID.postAvailable::
ARGUMENT:: deviceInfo
An link::Classes/IdentityDictionary:: with a more detailed filtering for a device.
ARGUMENT:: argTemplate
This should be an object that implements the method code::matchItem::. Depending on the code::argTemplateType::, it will be passed either the rawValue of the value of the element to be matched.
ARGUMENT:: argTemplateType
If the argTemplateType is code::\rawValue:: (the default) then the matching is done based on the incoming raw value of the element (not mapped according to the logical min and max). Otherwise the matching is done according to the mapped value.
ARGUMENT:: dispatcher
An optional instance of an appropriate subclass of link::Classes/AbstractDispatcher::. This can be used to allow for customised dispatching. Normally this should not be needed. The default for this type of code::HIDdef:: is code::HIDDeviceDispatcher::
returns:: A new instance of HIDdef which responds to a specific element usage for a specific device.
METHOD:: usageID
Create a new, enabled HIDdef. If an HIDdef already exists at this key, its parameters will be replaced with the ones provided (args for which nil is passed will use the old values).
A convenience method to filter an incoming HID value based on the number of its control usage. If the device is using a non-standard usage number, then this method can be used to look for it. A controls usage is fully specified by the combination of its usage ID and its usage page.
ARGUMENT:: key
The key at which to store this HIDdef in the global collection. Generally this will be a link::Classes/Symbol::.
ARGUMENT:: func
A link::Classes/Function:: or similar object which will respond to the incoming message. It will be passed...usage
ARGUMENT:: elUsageID
The id (an link::Classes/Integer::) of the usage to look for. This can be one usage id, or an array of usage ids.
ARGUMENT:: elPageID
The id (an link::Classes/Integer::) of the page of the usage to look for. This can be one page id, or an array of page ids.
ARGUMENT:: deviceName
Since this type of HIDdef is meant for non-standardized controls, you can filter by a specific device name, rather than a general usage, similar to code::HIDdef.device::
ARGUMENT:: deviceInfo
An link::Classes/IdentityDictionary:: with a more detailed filtering for a device.
ARGUMENT:: argTemplate
This should be an object that implements the method code::matchItem::. Depending on the code::argTemplateType::, it will be passed either the rawValue of the value of the element to be matched.
ARGUMENT:: argTemplateType
If the argTemplateType is code::\rawValue:: (the default) then the matching is done based on the incoming raw value of the element (not mapped according to the logical min and max). Otherwise the matching is done according to the mapped value.
ARGUMENT:: dispatcher
An optional instance of an appropriate subclass of link::Classes/AbstractDispatcher::. This can be used to allow for customised dispatching. Normally this should not be needed. The default for this type of code::HIDdef:: is code::HIDElementProtoDispatcher::
returns:: A new instance of HIDdef which responds to a specific element usage id for a specific device.
METHOD:: proto
Create a new, enabled HIDdef. If an HIDdef already exists at this key, its parameters will be replaced with the ones provided (args for which nil is passed will use the old values).
A convenience method to filter an incoming HID value based on a matching template of an element (a link::Classes/HIDElementProto::). If you have number of conditions for the element that should be matched, then this method can be used to look for it.
ARGUMENT:: key
The key at which to store this HIDdef in the global collection. Generally this will be a link::Classes/Symbol::.
ARGUMENT:: func
A link::Classes/Function:: or similar object which will respond to the incoming message. It will be passed...usage
ARGUMENT:: protoElement
The id (an link::Classes/Integer::) of the usage to look for. This can be one usage id, or an array of usage ids.
ARGUMENT:: deviceInfo
An link::Classes/IdentityDictionary:: with a more detailed filtering for a device.
ARGUMENT:: argTemplate
This should be an object that implements the method code::matchItem::. Depending on the code::argTemplateType::, it will be passed either the rawValue of the value of the element to be matched.
ARGUMENT:: argTemplateType
If the argTemplateType is code::\rawValue:: (the default) then the matching is done based on the incoming raw value of the element (not mapped according to the logical min and max). Otherwise the matching is done according to the mapped value.
ARGUMENT:: dispatcher
An optional instance of an appropriate subclass of link::Classes/AbstractDispatcher::. This can be used to allow for customised dispatching. Normally this should not be needed. The default for this type of code::HIDdef:: is code::HIDElementProtoDispatcher::
returns:: A new instance of HIDdef which responds to a specific prototype element.
METHOD:: element
Create a new, enabled HIDdef. If an HIDdef already exists at this key, its parameters will be replaced with the ones provided (args for which nil is passed will use the old values).
A convenience method to filter an incoming HID value based on the index of its element. If the device is using something non-standard, or you want to access keyboard elements directly, then this method can be used to look for it. Note that the element index is not necessarily the same across different operating systems (i.e. it may vary between Linux and OSX and Windows).
ARGUMENT:: key
The key at which to store this HIDdef in the global collection. Generally this will be a link::Classes/Symbol::.
ARGUMENT:: func
A link::Classes/Function:: or similar object which will respond to the incoming message. It will be passed...
ARGUMENT:: elID
The id (an link::Classes/Integer::) of the element to look for. This can be one element id, or an array of element ids.
ARGUMENT:: deviceName
Since this type of HIDdef is meant for non-standardized elements, you can filter by a specific device name, rather than a general usage, similar to code::HIDdef.device::
ARGUMENT:: deviceInfo
An link::Classes/IdentityDictionary:: with a more detailed filtering for a device.
ARGUMENT:: argTemplate
This should be an object that implements the method code::matchItem::. Depending on the code::argTemplateType::, it will be passed either the rawValue of the value of the element to be matched.
ARGUMENT:: argTemplateType
If the argTemplateType is code::\rawValue:: (the default) then the matching is done based on the incoming raw value of the element (not mapped according to the logical min and max). Otherwise the matching is done according to the mapped value.
ARGUMENT:: dispatcher
An optional instance of an appropriate subclass of link::Classes/AbstractDispatcher::. This can be used to allow for customised dispatching. Normally this should not be needed. The default for this type of code::HIDdef:: is code::HIDElementDispatcher::
returns:: A new instance of HIDdef which responds to a specific element id for a specific device.
INSTANCEMETHODS::
PRIVATE::addToAll, printOn
METHOD:: key
Get this HIDdef's key.
returns:: Usually a link::Classes/Symbol::.
METHOD:: free
Clears this HIDdef from the global collection and deactivates it.
EXAMPLES::
For all the examples below here, you will need to have initialized an HID device (see also link::Guides/Working_with_HID::). The examples below should work with a standard USB mouse.
code::
HID.findAvailable; // check which devices are attached
HID.postAvailable; // post the available devices
~myhid = HID.open( 1103, 53251 ); // adapt this line for the device that you want to open!
::
SUBSECTION:: Filtering based on usage
code::
// filter all events coming from the x-axis of a mouse
HIDdef.usage( \example, { |...args| args.postln; }, \X, \Mouse );
// filter all events coming from a mouse
HIDdef.usage( \example, { |...args| args.postln; }, nil, \Mouse );
// filter all events coming from an X-axis (could be from a mouse or a joystick or a gamepad)
HIDdef.usage( \example, { |...args| args.postln; }, \X );
// filter all events coming from an X-axis or an Y-axis (could be from a mouse or a joystick or a gamepad)
HIDdef.usage( \example, { |...args| args.postln; }, [\X,\Y] );
// usage of argTemplate: matching the rawValue (is the default behaviour)
// only react when the values are below zero:
HIDdef.usage( \example, { |...args| args.postln; }, [\X,\Y], argTemplate: { |val| val < 0 } );
// only match when rawvalue == -1
HIDdef.usage( \example, { |...args| args.postln; }, [\X,\Y], argTemplate: -1 );
// only match when rawvalue is one of [-3,-2,-1]
HIDdef.usage( \example, { |...args| args.postln; }, [\X,\Y], argTemplate: [-3,-2,-1] );
// usage of argTemplate: matching the scaled value when smaller than 0.5
HIDdef.usage( \example, { |...args| args.postln; }, [\X,\Y], argTemplate: { |val| val < 0.5 }, argTemplateType: \value );
// using deviceInfo rather than deviceUsage (you can add more device specifications to match)
HIDdef.usage( \example, { |...args| args.postln; }, \X, deviceInfo: ( usageName: \Mouse ) );
HIDdef.usage( \example, { |...args| args.postln; }, nil, deviceInfo: ( usageName: \Mouse ) );
HIDdef( \example ).free;
::
SUBSECTION:: Filtering based on usage ID
code::
// filter by usage ID 48 on usage page 1
HIDdef.usageID( \example2, { |...args| args.postln; }, 48, 1 );
// filter by usage ID 48 or 49 on usage page 1
HIDdef.usageID( \example2, { |...args| args.postln; }, [48,49], 1 );
// filter by any usage ID on usage page 1
HIDdef.usageID( \example2, { |...args| args.postln; }, nil, 1 );
// filter by usage ID 48 on usage page 1, of a device with an empty string as a name (fill in the name of your mouse there).
HIDdef.usageID( \example2, { |...args| args.postln; }, 48, 1, "" );
// filter by usage ID 48 on usage page 1, of a device with path "/dev/hidraw2" (adapt this path to the device you want to match)
HIDdef.usageID( \example2, { |...args| args.postln; }, 48, 1, deviceInfo: ( path: "/dev/hidraw2" ) );
HIDdef( \example2 ).free;
::
SUBSECTION:: Filtering based on a device
code::
// filter for device with name "", and element with usage \X.
HIDdef.device( \example3, { |...args| args.postln; }, \X, "" );
HIDdef( \example3 ).free;
::
SUBSECTION:: Filtering based on a prototype element
code::
// create an prototype element with usageName \X
c = HIDElementProto.new.usageName_( \X );
HIDdef.proto( \example4, { |...args| args.postln; }, c );
HIDdef( \example4 ).free;
::
SUBSECTION:: Filtering based on an element ID
code::
// filter for elements with element id 6:
HIDdef.element( \example5, { |...args| args.postln; }, 6 );
HIDdef( \example5 ).free;
::
|