PbindFx type \phrase

hey,
I would like to use the \phrase event type for applying a fx to a granular cloud using PbindFx.
I have investigated in some approaches using other event types then \note together with PbindFx.
For example from this thread Re: [sc-users] Pbindfx questions back from 2015 (i think there have been some updates on PbindFx since then). There are also newer ones like this one PbindFx with no main envelope and type \set - #2 by dkmayer

Basically as far as I understand it you need a routing Synth inside PbindFx and datasharing from the source Synth to make it work. With this setup below where I have been trying to come up with a solution.
Unfortunately I get either ugly clicks or an ever growing stack of Synth Nodes on the server.

So here are some questions i have, related to this setup:

1.) Does the Router SynthDef need an envelope?
2.) Do I need the “phrase bus” cleanup and a Pfunc { ~bus } argument or can i just use a “static” bus for routing.
3.) what should be taken for the \cleanupDelay for the router Synth?

and in general what am I doing wrong atm?
Thanks alot :slight_smile:

(
SynthDef(\test, {
	var gainEnv = EnvGen.ar(Env.perc(\atk.kr(0.01), \rel.kr(1)), doneAction: Done.freeSelf);
	var sig = SinOscFB.ar(\freq.kr(150), \fdbk.kr(0.6));
	sig = sig * gainEnv;
	sig = Pan2.ar(sig, \pan.kr(0)) * \amp.kr(0.25);
	Out.ar(\out.kr(0), sig);
}).add;

SynthDef(\spat, { |out, in, freq = 1, maxDelayTime = 0.005,
    amp = 1, mix = 1|
    var sig, inSig;
	inSig = In.ar(in, 2);
	inSig = LeakDC.ar(inSig);
    sig = DelayC.ar(
	   inSig,
	   maxDelayTime,
	   { LFDNoise3.ar(freq, maxDelayTime, maxDelayTime/2) } ! 2,
	   amp
    );
    Out.ar(out, (1 - mix) * inSig + (sig * mix));
}).add;

SynthDef(\router, {
	var sig, gainEnv;
	gainEnv = EnvGen.ar(Env.asr(\atk.kr(0.01), 1, \rel.kr(1)), doneAction: Done.freeSelf);
	sig = In.ar(\in.kr(0), 2);
	sig = sig * gainEnv;
	Out.ar(\out.kr(0), sig)
}).add;
)

(
~routerBus = Bus.audio(s, 2);
~mainGrp = Group.new;
~fxGrp = Group.after(~mainGrp);
)

(
Pdef(\oneshot, { |dur, divs|
    Pbind(
	   \instrument, \test,
		\fdbk, 0.6,
		\atk, 0.001,
		\rel, 0.35,
		\dur, dur.value / divs,
		\degree, Pseq([2, 4, 6, 5], inf),
    )
});

// phrasing pattern, shares data with PbindFx
Pdef(\phrase,
	Pbind(
		\type, \phrase,
		\instrument, \oneshot,

		\dur, Pseq([3, 1, 2, 2], inf).collect(~durs= _),
		\divs, 3,

		\octave, Pseq([3, 4, 5, 4], inf),

		\group, ~mainGrp,
		\out, ~routerBus,

		// "phrase bus", cleanup
		//\out, Pfunc { ~bus = Bus.audio(s, 2) },
		//\delay, Pfunc { ~delay = 5 },
		//\finish, Pfunc { |e| thisThread.clock.sched(e[\delay], { e[\out].free }) }
	)
);

Pdef(\router_fx,
	PbindFx([
		\instrument, \router,
		
		\otherBusArgs, [\in],
		\in, ~routerBus,
		//\in, Pfunc { ~bus },
		\group, ~fxGrp,
		
		\dur, Pfunc { ~durs },
		
		\atk, 0.001,
		\rel, 1,
		
		\cleanupDelay, Pkey(\rel),
		
		//\rel, Pfunc { ~delay - 1 },
		//\cleanupDelay, Pkey(\rel),
		\fxOrder, 1,
	],[
		\fx, \spat,
		\freq, Pwhite(10, 50),
		\maxDelayTime, 0.005,
		\clenupDelay, Pkey(\maxDelayTime),
	])
);

Pdef(\player, Ptpar([0, Pdef(\phrase), 0.0001, Pdef(\router_fx)])).play;
)