# Pdef durations are off

I’m trying to understand why the timing of the patterns below gets sort of wonky if i execute the second block on the fly, as the first one is still playing. It’s not hard for me to command period and run the second one in order to get the right timing, but i’d like to understand what it is that i’m missing. I tried different quant values for the Pdefs, but i still get the same results. I suspect it has something to do with some of the \dur values being Pseqs –– it’s as if the second block’s durations were not snapping/aligning right sometimes (that’s the best way i can describe it). Cheers!

``````
Pdef(\x).quant = 0;
Pdef(\y).quant = 0;

// first block:
Pdefn(\melamp, Pbjorklund(9, 12, inf, 0)); Pdefn(\kickamp, Pbjorklund(1, 10, inf, 0)); Pdefn(\hhamp, Pbjorklund(2, 10, inf, 0)); Pdef(\x, Pbind(\type, \midi, \chan, 0, \midicmd, \noteOn, \midiout, m, \dur, 0.2, \midinote, Pseq([60, 66, 64, 63], inf), \legato, 0.3, \amp, Pdefn(\melamp))).play; Pdef(\y, Pbind(\type, \midi, \chan, 1, \midicmd, \noteOn, \midiout, m, \dur, 0.1, \midinote, 44, \legato, 1, \amp, Pdefn(\kickamp))).play;

// second block:
Pdefn(\melamp, Pbjorklund(3, 6, inf, 2)); Pdefn(\kickamp, Pbjorklund(3, 12, inf, 0)); Pdefn(\hhamp, Pbjorklund(3, 12, inf, 0)); Pdef(\x, Pbind(\type, \midi, \chan, 0, \midicmd, \noteOn, \midiout, m, \dur, Pseq([0.2,0.1,0.1], inf), \midinote, Pseq([60, 66, 64, 63], inf), \legato, 0.4, \amp, Pdefn(\melamp))).play; Pdef(\y, Pbind(\type, \midi, \chan, 1, \midicmd, \noteOn, \midiout, m, \dur, 0.1, \midinote, 44, \legato, 1, \amp, Pdefn(\kickamp))).play;
``````

I’m not at computer to test this out, but it looks like you are dealing with polymeter – the amp, midinote, and duration patterns have different periods between repetitions, which combine to create phrases that have different overall periods in each Pdef. To ensure the alignment of phrases (i.e. 2nd block starts playing when both patterns from the 1st block have reached the end of a phrase), you will need to calculate the period of each phrase in beats, find their least common multiple, and set the quant for both Pdefs to this value.

You will have to double check my mental math, but I believe you have the following periods:

1st block:
x: 0.8
y: 1.0
LCM: 4.0

2nd block:
x: 1.6
y: 0.4
LCM: 1.6

So if you set the quants to 4.0 after running the 1st block, and 1.6 after the 2nd block, the phrases should stay aligned. You might prefer the feel of quant = 8.0 for both blocks, since that is the overall LCM, but that might be too long to wait.