Hello everyone,
there is probably a trivial solution to this, but I cannot figure it out.
(
SynthDef(\MainRecordPlayer, { arg bufnum = 0;
var signal;
signal = SoundIn.ar()!2;
RecordBuf.ar(signal, bufnum,recLevel: 1,preLevel: 0,loop: 0);
}).add;
);
~b1 = Buffer.alloc(s, s.sampleRate * 4, 2,bufnum: 1);
~recorder1 = Synth(\MainRecordPlayer,[\out, 0, \bufnum, ~b1]);
~recorder1.free;
(
a = SynthDef(\playback_buf, { arg out, bufnum, amp, rate = 1, startpos = 0;
var signal;
signal = PlayBuf.ar(2,bufnum,rate,1,startpos,0,2) * amp;
DetectSilence.ar(signal,0.1, 1,2);
Out.ar(out, signal);
}).add
);
x = Synth(\playback_buf,[\bufnum, ~b1, \amp, 1]);
~list1 = [[0,0,0,1],[0,0,0,1],[0,0,0,1],[0,0,0,1]]
(
~routine = Routine({
var count = 0, spawner;
g = Group.new;
NodeWatcher.register(g);
while ({(count) != ~list1_3.size},{
count.postln;
spawner = Spawner({| sp |
sp.seq(Ppar([
Pbind(\type, \note,\dur, 1,\instrument, \playback_buf, \bufnum, ~b1,\amp,Pseq(~list1[count]),\group, g)
]));
sp.suspendAll;
}).play;
0.1.wait;
while({ spawner.isPlaying == true},{0.1.wait;});
count = count + 1;
});
"end".postln;
}).play
);
I would like the last while loop
while({ spawner.isPlaying == true},{0.1.wait;});
to delay the routine until all the nodes generated by the Pbind are freed.
At first thought I could just register the spawner or pbind with NodeWatcher, but realized that does not really help.
So I thought I could put them all into a group and do something like
group.size != 0 or group.isEmpty != true but that does not work either.
Then after some searching I bumped into this thread : Evaluate function when synth freed?
and tried to do use the \callback key mentioned there along with \finish
~group = []
(
var myfun = { |n| (~group = ~group.add(n.nodeID))};
var myfun2 = { |n| (~group = ~group.remove(n.nodeID))};
p = Pbind(
//\degree, Pwhite(0, 7, inf),
\dur, 1,
\amp, Pseq(~list1_3[1]),
\finish, { |ev| ev[\id] do: { |id| Node.basicNew(s, id).onFree(myfun); } },
\callback, { |ev| ev[\id] do: { |id| Node.basicNew(s, id).onFree(myfun2); } }
).play;
)
while(group.size != 0 ).....
but it seems like I cannot use the \finish key the same way as callback
Is there any easy work around to this that I am not seeing ?
Last thing I came up with would be to somehow measure the bus output and once it drops to zero send a signal, or evaluate myfun function inside of the SynthDef instead. But those solutions somehow seem a bit out of place and overcomplicated ?
Thank you for any thoughts