Ndef clear fadeTime weird behavior

t = TempoClock(60/60).permanent_(true);

(
Ndef(\sine, {
	SinOsc.ar([100,101]);
} * -12.dbamp
).clock_(t).quant_(1).fadeTime_(5).play
)

Fade-in time works fine.

(
Ndef(\sine, {
	SinOsc.ar([100,101]);
} * -12.dbamp
).clock_(t).quant_(1).fadeTime_(5).clear(2)
)

Fade-out in 2 seconds, as expected.

(
Ndef(\sine, {
	SinOsc.ar([100,101]);
} * -12.dbamp
).clock_(t).quant_(1).fadeTime_(5).clear(10)
)

Fade-out in 5 seconds, no override.

(
Ndef(\sine, {
	SinOsc.ar([100,101]);
} * -12.dbamp
).clock_(t).quant_(1).fadeTime_(10).clear(10)
)

Fade-out in 5 seconds, weird!

(
Ndef(\sine, {
	SinOsc.ar([100,101]);
} * -12.dbamp
).clock_(t).quant_(1).clear(10)
)

Fade-out in 5 seconds, still unexpected.

It seems that the clear method in the Ndef is working when it is smaller than the most recently evaluated fadeTime. If it is larger, in it is ignored and the most recently evaluated fadeTime is used instead. Is this a bug?

This works:

(
Ndef(\sine, 
    {SinOsc.ar([100,101]) * -12.dbamp}
).clock_(t).quant_(1).fadeTime_(5).play
)

Ndef(\sine).clock_(t).quant_(1).clear(10);

So it seems the problem occurs when you pass an object as the 2nd argument to Ndef, thereby setting its source again, then immediately clear it. You are essentially doing this:

(
Ndef(\sine, 
    {SinOsc.ar([100,101]) * -12.dbamp}
).clock_(t).quant_(1).fadeTime_(5).play
)

// then...

(
Ndef(\sine, 
    {SinOsc.ar([100,101]) * -12.dbamp}
);
Ndef(\sine).clear(10);
)

The internals of Ndef / NodeProxy are really complicated, but it goes something like this:

When you set the source of an Ndef, it fades out the previous source according to the original fadeTime, and the new source fades in. Both of these actions are scheduled as MixedBundles to be sent to the server at a precise time.

Immediately after that (but before those bundles are sent), you call Ndef(\sine).clear(10). The original source is still scheduled to fade out over 5 seconds. The new source was scheduled to fade in over 5 seconds, but when you .clear an Ndef, it cancels any previous bundle that starts a new synth, so it doesn’t fade in at all.

At the same time all of this is happening, the Ndef monitor fades out over 10 seconds. If you watch the node tree, you will see your synth fade out over 5 seconds, but the monitor synths (system_link_audio_1) will hang around for another 5 seconds before disappearing.

1 Like

Thanks, that makes sense.

I was hoping to save some time by replacing the play method with the clear method during a live performance, without having to rewrite the Ndef statement again. I guess I have to do that or comment out the whole source argument then.