Pdup but instead of number of repetitions it repeats input stream values for a certain time

I’m looking for the right way to repeat input stream values until shifting Pseg reaches the end of its Env. It may not be very clear from the question what I mean, so below is a specific example. Сan someone guide me to do that? Thx

``````(
p = Pbind(
\instrument, \default,
\dur, Pseg(
[0.2, 0.4, 0.2],
[3.0, Pwhite(5.0, 10.0, inf)],
'cubed', inf),
\freq, ? // There should be a pattern here that produces the same value n times until Pseg reaches its end, and then the value changes on the next cycle
);
)

p.play;
``````

Fantasize of something like Pdup but instead of the number of repetitions, it repeats value for a certain time.

The random dur value in the Pseg makes it a bit tricky.

Here is what I came up with. Hopefully somebody else has a simpler idea.

``````
(
p = Pbind(

[\dur, \flag], Plazy({
Ptuple([

Pseg(
[0.2, 0.4, 0.2],
[3.0, Pwhite(5.0, 10.0, inf)],
'cubed', 1
),

Pseq([
Pseq([1], 1),
Pseq([0], inf)
])
])
}).repeat,

\freq, Pclutch(Pseq([60, 62, 63].midicps), Pkey(\flag))

).play
)
``````
1 Like

A somewhat simplified version of @droptableuser’s solution:

``````(
p = Pbind(

\dur, Pn(
Pseg(
[0.2, 0.4, 0.2],
[3.0, Pwhite(5.0, 10.0, inf)],
'cubed', 1
),
key: \foo
),

\freq, Pgate(
Pseq([60, 62, 63].midicps),
key: \foo
)

).play
)
``````

The documentation for Pn and Pgate has some examples of how to use the `key` argument to trigger a change at the end of a sub-pattern.

2 Likes

Pn / Pgate is good, yes.

Here’s another approach (not better or worse, just different): Pseg plays once. This goes into a Pbind with \freq – so now, when Pseg ends, so does \freq. Then \freq can be defined with a forever sample-and-hold pattern – “forever,” but it will be interrupted when Pseg ends. The `asStream` maintains continuity of the frequency stream across Pseg cycles.

Then you can Pchain other parameters onto that.

``````(
p = Pchain(
Pbind(
\instrument, \default,
// just to show that this stream is independent
// of the dur-freq grouping
\pan, Pseq([-0.6, 0.6], inf)
),
Pn(
Pbind(
\dur, Pseg(
[0.2, 0.4, 0.2],
[3.0, Pwhite(5.0, 10.0, inf)],
'cubed', 1
),
\freq, Pstep(Pseries(100, 50, inf).asStream, inf, inf)
),
inf
)
).play;
)
``````

(Note that I moved `play` – IMO it’s not a good habit to have a freestanding `p.play` because you lose access to the EventStreamPlayer – you can no longer stop it in code. The result of `.play` should be saved in the variable, rather than the source.)

hjh

1 Like

Thank you all @droptableuser, @PitchTrebler, @jamshark70. All of these solutions are practicable and I will definitely remember them for improving my toolset.

This is a good advice @jamshark70. Thanks for pointing out. That habit comes from using ~p = Pbind in ProxySpace, where it wraps into NodeProxy.