From 6a213f643bcee208afe6f1808e7ce4b634e39852 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 18 Mar 2018 00:57:06 +0100 Subject: Adding classes/MIDIState{,Manager}.sc, taking care of early stages of state management. Making constructors more readable. Adding MIDIStateManager to USBMIDIIsm. Creating/recycling states for new and re-recognized MIDI devices. --- classes/MIDIDevice.sc | 60 +++++++++++++++++++++++++++++++++++++++++++-- classes/MIDIState.sc | 21 ++++++++++++++++ classes/MIDIStateManager.sc | 41 +++++++++++++++++++++++++++++++ classes/NanoKontrol2.sc | 5 ++-- classes/PlatformMPlus.sc | 5 ++-- classes/USBMIDIIsm.sc | 35 ++++++++++++++++++++------ 6 files changed, 154 insertions(+), 13 deletions(-) create mode 100644 classes/MIDIState.sc create mode 100644 classes/MIDIStateManager.sc 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{ states, uid, <>inPortNum, <>outPortNum, 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 = 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