Noob: Fadetime on a Routine

Newbie question: is it possible to apply a fadetime to a whole Routine (consisting in several sounds with various envelops)?
I tried with the method stop:

~nameoftheroutine.stop(\fadeTime, 30);

This doesn’t work (neither with Task instead of Routine).
Any idea?

You can’t fade a Routine because it can perform actions which have nothing to do with Synth creation. You’ll need to fade the synths instead.

One way to do it is to have the Routine, when it’s spawning Synths, add them to the same Group. You’ll then be able to control all those synths through the group, including changing arguments simultaneously, as well as sending a release(releaseTime) message.

(
SynthDef(\sustained, { |freq = 440, attack = 0.01, decay = 0.3, sustainLevel = 0.7, release = 1, amp = 0.2, gate = 1, out|
	var sig, env;
	env = Env.adsr(attack, decay, sustainLevel, release).kr(Done.freeSelf, gate);
	sig = SinOsc.ar(freq);
	sig = sig * env * amp;
	Out.ar(out, sig ! 2)
}).add
)	


(
// create a group. it allows for simultaneous argument control of all synths on it, so all synths in the routine will be added to it. 
// it will not survive cmd-period
g = Group(s);
r = Routine {
	Synth(\sustained, [\freq, 100], g);
	1.wait;
	Synth(\sustained, [\freq, 300], g);
	1.wait;
	Synth(\sustained, [\freq, 500], g);
	1.wait;
	Synth(\sustained, [\freq, 700], g);
	1.wait;
}
)

r.play
g.release(4)
1 Like

Pdef supports a fadeTime argument. It does this by changing the \amp parameter, which works well with many short events, but of course doesn’t with long sustained events (since it won’t change the envelope of a running Synth). Ndef can encapsulate a pattern, and does audio crossfading, which may be either more musically relevant or less depending on your sound.

(
Pdef(\player, Pbind(
	\scale, Scale.mixolydian,
	\offset, 0, // <--- changing this will slowly fade to new pattern over 8 beats
	\degree, Pkey(\offset) + Pseq([
		[3, 5, 7],
		[4, 6, 8]
	], inf).stutter(4),
	\dur, 1/2,
	\strum, 1/3
)).play;

Pdef(\player).fadeTime = 8;
)
1 Like

Thank you so much @thresholdpeople and @scztt for your quick replies!
I think the Group is the better solution in my case.