Quantization failing with Pdefs?

Hi there, I was wondering if I’m doing something wrong (SC 3.10.3 Windows). I have Ndefs whose sources are Pdefs, but the quantization is not working as expected.

// Get rid of old stuff
Ndef.clear;
Pdef.removeAll;

// Create a "ping" metronome so we know where every 8th beat falls
Pdef(\ping, Pbind(\degree, Pseq([14, Pn(7,7)], inf), \dur, 1, \amp, 0.02)).quant_(8).play;

// Now create a quantized Ndef with a quantized Pdef as its source
Ndef(\test).quant_(8).play;
Ndef(\test).source = Pdef(\pat).quant_(8);

// Play a minimal pattern that *should* start on a multiple-of-eight beat
Pdef(\pat).source = Pbind(\dur, Pn(1, 1));
// (it doesn't, it seems to start right away, on the next beat)

// In contrast, this works (not using Pdef but Pbind as Ndef source directly) -- the source changes at the quantization point:

Ndef(\test, Pbind(\dur, Pn(1, 1)));

Any suggestions on how to do this properly? Should I just log a bug, or am I missing some step?

Thanks,
Glen.

I finally came up with a solution to this, that does exactly what I want. Replace the Pdef-source-setting line above with this (using the sched method on Pdef and set the source in a scheduled function):

Pdef(\pat).sched{ Pdef(\pat).source = Pbind(\dur, Pn(1, 1)) }

But why the difference with the behaviour of Ndef? Shouldn’t it just use the quant when you set the source of a Pdef? Ah, well…

Well if you have a source that fills the space to the next quant with silence, this will work too.

Pdef(\pat, Pbind(\type, \rest))

But it is a bug and we need to fix it …

Thanks, but what do you mean “will work”? Your example only stops the current pattern.

One problem with my “solution” (workaround above, using Pdef.sched) is that it will do “too much” if you evaluate it multiple times prior to the next quant boundary. (I’m thinking of a live-coding context, where you modify something in a running Pdef, then change your mind and modify it again before the next quant boundary has arrived). You can’t “cancel” or replace the scheduled source-setting functions.

I didn’t see it logged in GitHub, so I just added an issue:

here is a fix: https://github.com/supercollider/supercollider/pull/4768