From 22a4418392cb8a11170ba89805bf7c92ebf767f9 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 19 Mar 2018 22:57:01 +0100 Subject: classes/MIDIDevice.sc: Further specifying addSpec. Patching up connectPassThroughs (has to be moved). Implementing connectStates. --- classes/MIDIDevice.sc | 62 +++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/classes/MIDIDevice.sc b/classes/MIDIDevice.sc index f9e9372..a4bcb86 100644 --- a/classes/MIDIDevice.sc +++ b/classes/MIDIDevice.sc @@ -4,7 +4,7 @@ MIDIDevice{ verbose, <>states, 0, { - this.connectStates(); - }); this.connectPorts(); - postln("Device '"++name++"' initialized."); + postln("Device '"++name++"' (uid: "++uid++") initialized."); } addSpec{ - arg name, type, channel, minVal=0, maxVal=127, step=1, default=0, units=""; + arg name, type, channel, msgNum, minVal=0, maxVal=127, step=1, default=0, units=""; ^Dictionary.with(*[ \name->name, \type->type, \channel->channel, + \msgNum->msgNum, \spec->ControlSpec.new( minval: minVal, maxval: maxVal, @@ -129,6 +127,7 @@ MIDIDevice{ }); } + // TODO: this should be handled with a type of callback in MIDIStateManager connectPassThroughs{ if(passThroughs.notNil,{ if(verbose,{ @@ -155,8 +154,10 @@ MIDIDevice{ {type==\stop}{outPort.stop} {type==\continue}{outPort.continue}; }, - chan: channel, - msgType: type, + chan: channel.asInteger, +// msgNum: msgNum.asInteger, + msgType: type.asSymbol, + srcID: uid.asInteger ); }); }); @@ -177,30 +178,27 @@ MIDIDevice{ 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, - ); + Array.with(faders, potis, buttons, jogwheels, touchpads).do({|group, i| + group.do({|msgNum, i| + msgNum.do({|event, i| + MIDIdef.new( + key: ("state_"++uid++"_"++event.at(\name)++"_" + ++event.at(\type)).asSymbol, + func: {arg ...args; + if(verbose,{ + ("state_"++uid++"_"++event.at(\name)++"_"++event.at(\type)++ + ": "++args).postln; + }); + states.update(event.at(\name), event.at(\type), args[0], + event.at(\channel), event.at(\msgNum)); + }, + chan: event.at(\channel).asInteger, + msgNum: if(event.at(\msgNum).isInteger,{event.at(\msgNum)}), + msgType: event.at(\type).asSymbol, + srcID: uid.asInteger, + ); + }); + }); }); } } -- cgit v1.2.3