Why is \argument.ir recognized but a variable.ir containing the same is not

I am trying to learn from this example Control | SuperCollider 3.12.0 Help and can’t seem to understand how does this exactly work

(
SynthDef(\test, { arg out=0, i_freq;
    var klank, n, harm, amp, ring;

    harm = \iharm.ir(Array.series(4, 1, 1));
	
    amp = \amp.ir(Array.fill(4, 0.05));
    
    ring = \ring.ir(Array.fill(4, 1));

    klank = Klank.ar(`[harm, amp, ring], {ClipNoise.ar(0.003)}.dup, i_freq);

    Out.ar(out, klank);
}).add;
)

Then you can pass \harm as a parameter like this

Synth(\test, [\i_freq, 500, \iharm, [4, 1, 4, 6]]);

and it works

However, when i try to make the harm unparametrized, and set its values dynamically by some other logic inside the synthdef


(
SynthDef(\test, { arg out=0, i_freq;
    var klank, n, harm, amp, ring;
    var iharm = [4, 1, 4, round(MouseX.kr(1,6))];

    harm = \iharm.ir(Array.series(4, 1, 1));
	
    amp = \amp.ir(Array.fill(4, 0.05));
    
    ring = \ring.ir(Array.fill(4, 1));

    klank = Klank.ar(`[harm, amp, ring], {ClipNoise.ar(0.003)}.dup, i_freq);

    Out.ar(out, klank);
}).add;
)

I get an error Message 'ir' not understood.

Why is that? And how can i control these variables inside synthdef rather than have them as an argument?

If you want it to be unparameterized, then there should be no line related to iharm.ir or \iharm.ir. These are the lines that establish the external parameter – so, it shouldn’t be there if you don’t want an external parameter.

hjh

then how do i apply the array [4, 1, 4, 6] to Array.series(4, 1, 1), so it produces the same sound as the first example code without a parameter?

In a word, you don’t.

In the unmodified example, \iharm.ir(Array.series(4, 1, 1)) creates a NamedControl (a parameter), and the default value of this parameter (if it’s left unset) comes from the Array.series.

So the only reason for the Array.series is to complete the definition of the parameter. It has no other purpose here.

Now, you’re saying you want to remove the iharm parameter and replace it with an array that you’re building yourself. This means you don’t need \iharm.ir. And… if the parameter is gone, and the Array.series only gives the parameter’s default, then the default array should be deleted too.

So there is no “apply one array to another array.” You only need the one array.

I guess you’re trying to ir any UGens in your own array… It doesn’t work exactly like that. What you can do is sample-and-hold based on an initial impulse:


(
SynthDef(\test, { arg out=0, i_freq;
    var klank, n, harm, amp, ring;
    var initTrig = Impulse.kr(0);

    var iharm = [
        4, 1, 4, 
        Latch.kr(round(MouseX.kr(1,6)), initTrig)
    ];

    // iharm.ir line is *completely* deleted!
	
    amp = \amp.ir(Array.fill(4, 0.05));    
    ring = \ring.ir(Array.fill(4, 1));

    // just use iharm here
    klank = Klank.ar(`[iharm, amp, ring], {ClipNoise.ar(0.003)}.dup, i_freq);

    Out.ar(out, klank);
}).add;
)

But actually, the Latch and initTrig aren’t needed in this specific case because all inputs to Klank are already treated as ir.

hjh

1 Like

okay, thank you very much for the explanation, i misunderstood the syntax of the NamedControl in the middle of the function and didn’t realize the function parameters are just default values