Human input devices can be used as controllers for making music. This class provides you with access to them in a simple and transparent way.
The development of this SuperCollider implementation of HID access was funded by the SuperCollider community and BEK, Bergen Elektronisk Kunst, Bergen, Norway, http://www.bek.no
In general using an Human Input Device follows this scheme:
HID.findAvailable;
HID.postAvailable;
~myhid = HID.open( 1103, 53251 );
~myhid.elements[1].action = { |...args| args.postln; };
See Working with HID for a full introduction.
queries the operating system which HID devices are attached to the system and can be accessed. When using HID this is the first method you need to execute, before you can access any device.
an IdentityDictionary of available devices
A dictionary of available devices, or rather info about them in an instance of HIDInfo, populated by the method findAvailable
an IdentityDictionary
posts a human readable list of available HID devices and their properties (see also HIDInfo)
Find devices in the available device dictionary by specifying one or more characteristics of the device
vendorID |
The vendor ID of the device, this is a number encoded by the device itself, and the same across platforms. |
productID |
The product ID of the device, this is a number encoded by the device itself, and the same across platforms. |
path |
The path of the device, this is a path defined by the operating system, and thus not the same across platforms, but essential to distinguish devices with the same vendor and product ID from each other. |
serial |
The serial number of the device. This is dependent on the operating system, e.g. on Linux it is not set. |
releaseNumber |
The release number of the device, this is a number encoded by the device itself, and the same across platforms. |
an IdentityDictionary of devices the match the search query, or nil if no arguments are given
A dictionary of available usages from all HIDs, populated automatically when devices are opened and closed.
an IdentityDictionary
posts a human readable list of available HID usages and their properties (see also HIDElement and HIDUsage)
Open a device with a given vendorID, product ID and optionally a path.
vendorID |
The vendor ID of the device |
productID |
The product ID of the device |
path |
(optional) The path in the operating system, e.g. "/dev/hidraw0" on Linux. If not specified, the method will look for a matching device in the device list, and open the first match it finds. |
The HID device - an instance of HID.
Same as HID.open
Open a device using its path in the operating system
path |
The path in the operating system, e.g. "/dev/hidraw0" on Linux |
The HID device - an instance of HID.
Open a device using its index in the dictionary of available devices
index |
The index into the dictionary of available devices |
The HID device - an instance of HID.
A dictionary of the opened devices
an IdentityDictionary
Whenever data comes in from an opened HID device, there are two types of actions fired. An action for the incoming element data and an action for the device, indicating that there has been a change in one of the elements. In most cases you will want to use the first action; only in cases where the order of parsing the element data is important, you may want to use the second type - e.g. when dealing with very accurately timed button press combinations.
There are three levels where you can set actions:
Alternately, you can also use the HIDFunc interface.
When set to true, the incoming data from any opened HID device will be printed to the post window.
Set or get the action to be performed upon receiving element data from the device. The function will be passed the following arguments: the value (mapped between 0 and 1), the raw value, element usage page, the element usage, the element id, the device id, the device (an instance of HID).
function |
The function to be performed upon receiving element data from the device |
add a function to the internal FunctionList that will be evaluated whenever element data comes in from an open device. The arguments passed to the function are as defined above. Use this method if you want to add actions to HID functions from classes you write, so that you still keep the option to add an action on the fly from user code.
function |
The function to be added to the list. |
remove a function to the internal FunctionList that will be evaluated whenever data comes in from a device.
function |
The function to remove from the list, this must be a reference to the Function that was originally added to the list |
set an action or function to be performed whenever there is an update to any device's elements.
function |
The function to be performed upon receiving data from the device |
add a function to the internal FunctionList that will be evaluated whenever data comes in from a device.
function |
The function to be performed upon receiving data from the device |
remove a function to the internal FunctionList that will be evaluated whenever data comes in from a device.
function |
The function to remove from the list, this must be a reference to the Function that was originally added to the list |
The following methods are used internally to initialize and finalize the HID subsystem, but in rare cases you may wish to manage these methods manually.
Initialize the HID subsystem, this method is called automatically when calling the method findAvailable.
Indicates whether or not the HID subsystem is running.
This method is called automatically upon Shutdown, if the HID subsystem was initialized. It can be stopped manually, in order to save system resources. This method will close all opened HID devices.
An IdentityDictionary holding all the elements, i.e. controls, of the device
Find all elements with a certain usage and usagePage.
elUsage |
The usage index of the element |
elUsagePage |
The usage page of the element |
an Array with the found elements
Get the element with the given index
elid |
The index of the element |
the HIDElement
Close the HID device, closing a device is asynchronous. You can set a closeAction (see below), which will be performed when the device closes.
Returns true if the device is open, false if the device was closed.
returns: a Boolean
An IdentityDictionary holding all the collections, i.e. groups of controls, of the device
When set to true, the incoming data from this HID device will be printed to the post window.
Function to be performed when device is closed.
Set or get the action to be performed upon receiving element data from the device. The function will be passed the following arguments: the value (mapped between 0 and 1), the raw value, element usage page, the element usage, the element id
(function) |
The function to be performed upon receiving element data from the device |
set an action or function to be performed whenever there is an update to any of the device's elements.
(function) |
The function to be performed upon receiving data from the device |
Post the HIDInfo of this device in a human readable format
Post information about all the collections of this device in a human readable format
Post information about all the elements of this device in a human readable format
Post information about all the input elements of this device in a human readable format
Post information about all the output elements of this device in a human readable format
Post information about all the feature elements of this device in a human readable format
Post information about all the usages of this device in a human readable format
Retrieve the HIDInfo of this device
an instance of HIDInfo
Retrieve the usage index of a collection of this device, or the main usage of the device (if called without an argument).
collectionID |
The collection of which to retrieve the usage. Default is 0, which should define the primary usage of the device. |
the usage index of this device
Retrieve the usage name of a collection of this device, or the main usage of the device (if called without an argument). The name is looked up from the standardized HID usage tables using the usage index.
collectionID |
The collection of which to retrieve the usage. Default is 0, which should define the primary usage of the device. |
the usage name of this device
Retrieve the usage page index of a collection of this device, or the main page of the device (if called without an argument). The name is looked up from the standardized HID usage tables using the usage page index.
collectionID |
The collection of which to retrieve the usage page. Default is 0, which should define the primary usage of the device. |
the usage page index of this device
Retrieve the page name of a collection of this device, or the main page of the device (if called without an argument). The name is looked up from the standardized HID usage tables using the usage page index.
collectionID |
The collection of which to retrieve the usage page name. Default is 0, which should define the primary usage of the device. |
the usage page name of this device
Retrieve the vendor id of this device
the vendor id
Retrieve the product id of this device
the product id
Retrieve the usages of the elements of this device.
an IdentityDictionary with usages as keys and lists of elements as corresponding elements