Skip to content

Add \all param option#108

Merged
capital-G merged 2 commits intomainfrom
all-param
Mar 6, 2026
Merged

Add \all param option#108
capital-G merged 2 commits intomainfrom
all-param

Conversation

@capital-G
Copy link
Copy Markdown
Owner

Improves passing metadata to params within transpiler

DynGenDef(\x).compile(#{
            ~phase = (~phase + (~p.freq(200.0, spec: \freq)/~srate)).wrap(0.0, 1.0);
            ~sig = sin(~phase * 2 * pi + (~sig * ~p.fb(0.0, spec: [0.0, 2.0])));
            ~out0 = ~sig;
}).send,

Also allows to pass \all as param value in DynGen, which creates a named control for every param present in the code (w/ associated control spec/init value when using the transpiler). This allows to write

(
Ndef(\z, {
    var sig = DynGen.ar(
        numOutputs: 1,
        script: DynGenDef(\x).compile(#{
            ~phase = (~phase + (~p.freq(200.0, spec: \freq)/~srate)).wrap(0.0, 1.0);
            ~sig = sin(~phase * 2 * pi + (~sig * ~p.fb(0.0, spec: [0.0, 2.0])));
            ~out0 = ~sig;
        }).send,
        params: \all,
    );
    sig.dup * 0.2;
}).play.gui;
)

This also works w/o the transpiler as seen in the test testPlainDynGenParamExtract.

also improve param metadata passing for DynGenTranspiler
@capital-G capital-G requested a review from Spacechild1 March 5, 2026 23:10
@capital-G capital-G added the enhancement New feature or request label Mar 5, 2026
inputs = inputs.asArray;
params = params.asArray;

if((params.size==1).and(params[0]==\all), {
Copy link
Copy Markdown
Collaborator

@Spacechild1 Spacechild1 Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the second operand of and is an expression, it should be in a function. This way it is only evaluated if the first operand is true (= short circuiting):

if ((params.size == 1) and: { params[0] == \all }) { ... }

Note that the function will be inlined.

If a parameter is not found in the DynGen code, you get a warning in the console.
It is not discarded, though, you can still use it when you update the code.

If CODE::params:: is set to CODE::\all::, it will expose all parameters of the script with as LINK::Classes/NamedControl:: with its associated LINK::Classes/ControlSpec:: using LINK::Classes/DynGenDef#-allParams::.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all parameters of the script with as

all parameters of the script as

];
}

allParams {
Copy link
Copy Markdown
Collaborator

@Spacechild1 Spacechild1 Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm... I would expect this method to just return an Array of all parameter names or something. I definitely wouldn't expect it to have side effects (= creating NamedControls) for the containing Synth.

Maybe something like paramControls or makeControls could be clearer?


allParams {
var allParams = [];
DynGenDef.prExtractParameters(code).do({|param|
Copy link
Copy Markdown
Collaborator

@Spacechild1 Spacechild1 Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This calls prExtractParameters everytime you create a new DynGen, although the parameters only change when the code changes. For this reason, wouldn't it make more sense to just call prRegisterParams in the code_ setter method (instead of in the send method)?

I guess we only want the parameters that are currently in the code. But this could be easily solved by keeping another array, e.g. prCurrentParams, that only contains the current parameters. We probably need this anyway when we expose the current parameters (and their specs) to the user.

also rename allParams method to privet prMakeControls method
@capital-G capital-G merged commit 4012cb6 into main Mar 6, 2026
5 checks passed
code_ {|newCode|
code = newCode;
prCurrentParams = DynGenDef.prExtractParameters(code);
this.prRegisterParams;
Copy link
Copy Markdown
Collaborator

@Spacechild1 Spacechild1 Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prRegisterParams calls prExtractParameters again!

Just remove the call to prExtractParameters here and modify prRegisterParams to store the extracted parameters in prCurrentParams.

capital-G added a commit that referenced this pull request Mar 6, 2026
capital-G added a commit that referenced this pull request Mar 6, 2026
capital-G added a commit that referenced this pull request Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants