Quantizing Pdef.stop?

Hi,

is there a better way to quantize Pdef(\something).stop to
the next clock beat rather than scheduling it as
t.play({Pdef(\something).stop})?

I am currently running my clock at one-beat-per-bar. Hence, everything
that is quantized to 1 will either start or end at the beginning of a
bar, which I like. Plus I can notate quarter note durations as \dur, 1/4.

But if I want to stop a Pdef with t.play, as desribed above, it will
stop just after the first event of that bar has sounded. How could I
make Pdef stop “just before” that event is played without giving some small
numeric offset, as possibly in t.sched(0.999, {Pdef(\something).stop})?

Here is a minimal working example:

t=TempoClock.new(tempo: 130/60/4);
t.sched(0, {t.beatsPerBar=1});

Pdef(\inC, Pbind(\degree, Pseq([5,1,1,1], inf), \dur, 1/4)).play(t);

t.play({Pdef(\inC).stop;}); // will stop the Pdef at the next bar but
the first event of that bar will still sound. How to stop just before
it?

Thanks for all ideas!
P

To illustrate, consider this code block:

(
fork {  // get onto TempoClock
	var clock = thisThread.clock;

	// this is just to arbitrarily pick a timepoint in the future
	// this represents the barline where you're stopping the Pdef
	var x = clock.nextTimeOnGrid(1) + 1;
	
	clock.schedAbs(x, { "event A".postln });
	clock.schedAbs(x, { "event B".postln });
	
	1.0.wait;  // sometime later...
	
	clock.schedAbs(x, { "event C".postln });
};
)

“event A” and “event B” represent a process that is already scheduled on the clock (a running Pdef).

Sometime after that, something else gets scheduled for the same time – “event C” represents your stop request.

Most people, reading this code, but expect the events to be posted in order, A-B-C.

But the behavior you’re looking for here is that C should magically move to the front of the line – you want C-A-B (and C deactivates A and B).

I think that would be pretty confusing, if certain requests to schedule an action took place at the exact scheduled time, while other requests awakened slightly earlier than the scheduled time.

The solution is – if you want it to be scheduled just before the barline, then schedule it just before the barline.

So the point is really that you don’t want to write the offset every time you stop a Pdef. This is one of the use cases for functions: package a more complex behavior under a simpler name.

~stopPdef = { |name, quant|
	var pdef = Pdef(name);
	var clock = pdef.clock;
	var time = clock.nextTimeOnGrid(quant);
	
	clock.schedAbs(time - 0.001, { pdef.stop });
	pdef
};

Untested but that should do it – then you just write ~stopPdef.(\inC, 1).

hjh

1 Like