diff options
author | David Runge <dave@sleepmap.de> | 2018-03-18 00:57:06 +0100 |
---|---|---|
committer | David Runge <dave@sleepmap.de> | 2018-03-18 00:57:06 +0100 |
commit | 6a213f643bcee208afe6f1808e7ce4b634e39852 (patch) | |
tree | 44f738a741ab1dd3fd4df01522455cff0facecf4 /classes/MIDIDevice.sc | |
parent | 755cc2bc11e9c571c08df809935b68c5f4cf6652 (diff) | |
download | usbmidiism-6a213f643bcee208afe6f1808e7ce4b634e39852.tar.gz usbmidiism-6a213f643bcee208afe6f1808e7ce4b634e39852.tar.bz2 usbmidiism-6a213f643bcee208afe6f1808e7ce4b634e39852.tar.xz usbmidiism-6a213f643bcee208afe6f1808e7ce4b634e39852.zip |
Adding classes/MIDIState{,Manager}.sc, taking care of early stages of state management.
Making constructors more readable. Adding MIDIStateManager to USBMIDIIsm. Creating/recycling states for new and re-recognized MIDI devices.
Diffstat (limited to 'classes/MIDIDevice.sc')
-rw-r--r-- | classes/MIDIDevice.sc | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/classes/MIDIDevice.sc b/classes/MIDIDevice.sc index 9e7f2b1..f35be83 100644 --- a/classes/MIDIDevice.sc +++ b/classes/MIDIDevice.sc @@ -5,6 +5,7 @@ MIDIDevice{ <inPortNum, <outPortNum, <verbose, + <>states, <inPort, <outPort, <faders, @@ -15,8 +16,31 @@ MIDIDevice{ <passThroughs; *new{ - arg name, uid, inPortNum, outPortNum, verbose=false, faderSize=0, potiSize=0, buttonSize=0, jogwheelSize=0, touchpadSize=0; - ^super.newCopyArgs(name, uid, inPortNum, outPortNum, verbose).initDevice(faderSize, potiSize, buttonSize, jogwheelSize, touchpadSize); + arg name, + uid, + inPortNum, + outPortNum, + verbose=false, + states, + faderSize=0, + potiSize=0, + buttonSize=0, + jogwheelSize=0, + touchpadSize=0; + ^super.newCopyArgs( + name, + uid, + inPortNum, + outPortNum, + verbose, + states + ).initDevice( + faderSize, + potiSize, + buttonSize, + jogwheelSize, + touchpadSize + ); } initDevice{ @@ -27,6 +51,7 @@ MIDIDevice{ jogwheels = Array.newClear(indexedSize: jogwheelSize); touchpads = Array.newClear(indexedSize: touchpadSize); passThroughs = Dictionary(); +// states = MIDIState(); this.connectPorts(); postln("Device '"++name++"' initialized."); } @@ -145,4 +170,35 @@ MIDIDevice{ }); }); } + + connectStates{ + if(verbose,{ + postln("Setting up states for "++name); + }); + states.keysValuesDo({|channel, type| + MIDIdef.new( + key: ("state_"++uid++"_"++channel).asSymbol, + func: {arg ...args; + if(verbose,{ + ("state_"++uid++"_"++channel++": "++args).postln; + }); + case + {type==\control}{outPort.control(chan: channel, val: args[0])} + {type==\bend}{outPort.bend(chan: channel, val: args[0])} + {type==\midiClock}{outPort.midiClock} + {type==\bend}{outPort.bend(chan: channel, veloc: args[0])} + {type==\noteOn}{outPort.noteOn(chan: channel, note: args[1], veloc: args[0])} + {type==\noteOff}{outPort.noteOn(chan: channel, note: args[1], veloc: args[0])} + {type==\polyTouch}{outPort.polyTouch(chan: channel, note: args[1], val: args[0])} + {type==\program}{outPort.program(chan: channel, num: args[0])} + {type==\touch}{outPort.touch(chan: channel, val: args[0])} + {type==\start}{outPort.start} + {type==\stop}{outPort.stop} + {type==\continue}{outPort.continue}; + }, + chan: channel, + msgType: type, + ); + }); + } } |