Alternate between different Pbinds

Hi all!

I am trying to accomplish something with patterns but I cannot seem to get what I would like, and there must be some things I misunderstood on the way.

Let’s say that I have a SynthDef which has a buffer as argument and some other parameters (such as the rate):

SynthDef(\test {
    arg out = 0, buf, rate;

I would like to create a pattern that alternatively plays buf1 and buf2 (possibly in a random fashion), while buf1 should be played with rate 0.5 and a timing before the next event of 0.5, and buf2 with rate 2 and a shorter time before the next event.

I was thinking of using Pbindf or Pchain like so, in order to “bind” together some key-value pairs to buf1 and buf2, and then combine both patterns in one with Pseq or Prand:

Pdefn(\common, Pbind(
    \instrument, \test,
    \out, 0,

Pdefn(\buf1, Pbindf(
    \buf, ~buf1.bufnum,
    \rate, 0.5,
    \dur, 0.5,

Pdefn(\buf2, Pbindf(
    \buf, ~buf2.bufnum,
    \rate, 2.0,
    \dur, 0.2,

Pdef(\playing, Prand([Pdefn(\buf1), Pdefn(\buf2)], inf)).play;

But it does not seem to work. I have tried a few variants of the code above but it either does not play at all, or it plays only one of the two buffers.

Thanks in advance for your help!

EDIT: added \buf parameters.

I don’t know if you want to stick to the Pdefn approach, but this could be achieved in a really simple way, with the “multiple assignement” approach in a regular Pbind:

p=Pbind(\instrument, \playBufStereo,
	#[\bufnum,\dur,\whatever], Prand([[~b2,4,0.5],[~b8,2,4]],6),

PS: Simple remark on you code: I don’t see where you specify which buffer to play

I was not aware of this notation, thank you!
It would work for simple cases, but it seems a bit rigid, as I cannot easily define some common arguments for buf1 and buf2, I have to give for each argument one value for buf1 and one for buf2.
Another advantage of the Pbindf approach is that I can give common arguments and then override them for buf1 or buf2.

Indeed, I edited the original post.

A good formulation is:

        /* dictionary of Pbinds for the various buffers */
    Pbind( /* base values including bufID */ )

Psym and family assume the ID will be a symbol, but that’s easy to handle by thinking not in terms of buffers, but rather in terms of “sounding objects,” each one with a name. Then the buffer number is one parameter of the sounding object, but not the ID as such.