I would now like to apply what I learned in the post above, to an approach with patterns.
The goal: to move to specific locations of a sound file contained in a buffer, in sync with the clock (quant), but this time using a Pdef rather than Ndefs.
I use the same bases as in the solution of the post cited above:
//Load the sound:
b = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav");
//Set the tempo:
(
t = TempoClock.default.tempo = 110/60;
~rate_b = b.sampleRate;
~b = ~rate_b * t.tempo.reciprocal; //~b = 1 beat
)
(
SynthDef(\sound, {|gate=1, start=0, end=(b.numFrames-1), rate=1|
//// in the synth, '+' is analogous to 'or'
var trig = (Changed.kr(start) + Changed.kr(end)) > 0,
gate1 = ToggleFF.kr(trig),
gates = [gate1, 1.0 - gate1],
starts = Latch.kr(start, gates),
ends = Latch.kr(end, gates),
phasors = Phasor.ar(
trig:0,
rate:BufRateScale.kr(b)*rate,
start:starts,
end:ends
),
bufs = BufRd.ar(1, b, phase:phasors, loop:1),
egs = EnvGen.kr(
Env.asr(
attackTime:0.01,
sustainLevel:1,
releaseTime:0.01),
gate:gates,
doneAction:2),
sig = Mix(bufs * egs);
Out.ar(0, sig);
}).add;
)
// The Pdef that plays \sound:
(
Pdef(\pat,
Pbind(\instrument, \sound,
\start, Pseq([~b*0, ~b*12],inf),
\end, Pseq([~b*2, ~b*14],inf),
\dur, 4,
\rate, 1,
\legato, 1
));
)
p = Pdef(\pat).play(quant:4);
p.stop;
The problem: It seems that there is not only one synth created by the Pdef, but one for each move in the buffer. Then, the synths created accumulate in stack until saturation.
What is going wrong? … and how to correct that?