summaryrefslogtreecommitdiffstats
path: root/classes/MIDIDevice.sc
diff options
context:
space:
mode:
authorDavid Runge <dave@sleepmap.de>2018-02-02 21:02:41 +0100
committerDavid Runge <dave@sleepmap.de>2018-02-02 21:02:41 +0100
commit277292e7d7ea7c2275ea35ea40510b16c144593d (patch)
treeaaf854434f930c0c457ab0cba0bd47a5900ad20f /classes/MIDIDevice.sc
downloadusbmidiism-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.
Diffstat (limited to 'classes/MIDIDevice.sc')
-rw-r--r--classes/MIDIDevice.sc148
1 files changed, 148 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;
+ });
+ });
+ }
+}