How to run Pfuncs in a Pseq

I’m trying to run some Pfuncs in a Pseq like this:

(
Pdef(
	\example,
	Pbind(
		\funcs, Pseq([
			Pfunc({
                    postln("Executing Pfunc 1");
                }),
                Pfunc({
                    postln("Executing Pfunc 2");
                }),
                Pfunc({
                    postln("Executing Pfunc 3");
                }),
                Pfunc({
                    postln("Executing Pfunc 4");
                })
		]),
		\dur, 4
	)
).play;
)

What I was expecting was that each Pfunc executes once, giving the following output:

Executing Pfunc 1
Executing Pfunc 2
Executing Pfunc 3
Executing Pfunc 4

But what actually happens is that the first Pfunc executes over and over until I stop the pattern:

Executing Pfunc 1
Executing Pfunc 1
Executing Pfunc 1
Executing Pfunc 1
Executing Pfunc 1
... etc ...

This is a surprise to me as if I put a normal sequence in the Pseq it behaves as expected:

(
Pdef(
	\example,
	Pbind(
		\funcs, Pseq([
			0,1,2,3
		]).trace,
		\dur, 4
	)
).play;
)

0
1
2
3

Can anyone advise me on how to achieve what I’m looking for?

(
Pdef(
	\example,
	Pbind(
		\funcs, Pseq([
			Pfin(1, Pfunc({ 1.postln })),
			Pfin(1, Pfunc({ 2.postln })),
			Pfin(1, Pfunc({ 3.postln }))
		]),
		\dur, 0.1
	)
).play;
)

Pfunc doesn’t have a duration, it just continuously returns values. You can limit this with Pfin, or any of the other classes in the help category Streams-Patterns-Events > Patterns > Repetition

Change Pfunc to Pfuncn. It has a second repeats argument (1 by default) and should do what you’re looking for.

Spot on both of you, thank you so much! :slight_smile: