summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--classes/MIDIDevice.sc60
-rw-r--r--classes/MIDIState.sc21
-rw-r--r--classes/MIDIStateManager.sc41
-rw-r--r--classes/NanoKontrol2.sc5
-rw-r--r--classes/PlatformMPlus.sc5
-rw-r--r--classes/USBMIDIIsm.sc35
6 files changed, 154 insertions, 13 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,
+ );
+ });
+ }
}
diff --git a/classes/MIDIState.sc b/classes/MIDIState.sc
new file mode 100644
index 0000000..2b3da3c
--- /dev/null
+++ b/classes/MIDIState.sc
@@ -0,0 +1,21 @@
+MIDIState{
+ var <name, <>uid, <>inPortNum, <>outPortNum, <data, <>connected=false;
+
+ *new{
+ arg name, uid, inPortNum, outPortNum;
+ ^super.newCopyArgs(
+ name,
+ uid,
+ inPortNum,
+ outPortNum
+ ).initState();
+ }
+
+ initState{
+ data = Dictionary();
+ connected = true;
+ }
+
+
+
+}
diff --git a/classes/MIDIStateManager.sc b/classes/MIDIStateManager.sc
new file mode 100644
index 0000000..ec4b53c
--- /dev/null
+++ b/classes/MIDIStateManager.sc
@@ -0,0 +1,41 @@
+MIDIStateManager{
+
+ var <deviceStates;
+
+ *new{
+ ^super.new.initManager();
+ }
+
+ initManager{
+ deviceStates = Array();
+ }
+
+ // request a state
+ // if a stored and unconnected state is available return that, else return a
+ // new MIDIState
+ requestState{
+ arg name, uid, inPortNum, outPortNum;
+ var devicePosition = -1, stateAvailable = false;
+ deviceStates.do({|storedDevice, i|
+ if((name == storedDevice.name) && (storedDevice.connected.not),{
+ stateAvailable = true;
+ devicePosition = i;
+ });
+ });
+ if(stateAvailable && (devicePosition >= 0),{
+ deviceStates[devicePosition].connected=true;
+ ^deviceStates[devicePosition];
+ },{
+ deviceStates = deviceStates.add(
+ MIDIState.new(name, uid, inPortNum, outPortNum)
+ );
+ ^deviceStates[deviceStates.size-1];
+ });
+ }
+
+ listStates{
+ deviceStates.do({|state, i|
+ postln(i.asString++": ["++state.name++", "++state.uid++", "++state.inPortNum++", "++state.outPortNum++", "++state.connected++"]");
+ });
+ }
+}
diff --git a/classes/NanoKontrol2.sc b/classes/NanoKontrol2.sc
index d0f79c9..43fafe0 100644
--- a/classes/NanoKontrol2.sc
+++ b/classes/NanoKontrol2.sc
@@ -1,11 +1,11 @@
NanoKontrol2 : MIDIDevice{
*new{
- arg name, uid, inPort, outPort, verbose;
+ arg name, uid, inPort, outPort, verbose, states;
var faderSize = 8,
potiSize = 8,
buttonSize = 36;
- ^super.new(name, uid, inPort, outPort, verbose, faderSize, potiSize, buttonSize).init;
+ ^super.new(name, uid, inPort, outPort, verbose, states, faderSize, potiSize, buttonSize).init;
}
init{
@@ -16,6 +16,7 @@ NanoKontrol2 : MIDIDevice{
cleanup{
super.disconnectPorts();
+ states.connected=false;
}
addButtons{
diff --git a/classes/PlatformMPlus.sc b/classes/PlatformMPlus.sc
index fc10aa1..999786d 100644
--- a/classes/PlatformMPlus.sc
+++ b/classes/PlatformMPlus.sc
@@ -1,12 +1,12 @@
PlatformMPlus : MIDIDevice{
*new{
- arg name, uid, inPort, outPort, verbose;
+ arg name, uid, inPort, outPort, verbose, states;
var faderSize = 9,
potiSize = 8,
buttonSize = 48,
jogwheelSize = 1;
- ^super.new(name, uid, inPort, outPort, verbose, faderSize, potiSize, buttonSize, jogwheelSize).init;
+ ^super.new(name, uid, inPort, outPort, verbose, states, faderSize, potiSize, buttonSize, jogwheelSize).init;
}
init{
@@ -21,6 +21,7 @@ PlatformMPlus : MIDIDevice{
cleanup{
super.disconnectPorts();
super.disconnectPassThroughs();
+ states.connected=false;
}
addPassThroughs{
diff --git a/classes/USBMIDIIsm.sc b/classes/USBMIDIIsm.sc
index 3a7518a..52e421b 100644
--- a/classes/USBMIDIIsm.sc
+++ b/classes/USBMIDIIsm.sc
@@ -1,6 +1,6 @@
USBMIDIIsm{
- var <devices, verbose;
+ var <devices, <stateManager, verbose;
*new{
arg setVerbose=false;
@@ -10,6 +10,7 @@ USBMIDIIsm{
init{
arg setVerbose;
devices = Array();
+ stateManager = MIDIStateManager();
verbose = setVerbose;
this.discoverDevices();
}
@@ -23,6 +24,7 @@ USBMIDIIsm{
postln("Resetting list of MIDI input devices.");
devices.do({|device,i|
if(device.inPortNum.notNil || device.outPortNum.notNil,{
+ // stateManager.store(device)?
device.cleanup();
});
});
@@ -42,6 +44,7 @@ USBMIDIIsm{
inEndPoint.device.contains("Announce")).not, {
// correlate with output devices
MIDIClient.destinations.do({|outEndPoint, outPortNum|
+ var device, state;
if((inEndPoint.device == outEndPoint.device &&
inEndPoint.uid == outEndPoint.uid), {
// available devices
@@ -49,11 +52,17 @@ USBMIDIIsm{
{inEndPoint.device.contains("Platform M+")} {
devices = devices.add(
PlatformMPlus.new(
- inEndPoint.device,
+ name: inEndPoint.device,
uid: inEndPoint.uid.asSymbol,
inPort: inPortNum,
outPort: outPortNum,
- verbose: verbose
+ verbose: verbose,
+ states: stateManager.requestState(
+ inEndPoint.device,
+ inEndPoint.uid.asSymbol,
+ inPortNum,
+ outPortNum
+ );
)
);
}
@@ -64,7 +73,13 @@ USBMIDIIsm{
uid: inEndPoint.uid.asSymbol,
inPort: inPortNum,
outPort: outPortNum,
- verbose: verbose
+ verbose: verbose,
+ states: stateManager.requestState(
+ inEndPoint.device,
+ inEndPoint.uid.asSymbol,
+ inPortNum,
+ outPortNum
+ );
)
);
};
@@ -75,12 +90,18 @@ USBMIDIIsm{
}
listDevices{
- postln("Name, uid, in, out");
- devices.do({|device|
- postln(device.name++", "++device.uid++", "++device.inPortNum++", "++device.outPortNum);
+ devices.do({|device, i|
+ postln(i.asString++": ["++device.name++", "++device.uid++", "++device.inPortNum++", "++device.outPortNum++"]");
});
}
+ setStates{
+ arg device;
+
+
+ }
+
+
listen{
arg listen = true;
if(listen, {