How to set up a default quantification for all patterns

I have a group of Pbindefs for a live session and would like to set the quantification and fade time to all of them from a single control:

(
Pbindef(\p1, \i, \loop, \buf, ~buf, \dur, 2).play.quant_(4).fadeTime_(10);
Pbindef(\p2, \i, \loop, \buf, ~buf2, \dur, 2).play.quant_(4).fadeTime_(10);
)

I would like to find a way to simplify it so I can get the same settings without adding quant_(4).fadeTime_(10) to each of them. I have tried with Ppar and it does the job but for some reason the buffer loops are overlaying each time I evaluate the pattern:

(
Pdef(\p1, Ppar([
	Pbind(\i, \loop, \buf, ~buf, \dur, 2),
	Pbind(\i, \loop, \buf, ~buf2, \dur, 2),
])).play.quant_(4).fadeTime_(10);
)

What approach do you recommend to set up a global quantification and fadetime to all my patterns?

Thank you

There is Pdef.defaultQuant = ... your quant here... but no defaultFadeTime.

Here is a moderately sneaky trick. Run the first block before creating any Pdefs.

(
Pdef.all = EnvironmentRedirect.new.dispatch_({ |key, object|
	// substitute your own desired quant / fadeTime here
	Pdef(key).quant_(1).fadeTime_(0.5)
});
)

// testing...
Pdef(\x, Pbind.new);
Pdef(\x).fadeTime  // 0.5 -- ah-hah! automatically set

hjh

1 Like

Thanks! Your trick works fine with Pdef but it fails with Pbindef:

Pdef(\works, Pbind(\i, \loop));
Pbindef(\fails, \i, \loop);
ERROR: Message 'quant_' not understood

I way using Pbindef instead of Pdef to simplify the code but the pattern length is about the same, so I will use Pdef with your trick, thank you.

By the way, do you know how to avoid a buffer overlay on a Pdef sample looper when the pattern is evaluated? The node tree shows that for a couple of seconds there are multiple buffers, which increases the volume, while there should only one by Pdef.

SynthDef(\loopbuf, {
	arg buf=0, rate=1, startpos=0, startloop=0, endloop=1, gate=1, attack=0.1, decay=0.3, sustain=1, release=1, out=0, pan=0, amp=0.5;
	var sig, env;
	endloop = BufFrames.kr(buf) * endloop;
	sig = LoopBuf.ar(buf.numChannels, buf, BufRateScale.kr(buf) * rate, 1, startpos, startloop, endloop);
	env = EnvGen.ar(Env.adsr(attack, decay, sustain, release), gate, doneAction:2);
	Out.ar(out, Pan2.ar(sig * env * amp, pan));
}).add;
```

Thank you

Ah. Try this:

(
Pdef.all = EnvironmentRedirect.new.dispatch_({ |key, object|
	// substitute your own desired quant / fadeTime here
	thisThread.clock.sched(0, { Pdef(key).quant_(1).fadeTime_(0.5) })
});
)

Your SynthDef defines a default release time of 1 second. If you release the old synth at the same time that you’re starting a new one, then they would overlap for one second. So you could specify a shorter release, e.g., \release, 0.05, in the pattern.

hjh

Your new hack did the track with Pbindef, thanks :slightly_smiling_face:

About the overlap, I reduce the release to 0.01 on the SynthDef and also tried passing it in the pattern, but still overlaps.

It may be the fadeTime. This defines a fade-in fade-out time per assignment of a source (maybe for play/stop too, I forget).

So you’ve specified a 10 second fade time.

Then, what is the expectation at reevaluation time? If it must fade over 10 seconds and not overlap, then it would have to fade out over 10 seconds and then fade the new one in over 10 seconds – which would sound a bit silly.

So instead, fadeTime defines the crossfade time.

Crossfading implies hearing old and new at the same time = overlap. It’s impossible to crossfade without overlapping.

If you want the crossfade to be inaudible, then it should be much shorter than several seconds.

hjh

You are right, it makes sense. Thank you!