This is my attempt in the \dur key, which does not work. Every time Pswitch1 receives a 0, it rests. Every time Pswitch1 receives a 1, the synth plays. When Pswitch1 receives a 2, I want Pn(0.25,2) to play the exact same note two times. Is there a way to achieve this, ideally without changing the pattern in Pseq?
I have spent several hours on this but cannot find a solution.
This is a tricky one. Conditionally sample-and-holding a pattern is not something the current pattern system does very easily.
One thing I would do is to use an “inner Pbind” to link \degree and \dur – because, in your problem description, they are linked (they both follow the Pswitch ‘index’).
But Pswitch1 isn’t appropriate because it will always pull only one value from the indexed stream. This will inherently break Pn(0.25, 2) apart. It sounds like that isn’t what you want.
Pswitch can contain Pbinds, so there’s the linkage.
(
p = Pchain(
// unfortunately I don't see a way to keep statelessness
// but will try to isolate the mess inside a block
// (because 'degree' needs to be one stream shared across several patterns)
Plazy {
var degree = Pseq([1, 2, 3], inf).trace.asStream;
Pswitch([
// unfortunately \dur must come first here
Pbind(\dur, Pn(Rest(1), 1), \degree, degree),
Pbind(\dur, Pn(1, 1), \degree, degree),
Pbind(\dur, Pn(0.25, 2), \degree, Pdup(2, degree))
], Pseq([0, 1, 0, 2, 0, 2], inf))
},
Pbind(
\amp, 0.1,
\instrument, \triy,
\stretch, 0.2,
)
).play;
)
jamshark70, jordan, thank you so much for your time and effort. I need to experiment with your suggestions quite a bit in order to understand, what is actually happening. There is no doubt that this helps and teaches me a lot. I will also take a look at the Pattern Internals in that “Pattern Guide Reference”. Thank you again!