summaryrefslogtreecommitdiffstats
path: root/classes/USBMIDIIsm.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/USBMIDIIsm.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/USBMIDIIsm.sc')
-rw-r--r--classes/USBMIDIIsm.sc131
1 files changed, 131 insertions, 0 deletions
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;
+ });
+ }
+}