Changing length of PSeq array on every repeat?

Say I have a pattern like Pseq([1,2,3,4], inf). I’d like the number of elements in the sequence to vary on each repeat, according to another pattern. On the first playthrough I want to play all 4 elements, then 3, 2, back up to 3, and then 4 again, and so on. How can I achieve this?

For example, I’ve been trying this:

(
p = Pbind(
	\degree, Pn(Pfin(Pseq([1,2,3,4]), Pseq([1, 2, 3, 4, 5, 6, 7])), inf),
	\dur, Pseq([0.4], inf),
	\sustain, 0.15
).play
)

But on each repeat the pattern just plays the first 4 notes, or whatever number of elements happen to be in the array of the first sequence.

Pn(Pser((1..7), { rrand(2, 7) }), inf)

// or
Pn(Pser((1..7), Pwhite(2, 7, inf).asStream), inf)

Note that a pattern used as a number of repeats normally needs to have .asStream attached.

hjh

Ah, the .asStream seems to be what I was missing.

This works for me:

(
p = Pbind(
	\degree, Pn(Pser((1..7), Pseq((7..2) ++ (2..7)).asStream), inf),
	\dur, Pseq([0.4], inf),
	\sustain, 0.15
).play
)