Array vs Event sintax for argument passing in Synth

Hi all,

I’m running into a confusing issue when passing arguments to a synth, and I’d like to understand what’s going on.

I have a simple SynthDef using PlayBuf:

(
SynthDef(\playBufTest, {
|out=0, buf|

var sig;

sig = PlayBuf.ar(
    2,
    buf,
    BufRateScale.kr(buf),
    doneAction: 2
);

Out.ar(out, sig);

}).add;
)

Buffers are loaded correctly into an Event like:

When I call the synth using an array of key-value pairs, everything works as expected:

Synth(\playBufTest, [\buf, ~buffers[\B][2]]);

But when I use an Event-style arguments syntax:

Synth(\playBufTest, (buf: ~buffers[\A][2]));

it always plays buffer 0 (i.e. the first buffer), regardless of the index or function (i.e. choose) I specify. I checked and the buffers are correctly loaded, the only thing that is changing is the way I assign the arguments.

Why does passing arguments as an Event behave differently from the Array form in this case?

Is this: expected behavior? A subtle evaluation issue? Something specific to how Events handle Buffer objects?

And more generally, is there a recommended best practice here?

Thanks a lot!

If you want to play a Synth using an Event, it should look like this:

e = (instrument: \playBufTest, buf: ~buffers[\A][2]).play;

(If your SynthDef has a gate argument then the event-play syntax will automatically release the node after the event’s sustain time, where Synth doesn’t. Your SynthDef isn’t gated though, so you won’t see that behavior.)

In Synth.new, you can’t replace the argument array with an event – Array and Event are not compatible in this location.

hjh

Could you try the following?

Synth(\playBufTest, [buf: ~buffers[\A][2]]);

You could also reduce typing if you define event keys with a lower-case initial letter:

~buffers = (\a:(1: Buffer.read(s, ExampleFiles.apollo11), 2: Buffer.read(s, ExampleFiles.child)), \b:(\m0: Buffer.read(s, ExampleFiles.sinedPink), m1: Buffer.readChannel(s, ExampleFiles.sinedPink, channels:[1, 0])))

Synth(\playBufTest, [buf: ~buffers.a[2]]);

~buffers.a[2].play

~buffers.b.m1.play

hey prko,

your proposed syntax works.
I guess that’s about it as far as the difference between Symbol /array and Event / dictionary styles.

Thanks,

D

1 Like