summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--classes/MIDIState.sc54
1 files changed, 51 insertions, 3 deletions
diff --git a/classes/MIDIState.sc b/classes/MIDIState.sc
index 2b3da3c..40c4b0f 100644
--- a/classes/MIDIState.sc
+++ b/classes/MIDIState.sc
@@ -1,21 +1,69 @@
MIDIState{
- var <name, <>uid, <>inPortNum, <>outPortNum, <data, <>connected=false;
+ var <name, <>uid, <>inPortNum, <>outPortNum, <>verbose, <data, <banks,
+ <currentBank, <>connected=false;
*new{
- arg name, uid, inPortNum, outPortNum;
+ arg name, uid, inPortNum, outPortNum, verbose;
^super.newCopyArgs(
name,
uid,
inPortNum,
- outPortNum
+ outPortNum,
+ verbose
).initState();
}
initState{
data = Dictionary();
+ banks = Dictionary();
+ currentBank = 0;
connected = true;
}
+ update{
+ arg name, type, value, chan, msgNum;
+ if(verbose,{
+ postln(name++": ["++name.asString++", "++chan.asString++
+ ", "++type.asString++", " ++value.asString++"]");
+ });
+ // TODO: check whether event is a bankUp/bankDown event
+ data.add(name -> MIDIStateEvent.new(type.asString, value, chan, msgNum));
+ // if a bank-able event is changed
+ if("(channel|fader|button|poti)[1-9]".matchRegexp(name.asString),{
+ // create current bank, if not available yet
+ if(banks.at(currentBank).isKindOf(Dictionary).not,{
+ banks.add(currentBank -> Dictionary.new());
+ });
+ banks.at(currentBank).add(name -> MIDIStateEvent.new(type.asString,
+ value, chan, msgNum));
+ });
+ }
+
+ postData{
+ data.keysValuesDo({|name,event|
+ post(name++" -> ");
+ event.postln;
+ });
+ }
+ postBanks{
+ banks.keysValuesDo({|number,bank|
+ postln("Bank "++number++":");
+ bank.keysValuesDo({|name,event|
+ post(name++" -> ");
+ event.postln;
+ });
+ });
+ }
+
+ // set takeOver to true for all available MIDIStateEvents
+ takeOver{
+ [banks, data].do({|dict|
+ dict.valuesDo({|event|
+ event.takeOver=true;
+ });
+ });
+ }
}
+