I have this help class that takes care of setting up control busses for a 16n Faderbank.
Thought I would share, and also invite some criticism.
One plan I have is to allow for custom midi message setting, since it is now defaulted to the midi numbers the device default setting sends to.
Another is to handle several instances, through maybe an Dictionary, in case 16 faders are not enough. Perhaps by using the uid number as a key.
/*
* 16n Supercollider Class
*/
SixteenFaders {
classvar func = nil;
var <fader;
var enable = true;
var physical = true;
var id;
*new {
^super.new.init();
}
init {
var found = "16n found";
var server = Server.default;
var sources;
MIDIClient.init();
MIDIIn.connectAll;
sources = MIDIClient.sources;
// Check if 16n is in MIDIEndPoints, store uid in global var.
(
sources.do{|source|
if (source.device == "16n") {
id = source.uid;
found.postln;
physical = true;
};
};
);
// MIDIdef with correct midi \uid (srcID)
(
fader = 16.collect{
Bus.control(server, 1);
};
if (func.isNil == false) {
// free existing midifunc
func.free;
};
if (physical) {
func = MIDIFunc.new({
|val, num, chan, src|
if (enable) {
("*** Fader: " ++ '[ ' ++ (num - 32) ++ ' ]' ++
" Value: " ++ '[ ' ++ val ++ ' ]').postln;
};
switch(num,
32, { fader[0].set(val.linlin(0,127,0,1)) },
33, { fader[1].set(val.linlin(0,127,0,1)) },
34, { fader[2].set(val.linlin(0,127,0,1)) },
35, { fader[3].set(val.linlin(0,127,0,1)) },
36, { fader[4].set(val.linlin(0,127,0,1)) },
37, { fader[5].set(val.linlin(0,127,0,1)) },
38, { fader[6].set(val.linlin(0,127,0,1)) },
39, { fader[7].set(val.linlin(0,127,0,1)) },
40, { fader[8].set(val.linlin(0,127,0,1)) },
41, { fader[9].set(val.linlin(0,127,0,1)) },
42, { fader[10].set(val.linlin(0,127,0,1)) },
43, { fader[11].set(val.linlin(0,127,0,1)) },
44, { fader[12].set(val.linlin(0,127,0,1)) },
45, { fader[13].set(val.linlin(0,127,0,1)) },
46, { fader[14].set(val.linlin(0,127,0,1)) },
47, { fader[15].set(val.linlin(0,127,0,1)) },
)
}, msgNum: Array.series(16,32,1), chan: 0, msgType: \control, srcID: id);
} {
postln("No 16n was found, no MIDIFunc created");
// TODO: Create a mock QT faderbank for testing
}
);
}
faderAt {|faderPosition|
^fader[faderPosition];
}
enablePost {
enable = true;
}
disablePost {
enable = false;
}
usage {
var usage = "Usage: A 'Bus' object is accessed by <instance of object>.fader[n] or \n<instance of object>.faderAt(n). 'n' is the corresponding fader number, \nbut zero-indexed. ('0' gets you the first fader)\n";
Post << "|----------------------------------------------------------------------//\n" << usage << "|----------------------------------------------------------------------//\n";
}
}