That can’t work. You need a Plazy wapper if you want to read the repeats from the event itself because Pseq doesn’t accept a pattern for the repeats (and Pkey is a pattern). Alternatively, use PLseq. See more discussion/examples here. The whole list is being changed there, but the same applies to the repeat parameter.
Here’s the Plazy example adapted to something meaningful here (two Pseqs with different repeats):
(Pbindef(\twoseqs,
\instrument, \default,
\dur, 0.5, \reps1, 1, \reps2, 1,
\midinote, Pn(PlazyEnvir({|reps1, reps2| Pseq([Pseq([44, 55], reps1), Pseq([66, 77], reps2)])}))));
Pbindef(\twoseqs).play;
Pbindef(\twoseqs, \reps1, 2);
Pbindef(\twoseqs, \reps2, 2);
I’m assuming the whole point of using Pbindef is that you want to be able to change the repeats “on the fly”, as the pattern is playing, but with your initial example that doesn’t make much sense, as you only have one sequence being repeated and you seem to want to change just how many times it plays. You don’t need Pbindef or Plazy for that since you decide from the start how many repeats there are, which I’m guessing why you’ve accepted @elgiano’s answer. The last example I gave is more of an “advanced version” of doing this change on the fly and/or as a “pattern filter”; it would work the same with chained Pdefs…
Setting just an initial value for reps is in fact much simpler, using a Pdef function… which gets evald in the event envir, i.e. basically/implicitly Plazy-like
(Pdef(\oneseq, { Pbind( // note the brace!
\instrument, \default,
\dur, Pseq(0.5!2, ~reps),
\midinote, Pseq([44, 55], ~reps)) }));
Pdef(\oneseq).set(\reps, 2)
Pdef(\oneseq).play
Pdef(\oneseq).set(\reps, 3)
Pdef(\oneseq).play
Pdef(\oneseq).gui // because reps is read from the Pdef.evir, it shows up in gui
// same Pdef as above but using Pn for the reps:
(Pdef(\oneseq, { Pn(Pbind(
\instrument, \default,
\dur, Pseq(0.5!2),
\midinote, Pseq([44, 55])), ~reps) }));
// you can also set the reps on each play, without saving them in the envir
Pdef(\oneseq).set(\reps, nil)
Pdef(\oneseq).play(protoEvent: (reps: 2))
If you look in the source code of EventPatternProxy
, the relevant superclass of Pdef
, you’ll that it does
source_ { arg obj;
if(obj.isKindOf(Function)) // allow functions to be passed in
{ pattern = PlazyEnvirN(obj) }
which is how the “brace magic” works. Note that without that (brace or Plazy) ~reps
would get read from the current environment immediately when the Pdef is created, rather than when it is played.