I’m trying to trigger some action when a pattern has finished. In my example: stop a 2nd pattern from running and playing:
(
x=Pbind(\dur,Pwhite(3,5),\freq,Pn(440,4));
y=Pbind(\dur,Pwhite(1,5),\degree,Prand(Scale.minor.degrees,inf));
x.play;
y.play;
)
when x has finished, I’d like to stop y and release any synth running from that pattern.
Is there a way to attach some kind of “onEnded” function to the x pattern similar on the onFree of the Synth object ?
Today, I’m able to stop any running Synth but not the pattern:
(
~last=nil;
x=
Pseq(
[Pbind(\dur,Pwhite(3,5),\freq,Pn(440,4)),
Pbind(\type,\off,\id,Pfunc({~last['id'][0]})) // <-- Add an extra Step to release the last Synth played under y.
]
);
y=Pmono(\default,\dur,Pwhite(1,5),\degree,Prand(Scale.minor.degrees,inf));
x.play;
y.collect({|event| ~last=event; }).play; // <-- remember the last played event, hence the last played Synth
)