I've been trying to create a synth that will ultimately control the playback of audio from a wave file. The synth is currently called quantizedbleep (it just plays a random sine tone).
With James' help I've managed to get play/stop commands to this voice time-quantized to the tick of a second 'metronome' synth.
I want to only play one note at once, but have a tiny bit of overlap so i can have a tiny fade in/out on each note to avoid clicks.
So when I want to trigger a new 'note', i first send a set gate 0 command to the old instance of the synth, (which should ultimately result in that node being deallocated), and then i instantiate a new instance of the synth.
Triggering new notes this way works as expected if i just do this once between each metronome click: the synth count always settles at 2 (one metronome synth and one quantizedbleep synth).
But if i trigger notes this way several times between metronome pulses, unwanted synths get left behind on the server. I'm not sure why this is happening; i thought that the FreeSelf routine I have would keep unwanted synths from building up in the case of multiple notes being requested inbetween metronome pulses.
Apologies for the complexity of this example:
(
var metronome_bus;
s = Server.local;
s.reboot;
s.waitForBoot({
// A metronomic pulse
SynthDef("metronome", { arg hz,metronome_bus;
var im=Impulse.ar(hz, 0.0, 1);
OffsetOut.ar(metronome_bus,im);
Out.ar(0,im);
}).send(s);
// Beep note on/note offs should be carried out on the next metronome tick
SynthDef("quantisedbeep", { arg gate=1,metronome_bus;
var quantizedgate=SetResetFF.ar(
Trig.ar(gate,4)*(In.ar(metronome_bus)),
Trig.ar((gate-1).abs,4)*(In.ar(metronome_bus))
);
var env=Env.asr(0.005, 0.5, 0.005, 1, 'linear');
var env_gen=EnvGen.kr(env, gate: quantizedgate, doneAction: 2);
var sine = SinOsc.ar(Rand(800.0, 900.0),0,0.5);
var note = (sine)*(env_gen);
// Free the node if a gate off is received before quantizedgate is turned on
FreeSelf.kr(
((quantizedgate-1).abs)*((gate-1).abs);
);
Out.ar(0,note);
}).send(s);
SystemClock.sched(0.5,
{
m=Bus.audio(s);
t=Synth(\metronome,[\hz,0.25,\metronome_bus,m]);}
);
})
)
(
// Run this in one go. I expected the Synth count to settle on 2 (one metronome and one quantizedbleep). But instead, other unreferenced synths are accumulating left on the server.
x.set(\gate,0);
x=Synth("quantisedbeep",[\metronome_bus,m], s, \addToTail);
x.set(\gate,0);
x=Synth("quantisedbeep",[\metronome_bus,m], s, \addToTail);
x.set(\gate,0);
x=Synth("quantisedbeep",[\metronome_bus,m], s, \addToTail);
)
Can anyone see why the synths are building up here?