Thanks to suggestions here, I’ve written a cleaned-up version of my BusPlug.value
bugfix that doesn’t stuff more methods in the base classes.
+ BusPlug {
value { | something |
var n;
if(UGen.buildSynthDef.isNil) { ^this }; // only return when in ugen graph.
if(something.notNil) {
if(something.isKindOf(UGen.class) or: { something.isKindOf(UGen) }) {
// UGen.numChannels always 1, so let InBus.new1 ultimately called by this.ar/.kr
// auto-detect numChannels by keeping n=nil for the call to this.ar/.kr below.
// Certainly need to do this in the case of UGens classes that can't be
// flagged by something.isUGen, which is an instance method,
// e.g. CombN.isUGen == false while CombN.ar.isUGen == true
//("is UG or UGC" + something + n).postln
} {
n = something.numChannels
}
};
//"bpv2: % is_UGen:% is_UGen.class:% n:% ".format(something, something.isKindOf(UGen), something.isKindOf(UGen.class), n).postln;
^if(something.respondsTo(\rate) and: { something.rate == 'audio'} or: { this.rate == \audio }) {
this.ar(n)
} {
this.kr(n)
}
}
}