Skip to content

Commit

Permalink
Preload arg-generated Controls into NamedControl
Browse files Browse the repository at this point in the history
  • Loading branch information
avdrd committed Dec 21, 2021
1 parent cea67fc commit 82862d2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
11 changes: 8 additions & 3 deletions SCClassLibrary/Common/Audio/SynthDef.sc
Original file line number Diff line number Diff line change
Expand Up @@ -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

This comment has been minimized.

Copy link
@telephon

telephon Jan 2, 2022

I'd suggest to move currentControls from NamedControl to SynthDef. This will mean a few more edits, but it makes SynthDef responsible which seems better than entangling two classes.

result = func.valueArray(prependArgs ++ controlProxies);

controlNames = saveControlNames
controlNames = saveControlNames;

^result

}

addControlsFromArgsOfFunc { arg func, rates, skipArgs=0;
var def, names, values,argNames, specs;

Expand Down
15 changes: 15 additions & 0 deletions SCClassLibrary/Common/Control/GraphBuilder.sc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 82862d2

Please sign in to comment.