Penv vs Env asStream... or what does Thread.endBeat do?

I see, so the intention of endBeat in Penv is to make

e = Penv([0, 1, 0], [0.1, 0.1]);
e = Pseq([e, e]);

behave as if the whole 2nd Penv “comes after” the first, i.e. make it similar to what Pseq-inside-Pseq does, e.g. like

Pseq([Pseq([1, 1]), Pseq([2, 2])])

Interesting enough this Psequencing also ultimately works with Pseg although it’s a bit less obvious why (the durations get added more incrementally to endBeat), i.e.

(
~teste = { var s1 = e.asStream, start = thisThread.beats;
	12 do: { 0.04.wait; [s1.next, s1.endBeat-start].postln }};
fork {
	"Penv:".postln;
	e = Penv([0, 1, 0], [0.1, 0.1]);
	e = Pseq([e, e], 1);
	~teste.();
};
fork {
	1.wait;
	"Pseg:".postln;
	e = Pseg([0, 1, 0], [0.1, 0.1]);
	e = Pseq([e, e], 1);
	~teste.();
};
)

posts something like

Penv:
[ 0.0, 0.24000000001979 ]
[ 0.40000000008149, 0.24000000001979 ]
[ 0.80000000016298, 0.24000000001979 ]
[ 0.79999999975553, 0.24000000001979 ]
[ 0.39999999967404, 0.24000000001979 ]
[ 2.9103830456734e-10, 0.44000000003143 ]
[ 0.40000000037253, 0.44000000003143 ]
[ 0.80000000045402, 0.44000000003143 ]
[ 0.79999999946449, 0.44000000003143 ]
[ 0.399999999383, 0.44000000003143 ]
[ nil, 0.44000000003143 ]
[ nil, 0.44000000003143 ]
Pseg:
[ 0.0, 0.14000000001397 ]
[ 0.40000000008149, 0.14000000001397 ]
[ 0.80000000016298, 0.14000000001397 ]
[ 0.79999999981374, 0.24000000001979 ]
[ 0.39999999973224, 0.24000000001979 ]
[ 2.9103830456734e-10, 0.34000000002561 ]
[ 0.40000000037253, 0.34000000002561 ]
[ 0.80000000045402, 0.34000000002561 ]
[ 0.7999999995227, 0.44000000003143 ]
[ 0.39999999944121, 0.44000000003143 ]
[ nil, 0.44000000003143 ]
[ nil, 0.44000000003143 ]

So Pseq-d Penv and Pseg are indistinguishable inside Pbind

e = Pseg([0, 1, 0], [0.1, 0.1]); // same with e = Penv([0, 1, 0], [0.1, 0.1])
p = Pbind(\amp, Pseq([e, e]), \dur, 0.02);
p.trace.play

Unfortunately all the Ptime-like patterns get desynchronized from the underlying stream if you pause the Stream[Player]. So the analogy with embedding Pseqs in each other is somewhat imperfect even with Penv. (The workaround isn’t too complicated for Ptime, but it gets a bit duplicative to do it for all other similar classes.)