1 //human device interface pattern. pulls values from devices like gamepads etc.
5 var <>slot,<>type,<>device;
9 // the Device list must have been built.
10 *new { arg slot, type, device, repeats=inf;
11 ^super.new.init(slot, type, device, repeats)
19 if ( device.isKindOf( GeneralHIDDevice ).not,
21 try { device = GeneralHID.open( device ); }{ "device argument is not a GeneralHIDDevice".error; ^nil }
25 storeArgs { ^[slot, type, device, repeats] }
27 embedInStream { arg inval;
29 // slot and type streams
30 var slotStr = slot.asStream;
31 var typeStr = type.asStream;
32 var slotVal, typeVal, slottypes;
36 slotVal = slotStr.next(inval);
37 typeVal = typeStr.next(inval);
39 slottypes = [slotVal, typeVal].flop;
41 inval = slottypes.collect{ |it|
43 if ( device.slots[ it[1] ].isNil,
44 { "slot type not found".warn;
47 if ( device.slots[ it[1] ][ it[0] ].isNil,
48 { "slot not found".warn;
51 ret = device.slots[ it[1] ][ it[0] ].value;
69 // the Device list must have been built.
70 *new { arg key, device, repeats=inf;
71 ^super.new.init(key, device, repeats)
78 if ( device.isKindOf( GeneralHIDDevice ).not,
80 try { device = GeneralHID.open( device ); }{ "device argument is not a GeneralHIDDevice".error; ^nil }
84 storeArgs { ^[key, device, repeats] }
86 embedInStream { arg inval;
88 var keyStr = key.asStream;
93 keyVal = keyStr.next(inval);
94 keyVal = keyVal.asArray;
96 inval = keyVal.collect{ |it|
98 if ( device.at(it).isNil,
99 { "slot not found".warn;
102 ret = device.at( it ).value;