Pdef rerun TempoClock

Hi all,

After a finite Pbind stored in a Pdef had finished playing back, I’d like to restart the pattern a bit later at same tempo as defined in the global variable “t”:

a = Pbind(
	\dur, 1,
	\note, Pbrown(0,7,2,8)
);
m = Pbind(
	\dur, 1,
	\note, Pseq([24]++(12!3),inf));
)
(
t = TempoClock(100/60).permanent_(true);
Pdef(\pd,a).play(t);
Pdef(\pdm,m).play(t);
)
Pdef(\pd,a); // tempo = 60/60
Pdef(\pd,a).quant([4,0]); // tempo = 60/60; no snapping to 4th beat
Pdef(\pd,a).play(t,quant:[4,0]); // same result as above
(
t = TempoClock(100/60);
Pdef(\pd,a).play(t,quant:[4,0]); // same
)
Pdef.removeAll;

When I rerun the Pbind pattern via Pdef, it plays back the pattern at default tempo (ie. 60bpm), not at 100bpm.

N.B.: I do not want to use TempoClock.default because I intend to use different tempi.

How can I make sure that when I rerun a pattern, SC plays it back at the tempo I define in global variable “t”?

Thanks,
cd

Ok, so found this thread where @Bruno uses Pbindef and .premanent_(true) to get the desired effect I described in the original post.

In my example it also works this way:

(
t = TempoClock(100/60).permanent_(true);
a = Pbindef(\pd,
	\dur, 1,
	\note, Pbrown(0,7,2,8)
).play(t);
m = Pbindef(\pdm,
	\dur, 1,
	\note, Pseq([24]++(12!3),inf)).play(t);
)
Pbindef(\pd).play(t); // tempo = 100/60
Pbindef(\pd).play(t,quant:[4,0]); // same as above + snap to 4th beat
(
Pbindef(\pd).stop;
Pbindef(\pdm).stop;
)

How come I can’t obtain the same result with Pdef even if I set TempoClock(100/60).permanent_(true)? What seems to be the difference?

Permanent means that the TempoClock survives command + period. My guess is that you have hit command+period in you first example some time before playing the pattern the second time resulting in the TempoClock being destroyed and that the play method falls back to the default clock and the tempo of 1 bps in this case.

Assign the desired clock to the Pbind Pdef (<- edit, fix typo):

Pdef(\pd, Pbind(...))
.clock_(t)
.play;

Then you shouldn’t have to re-specify t every time you .play it.

http://doc.sccode.org/Classes/Pdef.html#-clock

hjh

Hi Thor,

Thanks for your response, I did not press CMD/CTRL + period before playing the pattern the second time. Curious if you have any suggestions as to what could be the issue.

Best,
cd

Hi hjh,

Thank you for your response too, did you mean assign .clock to the Pdef? I’m asking, because that’s the only time it works as desired:

(
a = Pbind(
	\dur, 1,
	\note, Pbrown(0,7,2,8)
);
m = Pbind(
	\dur, 1,
	\note, Pseq([24]++(12!3),inf)
);
t = TempoClock(100/60);
Pdef(\pd,a).clock_(t);
Pdef(\pdm,m).clock_(t);
)
(
Pdef(\pd,a).play;
Pdef(\pdm,m).play;
)
Pdef(\pd,a).quant([4,0]); // no snapping to 4th beat
Pdef.removeAll;

When I assign .clock to Pbind it plays the pattern at default tempo when played second time.

Also the .quant doesn’t seem to quantize the start of the Pdef unfortunately. I’m not sure why it’s not working.

Best,
András

You don’t have to assign the clock to the Pdef, you can just assign the clock to the play instance:

(
t = TempoClock(100/60).permanent_(true);
Pdef(\pd, Pbind(
	\dur, 1,
	\note, Pbrown(0,7,2,8)
));
Pdef(\pdm, Pbind(
	\dur, 1,
	\note, Pseq([24]++(12!3),inf);
))
)

Pdef(\pd).play(t); // tempo = 100/60
Pdef(\pd).play(t,quant:[4,0]); // same as above + snap to 4th beat
(
Pdef(\pd).stop;
Pdef(\pdm).stop;
)
(
t.tempo = 200/60; // test new tempo
Pdef(\pd).play(t); 
Pdef(\pd).play(t,quant:[4,0]);
)

You’re right, I wrote the English sentence incorrectly, but the code example was correct.

You need to set the Pdef’s quant: .quant_(4). When you write Pdef(\a).quant(4), you’re accessing the existing quant value assigned to the Pdef – it’s a “getter” method. The argument is unnecessary for that, so it’s ignored. To reassign, you need the “setter” method, with the underscore. There’s also a syntax for a setter that looks like variable assignment: Pdef(\a).quant = 4 but this way can’t be chained with other method calls (at least, not without some ugly syntactic tap-dancing).

At least as I read the original question, it was asking how to get the Pdef to play on the desired clock without specifying it in play every time.

It seems to come up from time to time with Pdef/Tdef – an assumption that playing on a clock once binds the Pdef to the clock permanently, so that it will always play on that clock (at that tempo). It doesn’t – but the clock can be explicitly bound. Maybe Pdef examples need to highlight this more (or maybe they already do, but it’s easily overlooked?).

hjh

Thank you both @jamshark70 and @Thor_Madsen for your help, I really appreciate it!

What I indeed tried to achieve is to “rerun” a finite pattern stored in a Pdef without having to run Pdef().stop then Pdef().play.

And it is also true that I assumed that Pdef() binds/“remembers” the clock I assigned/connected to it initially.

So this doesn’t get me the right result, because I guess in this case the clock is bound to the Pdef only once:

(
t = TempoClock(100/60);
a = Pbind(
	\dur, 1,
	\note, Pbrown(0,7,2,8)
);
m = Pbind(
	\dur, 1,
	\note, Pseq([24]++(12!3),inf));
Pdef(\pd, a).play(t,quant:[4,0]);
Pdef(\pdm, m).play(t,quant:[4,0]);
)

Pdef(\pd,a); // when rerun, the tempo is default (60BPM) and snapped to the 4th beat at this default tempo
Pdef.removeAll;

but when I explicitly set the clock to the desired value before playing the Pdef, so:

(
t = TempoClock(100/60);
a = Pbind(
	\dur, 1,
	\note, Pbrown(0,7,2,8)
);
m = Pbind(
	\dur, 1,
	\note, Pseq([24]++(12!3),inf));
Pdef(\pd, a).clock_(t).play(quant:[4,0]);
Pdef(\pdm, m).clock_(t).play(quant:[4,0]);
)
Pdef(\pd,a);
Pdef.removeAll;

Then the Pdef rerun is played back at 100BPM and is snapped at the 4th beat :tada:

It’s great to have a better understanding of how to use Pdef for creating phrases/motifs and quantizing them! :blush:

Best,
cd