I think I’ve found a solution to what I was looking for using the “pattern-write-on-a-control-bus” approach.
Here’s the code:
// first create a control bus to be used to write a value on on
// every barline and read this by a synth on the server side
~my_bus = Bus.control(s, 1);
// eventaully plot it in order to check the values on the bus
~my_bus.scope;
// evaluate a pattern of "bus" type to write values on the bus
(
Pbindef(\test_bus_ctrl,
\type, \bus,
\out, ~my_bus,
\array, Pseq([0.0, 1.0], inf),
\dur, 1
).quant_([4]).stop.play;
)
// define a synth to read from the buffer and use values on it to change
// the sound it produces.
(
SynthDef(\freezer, {
|out=0, gate, amp=0.9, pan=0.0,
atk=5, dcy=0.2, sus=0.7, rel=5,
buf, bus
|
var sig, env, chain;
// we are using a control bus to feed the synth
var trigger = In.kr(bus,1);
env = EnvGen.kr(Env.adsr(atk, dcy, sus, rel), gate, doneAction:2);
sig = PlayBuf.ar(1, buf, loop:1);
chain = FFT( LocalBuf((2048), 1), sig);
chain = PV_Freeze(chain, trigger );
sig = IFFT(chain);
sig = LeakDC.ar(sig);
sig = sig * env * amp;
Out.ar(out, Pan2.ar(sig, pan));
}).add;
);
// load a buffer, anything you want
~my_buffer = Buffer.read(s, "/path/to/your/mono/soundfile.wav");
// now istantiate your synth, you should hear the sound being
// freezed on every strong accent barlines while values ones and zeroes
// alternate in the control bus
(
x = Synth(\freezer, [
\out, 0, \gate, 1, \amp, 0.9,
\buf, ~my_buffer,
\bus, ~my_bus, \pan, 0.0
])
)
// you can easily see how a tempo change has immediate effect on the sound
t = TempoClock.default;
t.tempo_(60/60)
t.tempo_(95/60)
t.tempo_(120/60)
// eventually stop the pattern and free the synth
Pbindef(\test_bus_ctrl).stop;
x.free;