From 48d9b39b92e072b09fe7110685ffed2ef97078b9 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 19 Mar 2018 22:53:50 +0100 Subject: classes/MIDIState.sc: Adding update method to update data and banks (for now rudimentarily). Adding takeOver method to set takeover=true on all MIDIStateEvents. Adding convenience methods to post data and banks. Cleaning up variables. --- classes/MIDIState.sc | 54 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file 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 uid, <>inPortNum, <>outPortNum, connected=false; + var uid, <>inPortNum, <>outPortNum, <>verbose, 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; + }); + }); + } } + -- cgit v1.2.3-70-g09d2