diff options
author | David Runge <dave@sleepmap.de> | 2018-02-02 21:02:41 +0100 |
---|---|---|
committer | David Runge <dave@sleepmap.de> | 2018-02-02 21:02:41 +0100 |
commit | 277292e7d7ea7c2275ea35ea40510b16c144593d (patch) | |
tree | aaf854434f930c0c457ab0cba0bd47a5900ad20f | |
download | usbmidiism-277292e7d7ea7c2275ea35ea40510b16c144593d.tar.gz usbmidiism-277292e7d7ea7c2275ea35ea40510b16c144593d.tar.bz2 usbmidiism-277292e7d7ea7c2275ea35ea40510b16c144593d.tar.xz usbmidiism-277292e7d7ea7c2275ea35ea40510b16c144593d.zip |
classes: Adding first draft of USBMIDIIsm, allowing setting up and connecting of devices.
Mappings for Korg nanoKONTROL2 and ICON Platform M+ are included in the respective classes. MIDIDevice.sc serves as the common parent for all further specific implementations.
-rw-r--r-- | classes/MIDIDevice.sc | 148 | ||||
-rw-r--r-- | classes/NanoKontrol2.sc | 289 | ||||
-rw-r--r-- | classes/PlatformMPlus.sc | 463 | ||||
-rw-r--r-- | classes/USBMIDIIsm.sc | 131 |
4 files changed, 1031 insertions, 0 deletions
diff --git a/classes/MIDIDevice.sc b/classes/MIDIDevice.sc new file mode 100644 index 0000000..9e7f2b1 --- /dev/null +++ b/classes/MIDIDevice.sc @@ -0,0 +1,148 @@ +MIDIDevice{ + + var <name, + <uid, + <inPortNum, + <outPortNum, + <verbose, + <inPort, + <outPort, + <faders, + <potis, + <buttons, + <jogwheels, + <touchpads, + <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); + } + + initDevice{ + arg faderSize, potiSize, buttonSize, jogwheelSize, touchpadSize; + faders = Array.newClear(indexedSize: faderSize); + potis = Array.newClear(indexedSize: potiSize); + buttons = Array.newClear(indexedSize: buttonSize); + jogwheels = Array.newClear(indexedSize: jogwheelSize); + touchpads = Array.newClear(indexedSize: touchpadSize); + passThroughs = Dictionary(); + this.connectPorts(); + postln("Device '"++name++"' initialized."); + } + + addSpec{ + arg name, type, channel, minVal=0, maxVal=127, step=1, default=0, units=""; + ^Dictionary.with(*[ + \name->name, + \type->type, + \channel->channel, + \spec->ControlSpec.new( + minval: minVal, + maxval: maxVal, + step: step, + default: default, + units: units + ) + ]); + } + + connectPorts{ + if(inPortNum.notNil,{ + this.connectInPort(inPortNum); + }); + if(outPortNum.notNil,{ + this.connectOutPort(outPortNum); + }); + } + + connectInPort{ + arg inPortNum; + if(verbose,{ + postln("Connecting MIDIIn for "++name); + }); + inPort = MIDIIn.new(inPortNum); + MIDIIn.connect(inPortNum, inPortNum); + } + + connectOutPort{ + arg outPortNum; + if(verbose,{ + postln("Connecting MIDIOut for "++name); + }); + outPort = MIDIOut.new(outPortNum); + outPort.latency=0; + outPort.connect(outPortNum, outPortNum); + } + + disconnectPorts{ + this.disconnectInPort(); + this.disconnectOutPort(); + } + + disconnectInPort{ + if(inPort.notNil, { + if(verbose,{ + postln("Disconnecting MIDIIn for "++name); + }); + try{ + MIDIIn.disconnect(inPortNum, inPortNum); + } + }); + } + + disconnectOutPort{ + if(outPort.notNil, { + if(verbose,{ + postln("Disconnecting MIDIOut for "++name); + }); + try{ + outPort.disconnect(outPortNum, outPortNum); + } + }); + } + + connectPassThroughs{ + if(passThroughs.notNil,{ + if(verbose,{ + postln("Setting up passthroughs for "++name); + }); + passThroughs.keysValuesDo({|channel, type| + MIDIdef.new( + key: ("passThrough_"++uid++"_"++channel).asSymbol, + func: {arg ...args; + if(verbose,{ + ("passThrough_"++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, + ); + }); + }); + } + + disconnectPassThroughs{ + if(passThroughs.notNil,{ + if(verbose,{ + postln("Cleaning up passthroughs for "++name); + }); + passThroughs.keysValuesDo({|channel, type| + MIDIdef(("passThrough_"++uid++"_"++channel).asSymbol).free; + }); + }); + } +} diff --git a/classes/NanoKontrol2.sc b/classes/NanoKontrol2.sc new file mode 100644 index 0000000..d0f79c9 --- /dev/null +++ b/classes/NanoKontrol2.sc @@ -0,0 +1,289 @@ +NanoKontrol2 : MIDIDevice{ + + *new{ + arg name, uid, inPort, outPort, verbose; + var faderSize = 8, + potiSize = 8, + buttonSize = 36; + ^super.new(name, uid, inPort, outPort, verbose, faderSize, potiSize, buttonSize).init; + } + + init{ + this.addFaders(); + this.addPotis(); + this.addButtons(); + } + + cleanup{ + super.disconnectPorts(); + } + + addButtons{ + buttons.put(0, + List.newUsing([ + super.addSpec(\channel1Select, \control, 32, 0, 127), + ]); + ); + buttons.put(1, + List.newUsing([ + super.addSpec(\channel2Select, \control, 33, 0, 127), + ]); + ); + buttons.put(2, + List.newUsing([ + super.addSpec(\channel3Select, \control, 34, 0, 127), + ]); + ); + buttons.put(3, + List.newUsing([ + super.addSpec(\channel4Select, \control, 35, 0, 127), + ]); + ); + buttons.put(4, + List.newUsing([ + super.addSpec(\channel5Select, \control, 36, 0, 127), + ]); + ); + buttons.put(5, + List.newUsing([ + super.addSpec(\channel6Select, \control, 37, 0, 127), + ]); + ); + buttons.put(6, + List.newUsing([ + super.addSpec(\channel7Select, \control, 38, 0, 127), + ]); + ); + buttons.put(7, + List.newUsing([ + super.addSpec(\channel8Select, \control, 39, 0, 127), + ]); + ); + buttons.put(8, + List.newUsing([ + super.addSpec(\channel1Mute, \control, 48, 0, 127), + ]); + ); + buttons.put(9, + List.newUsing([ + super.addSpec(\channel2Mute, \control, 49, 0, 127), + ]); + ); + buttons.put(10, + List.newUsing([ + super.addSpec(\channel3Mute, \control, 50, 0, 127), + ]); + ); + buttons.put(11, + List.newUsing([ + super.addSpec(\channel4Mute, \control, 51, 0, 127), + ]); + ); + buttons.put(12, + List.newUsing([ + super.addSpec(\channel5Mute, \control, 52, 0, 127), + ]); + ); + buttons.put(13, + List.newUsing([ + super.addSpec(\channel6Mute, \control, 53, 0, 127), + ]); + ); + buttons.put(14, + List.newUsing([ + super.addSpec(\channel7Mute, \control, 54, 0, 127), + ]); + ); + buttons.put(15, + List.newUsing([ + super.addSpec(\channel8Mute, \control, 55, 0, 127), + ]); + ); + buttons.put(16, + List.newUsing([ + super.addSpec(\channel1Record, \control, 64, 0, 127), + ]); + ); + buttons.put(17, + List.newUsing([ + super.addSpec(\channel2Record, \control, 65, 0, 127), + ]); + ); + buttons.put(18, + List.newUsing([ + super.addSpec(\channel3Record, \control, 66, 0, 127), + ]); + ); + buttons.put(19, + List.newUsing([ + super.addSpec(\channel4Record, \control, 67, 0, 127), + ]); + ); + buttons.put(20, + List.newUsing([ + super.addSpec(\channel5Record, \control, 68, 0, 127), + ]); + ); + buttons.put(21, + List.newUsing([ + super.addSpec(\channel6Record, \control, 69, 0, 127), + ]); + ); + buttons.put(22, + List.newUsing([ + super.addSpec(\channel7Record, \control, 70, 0, 127), + ]); + ); + buttons.put(23, + List.newUsing([ + super.addSpec(\channel8Record, \control, 71, 0, 127), + ]); + ); + buttons.put(24, + List.newUsing([ + super.addSpec(\channel8Record, \control, 71, 0, 127), + ]); + ); + buttons.put(25, + List.newUsing([ + super.addSpec(\trackDown, \control, 58, 0, 127), + ]); + ); + buttons.put(26, + List.newUsing([ + super.addSpec(\trackUp, \control, 59, 0, 127), + ]); + ); + buttons.put(27, + List.newUsing([ + super.addSpec(\cycle, \control, 46, 0, 127), + ]); + ); + buttons.put(28, + List.newUsing([ + super.addSpec(\backwards, \control, 43, 0, 127), + ]); + ); + buttons.put(29, + List.newUsing([ + super.addSpec(\forwards, \control, 44, 0, 127), + ]); + ); + buttons.put(30, + List.newUsing([ + super.addSpec(\set, \control, 60, 0, 127), + ]); + ); + buttons.put(31, + List.newUsing([ + super.addSpec(\markerDown, \control, 61, 0, 127), + ]); + ); + buttons.put(32, + List.newUsing([ + super.addSpec(\markerUp, \control, 62, 0, 127), + ]); + ); + buttons.put(33, + List.newUsing([ + super.addSpec(\stop, \control, 42, 0, 127), + ]); + ); + buttons.put(34, + List.newUsing([ + super.addSpec(\play, \control, 41, 0, 127), + ]); + ); + buttons.put(35, + List.newUsing([ + super.addSpec(\record, \control, 45, 0, 127), + ]); + ); + } + + addPotis{ + potis.put(0, + List.newUsing([ + super.addSpec(\poti1, \control, 16, 0, 127), + ]); + ); + potis.put(1, + List.newUsing([ + super.addSpec(\poti2, \control, 17, 0, 127), + ]); + ); + potis.put(2, + List.newUsing([ + super.addSpec(\poti3, \control, 18, 0, 127), + ]); + ); + potis.put(3, + List.newUsing([ + super.addSpec(\poti4, \control, 19, 0, 127), + ]); + ); + potis.put(4, + List.newUsing([ + super.addSpec(\poti5, \control, 20, 0, 127), + ]); + ); + potis.put(5, + List.newUsing([ + super.addSpec(\poti6, \control, 21, 0, 127), + ]); + ); + potis.put(6, + List.newUsing([ + super.addSpec(\poti7, \control, 22, 0, 127), + ]); + ); + potis.put(7, + List.newUsing([ + super.addSpec(\poti8, \control, 23, 0, 127), + ]); + ); + } + + addFaders{ + faders.put(0, + List.newUsing([ + super.addSpec(\fader1, \control, 0, 0, 127), + ]); + ); + faders.put(1, + List.newUsing([ + super.addSpec(\fader2, \control, 1, 0, 127), + ]); + ); + faders.put(2, + List.newUsing([ + super.addSpec(\fader3, \control, 2, 0, 127), + ]); + ); + faders.put(3, + List.newUsing([ + super.addSpec(\fader4, \control, 3, 0, 127), + ]); + ); + faders.put(4, + List.newUsing([ + super.addSpec(\fader5, \control, 4, 0, 127), + ]); + ); + faders.put(5, + List.newUsing([ + super.addSpec(\fader6, \control, 5, 0, 127), + ]); + ); + faders.put(6, + List.newUsing([ + super.addSpec(\fader7, \control, 6, 0, 127), + ]); + ); + faders.put(7, + List.newUsing([ + super.addSpec(\fader8, \control, 7, 0, 127), + ]); + ); + } +} diff --git a/classes/PlatformMPlus.sc b/classes/PlatformMPlus.sc new file mode 100644 index 0000000..fc10aa1 --- /dev/null +++ b/classes/PlatformMPlus.sc @@ -0,0 +1,463 @@ +PlatformMPlus : MIDIDevice{ + + *new{ + arg name, uid, inPort, outPort, verbose; + var faderSize = 9, + potiSize = 8, + buttonSize = 48, + jogwheelSize = 1; + ^super.new(name, uid, inPort, outPort, verbose, faderSize, potiSize, buttonSize, jogwheelSize).init; + } + + init{ + this.addFaders(); + this.addPotis(); + this.addJogwheels(); + this.addButtons(); + this.addPassThroughs(); + super.connectPassThroughs(); + } + + cleanup{ + super.disconnectPorts(); + super.disconnectPassThroughs(); + } + + addPassThroughs{ + passThroughs.add(0->\bend); + passThroughs.add(1->\bend); + passThroughs.add(2->\bend); + passThroughs.add(3->\bend); + passThroughs.add(4->\bend); + passThroughs.add(5->\bend); + passThroughs.add(6->\bend); + passThroughs.add(7->\bend); + passThroughs.add(8->\bend); + } + + addButtons{ + buttons.put(0, + List.newUsing([ + super.addSpec(\channel1RecNoteOn, \noteOn, 0, 0, 127), + super.addSpec(\channel1RecNoteOff, \noteOff, 0, 0, 127), + ]); + ); + buttons.put(1, + List.newUsing([ + super.addSpec(\channel2RecNoteOn, \noteOn, 1, 0, 127), + super.addSpec(\channel2RecNoteOff, \noteOff, 1, 0, 127), + ]); + ); + buttons.put(2, + List.newUsing([ + super.addSpec(\channel3RecNoteOn, \noteOn, 2, 0, 127), + super.addSpec(\channel3RecNoteOff, \noteOff, 2, 0, 127), + ]); + ); + buttons.put(3, + List.newUsing([ + super.addSpec(\channel4RecNoteOn, \noteOn, 3, 0, 127), + super.addSpec(\channel4RecNoteOff, \noteOff, 3, 0, 127), + ]); + ); + buttons.put(4, + List.newUsing([ + super.addSpec(\channel5RecNoteOn, \noteOn, 4, 0, 127), + super.addSpec(\channel5RecNoteOff, \noteOff, 4, 0, 127), + ]); + ); + buttons.put(5, + List.newUsing([ + super.addSpec(\channel6RecNoteOn, \noteOn, 5, 0, 127), + super.addSpec(\channel6RecNoteOff, \noteOff, 5, 0, 127127), + ]); + ); + buttons.put(6, + List.newUsing([ + super.addSpec(\channel7RecNoteOn, \noteOn, 6, 0, 127), + super.addSpec(\channel7RecNoteOff, \noteOff, 6, 0, 127), + ]); + ); + buttons.put(7, + List.newUsing([ + super.addSpec(\channel8RecNoteOn, \noteOn, 7, 0, 127), + super.addSpec(\channel8RecNoteOff, \noteOff, 7, 0, 127), + ]); + ); + buttons.put(8, + List.newUsing([ + super.addSpec(\channel1SoloNoteOn, \noteOn, 8, 0, 127), + super.addSpec(\channel1SoloNoteOff, \noteOff, 8, 0, 127), + ]); + ); + buttons.put(9, + List.newUsing([ + super.addSpec(\channel2SoloNoteOn, \noteOn, 9, 0, 127), + super.addSpec(\channel2SoloNoteOff, \noteOff, 9, 0, 127), + ]); + ); + buttons.put(10, + List.newUsing([ + super.addSpec(\channel3SoloNoteOn, \noteOn, 10, 0, 127), + super.addSpec(\channel3SoloNoteOff, \noteOff, 10, 0, 127), + ]); + ); + buttons.put(11, + List.newUsing([ + super.addSpec(\channel4SoloNoteOn, \noteOn, 11, 0, 127), + super.addSpec(\channel4SoloNoteOff, \noteOff, 11, 0, 127), + ]); + ); + buttons.put(12, + List.newUsing([ + super.addSpec(\channel5SoloNoteOn, \noteOn, 12, 0, 127), + super.addSpec(\channel5SoloNoteOff, \noteOff, 12, 0, 127), + ]); + ); + buttons.put(13, + List.newUsing([ + super.addSpec(\channel6SoloNoteOn, \noteOn, 13, 0, 127), + super.addSpec(\channel6SoloNoteOff, \noteOff, 13, 0, 127), + ]); + ); + buttons.put(14, + List.newUsing([ + super.addSpec(\channel7SoloNoteOn, \noteOn, 14, 0, 127), + super.addSpec(\channel7SoloNoteOff, \noteOff, 14, 0, 127), + ]); + ); + buttons.put(15, + List.newUsing([ + super.addSpec(\channel8SoloNoteOn, \noteOn, 15, 0, 127), + super.addSpec(\channel8SoloNoteOff, \noteOff, 15, 0, 127), + ]); + ); + buttons.put(16, + List.newUsing([ + super.addSpec(\channel1MuteNoteOn, \noteOn, 16, 0, 127), + super.addSpec(\channel1MuteNoteOff, \noteOff, 16, 0, 127), + ]); + ); + buttons.put(17, + List.newUsing([ + super.addSpec(\channel2MuteNoteOn, \noteOn, 17, 0, 127), + super.addSpec(\channel2MuteNoteOff, \noteOff, 17, 0, 127), + ]); + ); + buttons.put(18, + List.newUsing([ + super.addSpec(\channel3MuteNoteOn, \noteOn, 18, 0, 127), + super.addSpec(\channel3MuteNoteOff, \noteOff, 18, 0, 127), + ]); + ); + buttons.put(19, + List.newUsing([ + super.addSpec(\channel4MuteNoteOn, \noteOn, 19, 0, 127), + super.addSpec(\channel4MuteNoteOff, \noteOff, 19, 0, 127), + ]); + ); + buttons.put(20, + List.newUsing([ + super.addSpec(\channel5MuteNoteOn, \noteOn, 20, 0, 127), + super.addSpec(\channel5MuteNoteOff, \noteOff, 20, 0, 127), + ]); + ); + buttons.put(21, + List.newUsing([ + super.addSpec(\channel6MuteNoteOn, \noteOn, 21, 0, 127), + super.addSpec(\channel6MuteNoteOff, \noteOff, 21, 0, 127), + ]); + ); + buttons.put(22, + List.newUsing([ + super.addSpec(\channel7MuteNoteOn, \noteOn, 22, 0, 127), + super.addSpec(\channel7MuteNoteOff, \noteOff, 22, 0, 127), + ]); + ); + buttons.put(23, + List.newUsing([ + super.addSpec(\channel8MuteNoteOn, \noteOn, 23, 0, 127), + super.addSpec(\channel8MuteNoteOff, \noteOff, 23, 0, 127), + ]); + ); + buttons.put(24, + List.newUsing([ + super.addSpec(\channel1SelectNoteOn, \noteOn, 24, 0, 127), + super.addSpec(\channel1SelectNoteOff, \noteOff, 24, 0, 127), + ]); + ); + buttons.put(25, + List.newUsing([ + super.addSpec(\channel2SelectNoteOn, \noteOn, 25, 0, 127), + super.addSpec(\channel2SelectNoteOff, \noteOff, 25, 0, 127), + ]); + ); + buttons.put(26, + List.newUsing([ + super.addSpec(\channel3SelectNoteOn, \noteOn, 26, 0, 127), + super.addSpec(\channel3SelectNoteOff, \noteOff, 26, 0, 127), + ]); + ); + buttons.put(27, + List.newUsing([ + super.addSpec(\channel4SelectNoteOn, \noteOn, 27, 0, 127), + super.addSpec(\channel4SelectNoteOff, \noteOff, 27, 0, 127), + ]); + ); + buttons.put(28, + List.newUsing([ + super.addSpec(\channel5SelectNoteOn, \noteOn, 28, 0, 127), + super.addSpec(\channel5SelectNoteOff, \noteOff, 28, 0, 127), + ]); + ); + buttons.put(29, + List.newUsing([ + super.addSpec(\channel6SelectNoteOn, \noteOn, 29, 0, 127), + super.addSpec(\channel6SelectNoteOff, \noteOff, 29, 0, 127), + ]); + ); + buttons.put(30, + List.newUsing([ + super.addSpec(\channel7SelectNoteOn, \noteOn, 30, 0, 127), + super.addSpec(\channel7SelectNoteOff, \noteOff, 30, 0, 127), + ]); + ); + buttons.put(31, + List.newUsing([ + super.addSpec(\channel8SelectNoteOn, \noteOn, 31, 0, 127), + super.addSpec(\channel8SelectNoteOff, \noteOff, 31, 0, 127), + ]); + ); + buttons.put(32, + List.newUsing([ + super.addSpec(\channel8SelectNoteOn, \noteOn, 31, 0, 127), + super.addSpec(\channel8SelectNoteOff, \noteOff, 31, 0, 127), + ]); + ); + buttons.put(33, + List.newUsing([ + super.addSpec(\flipBankDownNoteOn, \noteOn, 46, 0, 127), + super.addSpec(\flipBankDownNoteOff, \noteOff, 46, 0, 127), + ]); + ); + buttons.put(34, + List.newUsing([ + super.addSpec(\flipBankUpNoteOn, \noteOn, 47, 0, 127), + super.addSpec(\flipBankUpNoteOff, \noteOff, 47, 0, 127), + ]); + ); + buttons.put(35, + List.newUsing([ + super.addSpec(\flipChanDownNoteOn, \noteOn, 48, 0, 127), + super.addSpec(\flipChanDownNoteOff, \noteOff, 48, 0, 127), + ]); + ); + buttons.put(36, + List.newUsing([ + super.addSpec(\flipChanUpNoteOn, \noteOn, 49, 0, 127), + super.addSpec(\flipChanUpNoteOff, \noteOff, 49, 0, 127), + ]); + ); + buttons.put(37, + List.newUsing([ + super.addSpec(\flipChanUpNoteOn, \noteOn, 49, 0, 127), + super.addSpec(\flipChanUpNoteOff, \noteOff, 49, 0, 127), + ]); + ); + buttons.put(38, + List.newUsing([ + super.addSpec(\readNoteOn, \noteOn, 74, 0, 127), + super.addSpec(\readNoteOff, \noteOff, 74, 0, 127), + ]); + ); + buttons.put(39, + List.newUsing([ + super.addSpec(\writeNoteOn, \noteOn, 75, 0, 127), + super.addSpec(\writeNoteOff, \noteOff, 75, 0, 127), + ]); + ); + buttons.put(40, + List.newUsing([ + super.addSpec(\mixerNoteOn, \noteOn, 78, 0, 127), + super.addSpec(\mixerNoteOff, \noteOff, 78, 0, 127), + ]); + ); + buttons.put(41, + List.newUsing([ + super.addSpec(\rewindNoteOn, \noteOn, 86, 0, 127), + super.addSpec(\rewindNoteOff, \noteOff, 86, 0, 127), + ]); + ); + buttons.put(42, + List.newUsing([ + super.addSpec(\transDownNoteOn, \noteOn, 91, 0, 127), + super.addSpec(\transDownNoteOff, \noteOff, 91, 0, 127), + ]); + ); + buttons.put(43, + List.newUsing([ + super.addSpec(\transUpNoteOn, \noteOn, 92, 0, 127), + super.addSpec(\transUpNoteOff, \noteOff, 92, 0, 127), + ]); + ); + buttons.put(44, + List.newUsing([ + super.addSpec(\stopNoteOn, \noteOn, 93, 0, 127), + super.addSpec(\stopNoteOff, \noteOff, 93, 0, 127), + ]); + ); + buttons.put(45, + List.newUsing([ + super.addSpec(\playNoteOn, \noteOn, 94, 0, 127), + super.addSpec(\playNoteOff, \noteOff, 94, 0, 127), + ]); + ); + buttons.put(46, + List.newUsing([ + super.addSpec(\recordNoteOn, \noteOn, 95, 0, 127), + super.addSpec(\recordNoteOff, \noteOff, 95, 0, 127), + ]); + ); + buttons.put(47, + List.newUsing([ + super.addSpec(\zoomNoteOn, \noteOn, 100, 0, 127), + super.addSpec(\zoomNoteOff, \noteOff, 100, 0, 127), + ]); + ); + } + + addJogwheels{ + jogwheels.put(0, + List.newUsing([ + super.addSpec(\jogwheel1Control, \control, 60, 0, 127), + super.addSpec(\jogwheel1NoteOn, \noteOn, 101, 0, 127), + super.addSpec(\jogwheel1NoteOff, \noteOff, 101, 0, 127) + ]) + ); + } + + addPotis{ + potis.put(0, + List.newUsing([ + super.addSpec(\poti1Control, \control, 16, 0, 127), + super.addSpec(\poti1NoteOn, \noteOn, 32, 0, 127), + super.addSpec(\poti1NoteOff, \noteOff, 32, 0, 127) + ]) + ); + potis.put(1, + List.newUsing([ + super.addSpec(\poti2Control, \control, 17, 0, 127), + super.addSpec(\poti2NoteOn, \noteOn, 33, 0, 127), + super.addSpec(\poti2NoteOff, \noteOff, 33, 0, 127) + ]) + ); + potis.put(2, + List.newUsing([ + super.addSpec(\poti3Control, \control, 18, 0, 127), + super.addSpec(\poti3NoteOn, \noteOn, 34, 0, 127), + super.addSpec(\poti3NoteOff, \noteOff, 34, 0, 127) + ]) + ); + potis.put(3, + List.newUsing([ + super.addSpec(\poti4Control, \control, 19, 0, 127), + super.addSpec(\poti4NoteOn, \noteOn, 35, 0, 127), + super.addSpec(\poti4NoteOff, \noteOff, 35, 0, 127) + ]) + ); + potis.put(4, + List.newUsing([ + super.addSpec(\poti5Control, \control, 20, 0, 127), + super.addSpec(\poti5NoteOn, \noteOn, 36, 0, 127), + super.addSpec(\poti5NoteOff, \noteOff, 36, 0, 127) + ]) + ); + potis.put(5, + List.newUsing([ + super.addSpec(\poti6Control, \control, 21, 0, 127), + super.addSpec(\poti6NoteOn, \noteOn, 37, 0, 127), + super.addSpec(\poti6NoteOff, \noteOff, 37, 0, 127) + ]) + ); + potis.put(6, + List.newUsing([ + super.addSpec(\poti7Control, \control, 22, 0, 127), + super.addSpec(\poti7NoteOn, \noteOn, 38, 0, 127), + super.addSpec(\poti7NoteOff, \noteOff, 38, 0, 127) + ]) + ); + potis.put(7, + List.newUsing([ + super.addSpec(\poti8Control, \control, 23, 0, 127), + super.addSpec(\poti8NoteOn, \noteOn, 39, 0, 127), + super.addSpec(\poti8NoteOff, \noteOff, 39, 0, 127) + ]) + ); + } + + addFaders{ + faders.put(0, + List.newUsing([ + super.addSpec(\fader1, \bend, 0, 0, 16383), + super.addSpec(\fader1NoteOn, \noteOn, 104, 0, 127), + super.addSpec(\fader1NoteOff, \noteOff, 104, 0, 127) + ]) + ); + faders.put(1, + List.newUsing([ + super.addSpec(\fader2, \bend, 1, 0, 16383), + super.addSpec(\fader2NoteOn, \noteOn, 105, 0, 127), + super.addSpec(\fader2NoteOff, \noteOff, 105, 0, 127) + ]) + ); + faders.put(2, + List.newUsing([ + super.addSpec(\fader3, \bend, 2, 0, 16383), + super.addSpec(\fader3NoteOn, \noteOn, 106, 0, 127), + super.addSpec(\fader3NoteOff, \noteOff, 106, 0, 127) + ]) + ); + faders.put(3, + List.newUsing([ + super.addSpec(\fader4, \bend, 3, 0, 16383), + super.addSpec(\fader4NoteOn, \noteOn, 107, 0, 127), + super.addSpec(\fader4NoteOff, \noteOff, 107, 0, 127) + ]) + ); + faders.put(4, + List.newUsing([ + super.addSpec(\fader5, \bend, 4, 0, 16383), + super.addSpec(\fader5NoteOn, \noteOn, 108, 0, 127), + super.addSpec(\fader5NoteOff, \noteOff, 108, 0, 127) + ]) + ); + faders.put(5, + List.newUsing([ + super.addSpec(\fader6, \bend, 5, 0, 16383), + super.addSpec(\fader6NoteOn, \noteOn, 109, 0, 127), + super.addSpec(\fader6NoteOff, \noteOff, 109, 0, 127) + ]) + ); + faders.put(6, + List.newUsing([ + super.addSpec(\fader7, \bend, 6, 0, 16383), + super.addSpec(\fader7NoteOn, \noteOn, 110, 0, 127), + super.addSpec(\fader7NoteOff, \noteOff, 110, 0, 127) + ]) + ); + faders.put(7, + List.newUsing([ + super.addSpec(\fader8, \bend, 7, 0, 16383), + super.addSpec(\fader8NoteOn, \noteOn, 111, 0, 127), + super.addSpec(\fader8NoteOff, \noteOff, 111, 0, 127) + ]) + ); + faders.put(8, + List.newUsing([ + super.addSpec(\fader9, \bend, 8, 0, 16383), + super.addSpec(\fader9NoteOn, \noteOn, 112, 0, 127), + super.addSpec(\fader9NoteOff, \noteOff, 112, 0, 127) + ]) + ); + } +} diff --git a/classes/USBMIDIIsm.sc b/classes/USBMIDIIsm.sc new file mode 100644 index 0000000..3a7518a --- /dev/null +++ b/classes/USBMIDIIsm.sc @@ -0,0 +1,131 @@ +USBMIDIIsm{ + + var <devices, verbose; + + *new{ + arg setVerbose=false; + ^super.new.init(setVerbose); + } + + init{ + arg setVerbose; + devices = Array(); + verbose = setVerbose; + this.discoverDevices(); + } + + discoverDevices{ + if(MIDIClient.initialized.not,{ + postln("Initializing MIDIClient..."); + MIDIClient.init(verbose: verbose); + },{ + if(devices.size > 0, { + postln("Resetting list of MIDI input devices."); + devices.do({|device,i| + if(device.inPortNum.notNil || device.outPortNum.notNil,{ + device.cleanup(); + }); + }); + devices = Array(); + }); + postln("Restarting MIDIClient..."); + MIDIClient.disposeClient; + MIDIClient.init(verbose: verbose); + }); + + postln("Scanning for MIDI devices..."); + //TODO: find way to select in/out-only devices + MIDIClient.sources.do({ |inEndPoint, inPortNum| + if((inEndPoint.device.contains("SuperCollider") || + inEndPoint.device.contains("Midi Through") || + inEndPoint.device.contains("Timer") || + inEndPoint.device.contains("Announce")).not, { + // correlate with output devices + MIDIClient.destinations.do({|outEndPoint, outPortNum| + if((inEndPoint.device == outEndPoint.device && + inEndPoint.uid == outEndPoint.uid), { + // available devices + case + {inEndPoint.device.contains("Platform M+")} { + devices = devices.add( + PlatformMPlus.new( + inEndPoint.device, + uid: inEndPoint.uid.asSymbol, + inPort: inPortNum, + outPort: outPortNum, + verbose: verbose + ) + ); + } + {inEndPoint.device.contains("nanoKONTROL2")} { + devices = devices.add( + NanoKontrol2.new( + inEndPoint.device, + uid: inEndPoint.uid.asSymbol, + inPort: inPortNum, + outPort: outPortNum, + verbose: verbose + ) + ); + }; + }); + }); + }); + }); + } + + listDevices{ + postln("Name, uid, in, out"); + devices.do({|device| + postln(device.name++", "++device.uid++", "++device.inPortNum++", "++device.outPortNum); + }); + } + + listen{ + arg listen = true; + if(listen, { + MIDIdef.cc(\listen_cc, {arg ...args; ("control : "++args).postln}); + MIDIdef.noteOn(\listen_noteOn, {arg ...args; ("noteOn : "++args).postln}); + MIDIdef.noteOff(\listen_noteOff, {arg ...args; ("noteOff : "++args).postln}); + MIDIdef.polytouch(\listen_polytouch, {arg ...args; ("polyTouch: "++args).postln}); + MIDIdef.touch(\listen_touch, {arg ...args; ("touch: "++args).postln}); + MIDIdef.bend(\listen_bend, {arg ...args; ("bend: "++args).postln}); + MIDIdef.program(\listen_program, {arg ...args; ("program: "++args).postln}); + // TODO: find something for sysex (too noisy) + // MIDIdef.sysex(\listen_sysex, {arg ...args; ("sysex: "++args).postln}); + MIDIdef.smpte(\listen_smpte, {arg ...args; ("smpte: "++args).postln}); + MIDIdef.songPosition(\listen_songPosition, {arg ...args; ("songPosition: "++args).postln}); + MIDIdef.songSelect(\listen_songSelect, {arg ...args; ("songSelect: "++args).postln}); + MIDIdef.tuneRequest(\listen_tuneRequest, {arg ...args; ("tuneRequest: "++args).postln}); + MIDIdef.midiClock(\listen_midiClock, {arg ...args; ("midiClock: "++args).postln}); + MIDIdef.sysrt(\listen_sysrt, {arg ...args; ("sysrt: "++args).postln}); + MIDIdef.tick(\listen_tick, {arg ...args; ("tick: "++args).postln}); + MIDIdef.start(\listen_start, {arg ...args; ("start: "++args).postln}); + MIDIdef.stop(\listen_stop, {arg ...args; ("stop: "++args).postln}); + MIDIdef.continue(\listen_continue, {arg ...args; ("continue: "++args).postln}); + MIDIdef.reset(\listen_reset, {arg ...args; ("reset: "++args).postln}); + MIDIdef.activeSense(\listen_activeSense, {arg ...args; ("activeSense: "++args).postln}); + }, { + MIDIdef(\listen_cc).free; + MIDIdef(\listen_noteOn).free; + MIDIdef(\listen_noteOff).free; + MIDIdef(\listen_polytouch).free; + MIDIdef(\listen_touch).free; + MIDIdef(\listen_bend).free; + MIDIdef(\listen_program).free; +// MIDIdef(\listen_sysex).free; + MIDIdef(\listen_smpte).free; + MIDIdef(\listen_songPosition).free; + MIDIdef(\listen_songSelect).free; + MIDIdef(\listen_tuneRequest).free; + MIDIdef(\listen_midiClock).free; + MIDIdef(\listen_sysrt).free; + MIDIdef(\listen_tick).free; + MIDIdef(\listen_start).free; + MIDIdef(\listen_stop).free; + MIDIdef(\listen_continue).free; + MIDIdef(\listen_reset).free; + MIDIdef(\listen_activeSense).free; + }); + } +} |