diff --git a/SCClassLibrary/Common/Audio/SynthDef.sc b/SCClassLibrary/Common/Audio/SynthDef.sc index 5f6c7166fa5..2c1cdb294d3 100644 --- a/SCClassLibrary/Common/Audio/SynthDef.sc +++ b/SCClassLibrary/Common/Audio/SynthDef.sc @@ -75,22 +75,27 @@ SynthDef { controlIndex = 0; maxLocalBufs = nil; } + buildUgenGraph { arg func, rates, prependArgs; var result; // save/restore controls in case of *wrap var saveControlNames = controlNames; + var controlProxies; controlNames = nil; prependArgs = prependArgs.asArray; this.addControlsFromArgsOfFunc(func, rates, prependArgs.size); - result = func.valueArray(prependArgs ++ this.buildControls); + // at this point this.controlNames is loaded with the ControlNames for the current func + controlProxies = this.buildControls; // OutputProxies for the Control objects + NamedControl.preload(controlProxies); // this.controlNames is also used in preload + result = func.valueArray(prependArgs ++ controlProxies); - controlNames = saveControlNames + controlNames = saveControlNames; ^result - } + addControlsFromArgsOfFunc { arg func, rates, skipArgs=0; var def, names, values,argNames, specs; diff --git a/SCClassLibrary/Common/Control/GraphBuilder.sc b/SCClassLibrary/Common/Control/GraphBuilder.sc index c75212425c8..6921059d36c 100644 --- a/SCClassLibrary/Common/Control/GraphBuilder.sc +++ b/SCClassLibrary/Common/Control/GraphBuilder.sc @@ -71,6 +71,21 @@ NamedControl { ^this.new(name, values, \trigger, lags, false, spec) } + *preload { arg controlProxies; + + this.initDict; // this also ensures buildSynthDef is valid + + buildSynthDef.controlNames.do { |cno, i| + currentControls.put( + cno.name, + super.newCopyArgs( + cno.name, cno.defaultValue.asArray, cno.lag, + cno.rate, true, controlProxies[i] + ) + ) + } + } + *new { arg name, values, rate, lags, fixedLag = false, spec; var res;