PdefGui and FadeEnvelope

Hi there -

I have a PdefGui, playing back a Pbindef. I’d like to code it so that the Pbindef fades out when you close the PdefGui. I tried the following code, but I think I must be referencing something incorrectly. Does anyone see the error in my ways?

x = PdefGui(Pbindef(\f,
	\instrument, \default,
	\freq, 900,
	\dur, 0.1));

Pbindef(\f).fadeTime = 4;
Pbindef(\f).clear;

If you want to stop when the view is closed, you can use onClose. The only trick is finding the right THING to call onClose on. Try this:

~gui = Pbindef(\f).gui;
~gui.parent.onClose = ~gui.parent.onClose.addFunc({ Pbindef(\test).clear });

Yes, I’m afraid the issue is the fade envelope - not the GUI command. I should have made that more clear in the original post. Pbindef(\test).clear works perfeclty well - but Pbindef(\test).clear(10), for instance does not seem to obey the fadeTime control when a Pdef is inside a PdefGui. Maybe I am overlooking something important, though.

PdefGui(Pdef(\y, Pbind(\dur, 0.25, \degree, Pseq([3, 4, 5b]-2, inf))));
Pdef(\y).fadeTime = 10;
Pdef(\y, Pbind(\amp, 0));

This seems to work - but if anyone can spot a more elegant solution, I’m all ears!

One other thing I’ve noticed in the archives here is using a simple fade envelope, i.e:

~f = { |start, end, time, curve = 0| Pseg(Pseq([start, Pn(end)]), time, curve) }

One thing I was unclear on - is there a way to process a Pbindef so that I can simply multiply whatever the current \amp key is holding by a fade envelope?