Synthdef set parameters

Synthdef …making presets
I put 1< parameters in a set to make presets for a single synthdef.
The issue is I first have to trigger the synth with w=synth , then I can click the w.set parameters
I would like to click the w.set parameters first and then trigger the synth but this gives a n set node failure
Is this possible ?

(

SynthDef(\effem,
{
   arg moddetune=1,modratio=2,carrierratio=1,carrierdetune=(-1),moddepth=8,att=4,decay=4.500;
   var mod,carrier,modenv;
   mod=SinOsc.ar(220+moddetune*modratio);
   modenv=EnvGen.ar(Env([0,1,0],[att,decay],[0,-2]),doneAction:2);
   mod=(moddepth*mod)*modenv;
   carrier=SinOsc.ar(220+carrierdetune*carrierratio,mod)*0.3!2;
   	Out.ar(0,carrier);
}).add
)




w=Synth(\effem);
w.set(\decay,2.5);
w.set(\at,2);
w.set(\moddepth,10)
w.set(\moddepth,5);
w.set(\moddepth,2);
w.set(\moddepth,100,\modratio,2,\moddetune,6,\carrierratio,1,\att,5,\decay,8);///lots of parameters in one 
w.free;

Also wonder why follwing code to make a stereo channel does not work on the final line of synthfdef

Out.ar(0,carrier)!2

To answer your first question, there are several ways to do this. Here are a few:

// 1. the "standard" way: an array of args as the 2nd argument to Synth:
w=Synth(\effem, [modratio: 6]);

// 2. start a paused Synth, then set args, then run:
w=Synth.newPaused(\effem);
w.set(\modratio, 6);
w.run;

// 3. make variants in the SynthDef:
(
SynthDef(\effem,
    {
        arg moddetune=1,modratio=2,carrierratio=1,carrierdetune=(-1),moddepth=8,att=4,decay=4.500;
        var mod,carrier,modenv;
        mod=SinOsc.ar(220+moddetune*modratio);
        modenv=EnvGen.ar(Env([0,1,0],[att,decay],[0,-2]),doneAction:2);
        mod=(moddepth*mod)*modenv;
        carrier=SinOsc.ar(220+carrierdetune*carrierratio,mod)*0.3!2;
        Out.ar(0,carrier);
    },
    variants: (
        modratio6: [modratio: 6],
        // add more variants here...
    )
).add
)

w=Synth('effem.modratio6');

I only ever use the first way, but I think it’s good to be aware of SynthDef variants.

To answer your 2nd question, Out.ar(0,carrier)!2 is equivalent to

[Out.ar(0, carrier), Out.ar(0, carrier)]

It is sending carrier to out 0 twice, which is redundant. What you meant is to send carrier to outs 0 and 1, which looks like this:

[Out.ar(0, carrier), Out.ar(1, carrier)]

But with Multichannel Expansion, you can write it like this:

Out.ar(0, [carrier, carrier])

which is more easily accomplished with the ! or dup method:

Out.ar(0, carrier!2);
2 Likes

About making variants in the synthdef , are those a new set of arguments because I don’t see them declared ?
Wouldnt it be easier to just put them all in one line ?
w.set(\ratio,6,\modindex,4,\carrierratio,2,\modratio,2);

Yes, put all the “preset” values for each variant in one array

variants: (
        preset1: [modratio: 6, carrierratio: 2, moddepth: 4],
        preset2: [modratio: 3, carrierratio: 5, moddetune: 3.7]
    )

The arguments were already declared at the top of the SynthDef, but I should point out that I am using \symbols (modratio, carrierratio, moddepth) in the variant arrays. These are not “arguments”.

[modratio: 6, carrierratio: 2, moddepth: 4]

is equivalent to

[\modratio, 6, \carrierratio, 2, \moddepth 4]

As with the set message, you use symbols in SynthDef variants to set the default values.
And as you mentioned, all args can be set in one line with the set message as well:

w.set(\ratio,6,\modindex,4,\carrierratio,2,\modratio,2);
1 Like