Prout to create a timed function in a Pbind

I’d like to evaluate a function inside of a Pbind every five seconds. It seemed like Prout should be the thing to do it - but the following code doesn’t seem to work… Am I using it incorrectly?

~print = {"hello".postln};
Pbind(\dur, 0.1, \printer, Prout({loop{5.yield; ~print.()}})).play;

Thank you very much!

A pattern (or stream / routine / thread) can have only one timing. There’s no concept of a Pbind running with its own timing and something else inside it running with different timing. (It’s the “inside” part that is breaking here.)

You can have two patterns running side-by-side with independent timing. See Ppar or Ptpar to unify them in a common wrapper. Also see the Data Sharing chapter of the Practical Guide to Patterns for advice on getting values from one parallel pattern into the other.

hjh

1 Like

You can use a Pspawner for that purpose:

(
p = Pbind(
	\type, \rest,
	\dur, 5,
	\do, Pfuncn({ "hello".postln }, 3) // end after 3
);

q = Pspawner { |sp|
	loop { |i|
		sp.par(p);
		0.1.wait
	}
}.play;
)	


// to make the subpatterns identifiable you can make a pattern generator function

// note how low numbers are posted again after the counter has reached 50 (5 seconds)


(
p = { |i| 
	Pbind(
		\type, \rest,
		\dur, 5,
		\do, Pfuncn({ i.postln }, 3)
	)
};

q = Pspawner { |sp|
	inf.do { |i|
		sp.par(p.(i));
		0.1.wait
	}
}.play;
)	


1 Like