Passing buffer array as array argument (Pproto)?

Hello list,

im trying to pass an array of buffers as an array argument through Pproto for usage within a SynthDef.
As im using Pfunc the double quotes wont do as usually for array args.
Is there eventually another way to pass it then?

p= (Pspawner({|sp|
		{	~sbuf=(20.collect{ |index| ( ( type: \allocRead, path: Platform.resourceDir +/+ "sounds/%.wav".format(index)).yield)});   //collecting sound buffers
			\instrument, \test,
			\bufA,  Pfunc { |ev| ev[\sbuf].at((0..19))},    //but how to pass them as array arg for synthdef instead of creating 20 events?

Thanks for suggestions,

1 Like

Hi! You might want to check this out:

The answer is simple, you need to wrap your bufnums in an extra array:

\bufA,  Pfunc { |ev| [ev[\sbuf].atAll((0..19))] },
// or simpler syntax if you want to pass all of them:
\bufA,  Pfunc { |ev| [ev[\sbuf]] },

Note that your SynthDef has to be ready to receive 20 values in a single control, which you can do easily with NamedControls:

SynthDef(\play) { |out, gate|
	var buf = \!20);,, buf) *, gate))

Here is an example with 4 buffers, with tracing and polling, so that you can see in the Post window all the Events from the Pbind and the controls received by the synths:

SynthDef(\play) { |out, gate=1|
	var buf = \!4);
	var players =, buf.poll);, *, gate))

Pspawner {|sp|	
	var pproto = Pproto({
		~sbuf = 4.collect {
			(type: \allocRead, path: Platform.resourceDir +/+ "sounds/a11wlk01.wav").yield
	}, Pbind(
		\instrument, \play, \amp, 0.1,
		\dur, 1,
		\buf, Pfunc { |ev| [ev[\sbuf]] }, 
1 Like

Thank you @elgiano! Im perplexed as i was sure had tried to wrap the bufnums with the necessary extra brackets to achieve just that, but i must’ve gotten something wrong then…Working perfectly now, cheers!