From 277292e7d7ea7c2275ea35ea40510b16c144593d Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 2 Feb 2018 21:02:41 +0100 Subject: 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. --- classes/MIDIDevice.sc | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 classes/MIDIDevice.sc (limited to 'classes/MIDIDevice.sc') 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, + \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; + }); + }); + } +} -- cgit v1.2.3-54-g00ecf