1 //human device interface pattern. pulls values from devices like gamepads etc.
4 var <>element, <>locID, <>repeats;
6 //element can be key or index
7 *new { arg element, locID=0, repeats=inf;
8 ^super.newCopyArgs(element, locID, repeats)
10 storeArgs { ^[element,locID,repeats] }
11 embedInStream { arg event;
12 var all, device, spec, elements, deviceName, min, max;
14 all = HIDDeviceService.devices;
16 HIDDeviceService.buildDeviceList;
17 all = HIDDeviceService.devices;
19 device = all.at(locID);
20 if(device.isNil, { "device not found".error; ^nil });
21 if(element.isNumber.not, {
22 element = HIDDeviceService.keyToIndex(element, locID);
23 if(element.isNil, { "key not found".error; ^nil });
25 elements = device.elements;
26 min = elements.at(element).min;
27 max = elements.at(element).max;
28 spec = ControlSpec.new(min, max, 'lin', 1);
29 if((min === 0) and: {max === 1}, {
30 repeats.value(event).do({
31 event = device.value(element).yield
35 repeats.value(event).do({
36 event = spec.unmap(device.value(element)).yield