PbindMultiChan : Pbind


PbindMultiChan differs from Pbind in its handling of multi-value streams.


In Pbind, you can have a stream return an array of values, and assign those values to multiple keys by specifying an array as the "key" for the key/value pair.


p = Pbind(#[x, y, z], Ptuple([Pseries(0, 1, inf), Pgeom(1, 2, inf), Pwhite(1, 10, inf)], inf)).asStream;

p.next(());


( 'y': 1, 'x': 0, 'z': 6 )

( 'y': 2, 'x': 1, 'z': 6 )

( 'y': 4, 'x': 2, 'z': 7 )

( 'y': 8, 'x': 3, 'z': 8 )

( 'y': 16, 'x': 4, 'z': 9 )

( 'y': 32, 'x': 5, 'z': 5 )

( 'y': 64, 'x': 6, 'z': 3 )

( 'y': 128, 'x': 7, 'z': 10 )

( 'y': 256, 'x': 8, 'z': 1 )

( 'y': 512, 'x': 9, 'z': 8 )


If there are not enough elements in the stream array, keys in the key array will be ignored in Pbind.


// three keys, two values

p = Pbind(#[x, y, z], Ptuple([Pseries(0, 1, inf), Pgeom(1, 2, inf)], inf)).asStream;

p.next(());


( 'y': 1, 'x': 0 ) // 'z' is omitted

( 'y': 2, 'x': 1 )

( 'y': 4, 'x': 2 )

( 'y': 8, 'x': 3 )


PbindMultiChan will wrap the value array around so that all keys will be populated. It is the same behavior as multichannel expansion in a UGen. This is useful for cases where the number of keys is known but the streams are user-supplied and might not have enough streams to match keys.


// three keys, two values

p = PbindMultiChan(#[x, y, z], Ptuple([Pseries(0, 1, inf), Pgeom(1, 2, inf)], inf)).asStream;

p.next(());


( 'y': 1, 'x': 0, 'z': 0 )

( 'y': 2, 'x': 1, 'z': 1 )

( 'y': 4, 'x': 2, 'z': 2 )

( 'y': 8, 'x': 3, 'z': 3 )

( 'y': 16, 'x': 4, 'z': 4 )


Observe that 'x' and 'z' have the same values in each event. 'x' gets the first stream result, 'y' gets the second, and 'z' wraps back around to the first.