Pseg inside a list of a Pwrand

Hey community,

is anybody able to tell me why if have to restart my Interpreter after 15 seconds pass in all those Psegs?

When I drop .asStream respectively I don’t get that problem but then the values won’t change inside the Psegs - they stay infinitely in their inital positions (0.24, 1.2 and 2.3)…
I already tried to work around with Envs, Pstep and PstepDur, but it just doesn’t work…

(
Pbindef(\test,
	
	\instrument, \default,
	
	\dur, Pseq([
		Pwrand(
			list: [
				Pwhite(Pseg([0.24, 0.08], 15, 'lin', 1).asStream.trace(prefix: "a: "), 0.24, 1),
				Pwhite(Pseg([1.2, 0.9], 15, 'lin', 1).asStream.trace(prefix: "b: "), 1.2, 1),
				Pwhite(Pseg([2.3, 1.9], 15, 'lin', 1).asStream.trace(prefix: "c: "), 2.3, 1)
			],
			weights: Ptuple([
				Pwhite(0.35, 0.5, 1),
				Pwhite(0.3, 0.45, 1),
				Pwhite(0.2, 0.25, 1)
			], repeats: inf).collect(_.normalizeSum),
			repeats: inf)
	], repeats: 1),
	
).play;
)

Anyone got a clue?
Thank you all in advance!

The fact is that after your 15sec your 3 Pseg have reached their end. As they have a repeat at 1, they don’t start over. At the next event they will output is nil.

At the same time your Pwrand has a repeat at inf.

So after the 15sec, the Pwrandwill start choosing a random value among [nil,nil,nil] and put this as the duration of the event. One can expect that SC will stop the pattern there, but obviously it doesn’t. My guess is that the pattern keeps running but within an invalid state.

One solution is to stop explicitly the pattern after 15sec with a Pconst:

Pbind(\note, 0,

	\dur, 
		Pconst(15,Pwrand(
			list: [
				Pwhite(Pseg([0.24, 0.08], 15, 'lin', 1).asStream.trace(prefix: "a: "), 0.24, 1),
				Pwhite(Pseg([1.2, 0.9], 15, 'lin', 1).asStream.trace(prefix: "b: "), 1.2, 1),
				Pwhite(Pseg([2.3, 1.9], 15, 'lin', 1).asStream.trace(prefix: "c: "), 2.3, 1)
			],
			weights: Ptuple([
				Pwhite(0.35, 0.5, 1),
				Pwhite(0.3, 0.45, 1),
				Pwhite(0.2, 0.25, 1)
			], repeats: inf).collect(_.normalizeSum),
			repeats: inf)
, tolerance: 1)
).play;
)

So when the total duration will reach 15sec with a tolerance of 1sec, the pattern will be stopped properly.

1 Like

Another option would be to replace the Psegs with instances of Env(...).asStream, which hold the last value indefinitely after the envelope ends. See Using envelopes as patterns.

2 Likes

Pconst works fine! Thank you for your answer :slight_smile: