Something like Ppar but which stops when first stream ended?

Hi all,

Normal behavior for Ppar is to end when the last of the patterns in its list ends. However, in my current experiment, I’d like a version of Ppar that ends as soon as one of its patterns end. Am I missing the obvious way to do it? If so, I’d appreciate a hint. If not, what would be an approach to accomplish this?



a = Pbind(\degree, Pseq([0,2,4],inf));
b = Pbind(\octave, Pseq([3]));

p = Pfindur(2, Ppar([a,b]));

I’m aware of Pfindur and Pfin but in my use case I cannot easily know exactly how long each of the patterns will take (they are dynamically “compiled” from external data).

I’m somewhat surprised that nothing like it seems to exist yet.

This seems like a straightforward and simple addition to Ppar. I think it’s as simple as:

Ppar : ListPattern {
    var waitForAll = true;
    // ...


if (nexttime.notNil && waitForAll, {
1 Like

If @shiihs (or anyone!) gets this working, it should be proposed as a pull request, I think this would be a useful addition to sclang.

1 Like

I was surprised too. I roughly remember that there are other Patterns, that end if one stream ends, but I couldn’t find them. However when dealing with subpatterns Pspawner is your best friend:

p = Pbind(\note, Pn(0, 3));
q = Pbind(\note, 2);

r = [p, q];

// you can emulate Ppar's behaviour like this
Pspawner { |sp|

// this finishes in the special case when first stream ends
Pspawner { |sp|
	sp.par(Pseq([p, Prout { sp.suspendAll } ]));

// for an arbitrary number of patterns
Pspawner { |sp| { |p| sp.par(Pseq([p, Prout { sp.suspendAll }])) }

You could write a little helper class or Function for this. A further advantage of Pspawner is that you can easily adapt the finishing behaviour in special cases.

1 Like


var waitForAll = true;


var  >waitForAll = true;

in your suggestion makes it possible to write e.g.

p = Ppar([Pseq([0.1,0.2,0.3], 1).trace, Pseq([0.6], inf).trace], 1).waitForAll_(false).play;

which seems to work as expected, thanks for that!

Thanks for this solution too, it works well and is quite flexible.