doneAction problems / FM synthesis

Hi everyone!
I have some problems I think is with the doneAction code, the piece only works for several seconds long.

(
SynthDef(\fm, {
	arg
	out = 0, freq = 440, freq2 = 440, freq3, carPartial = 1, carPartial1 = 1, carPartial2 =2,
	modPartial = 1, modPartial1=1, modPartialb =1, modPartialb1= 1, modPartialc =1, modPartialc1= 1,
	index = 0, index2 = 0, mul = 0.5,
	indexb = 0, indexb2 = 0, mulb = 0.5,
	indexc = 0, indexc2 = 0, mulc = 0.5,
	at=0 , at1=0, at2=0, dt=0, dt1=0, dt2=0, sl=0, sl1=0, sl2=0, rt=0, rt1=0, rt2=0,
	atb=0 , atb1=0, atb2=0, dtb=0, dtb1=0, dtb2=0, slb=0, slb1=0, slb2=0, rtb=0, rtb1=0, rtb2=0,
	atc=0 , atc1=0, atc2=0, dtc=0, dtc1=0, dtc2=0, slc=0, slc1=0, slc2=0, rtc=0, rtc1=0, rtc2=0,
	atm=0.01, dtm=100, sus=100, rtm=0.1, env;

    var car, car1, car2, mod, mod1, modb, modb1, modc, modc1, mix;

	mod1 = SinOsc.ar(freq * modPartial1,0, freq * index2 *EnvGen.kr(Env.adsr(at2,dt2,sl2,rt2), doneAction:2));
	mod = SinOsc.ar((freq * modPartial) + mod1,0, freq * index *EnvGen.kr(Env.adsr(at1,dt1,sl1,rt1), doneAction:2));
	car = SinOsc.ar((freq * carPartial) + mod, 0, mul*EnvGen.kr(Env.adsr(at,dt,sl,rt), doneAction:2));

modb1 = SinOsc.ar(freq2 * modPartialb1,0, freq2 * indexb2 *EnvGen.kr(Env.adsr(atb2,dtb2,slb2,rtb2), doneAction:2));
	modb = SinOsc.ar((freq2 * modPartialb) + modb1,0, freq2 * indexb *EnvGen.kr(Env.adsr(atb1,dtb1,slb1,rtb1), doneAction:2));
	car1 = SinOsc.ar((freq2 * carPartial1) + modb, 0, mulb*EnvGen.kr(Env.adsr(atb,dtb,slb,rtb), doneAction:2));

	modc1 = SinOsc.ar(freq3 * modPartialc1,0, freq3 * indexc2 *EnvGen.kr(Env.adsr(atc2,dtc2,slc2,rtc2), doneAction:2));
	modc = SinOsc.ar((freq3 * modPartialc) + modc1,0, freq3 * indexc *EnvGen.kr(Env.adsr(atc1,dtc1,slc1,rtc1), doneAction:2));
	car2 = SinOsc.ar((freq3 * carPartial2) + modc, 0, mulc*EnvGen.kr(Env.adsr(atc,dtc,slc,rtc), doneAction:2));
	mix = Mix.new([car, car1, car2]);
	env = EnvGen.kr(Env.linen(0.01, sus, 0.1), doneAction:2);
	mix = mix * env;
	mix = Pan2.ar(mix, 0);
	Out.ar(out,mix*0.2)
}).add;
)
s.plotTree;
{SinOsc.ar(440 * 3.3,0)* EnvGen.kr(Env.adsr(0.0001,8,3,0.1), doneAction:2)}.play
//Gong
(
Synth(\fm, [ \freq, 440, \carPartial, 0.84,      \at,   0.001, \dt, 1.4,  \rt, 0.1,
                       \modPartial, 5.7, \index,  12, \at1, 0.001, \dt1, 3,  \rt1, 0.1,
			           \modPartial1, 3.3,  \index2, 7, \at2, 0.001,  \dt2,8,  \rt2, 0.1,
	                   \freq2, 630, \carPartial1, 0.67,     \atb,   0.001, \dtb, 1.6,  \rtb, 0.1,
                       \modPartialb, 4.3, \indexb,  13, \atb1, 0.001, \dtb1, 2,  \rtb1, 0.1,
			           \modPartialb1, 3.8,  \indexb2, 3, \atb2, 0.001,  \dtb2,8,  \rtb2, 0.1,
	                   \freq3, 62, \carPartial2, 0.67,     \atc,   0.001, \dtc, 1.6,  \rtc, 0.1,
                       \modPartialc, 4.3, \indexc,  13, \atc1, 0.001, \dtc1, 2,  \rtc1, 0.1,
			           \modPartialc1, 3.8,  \indexc2, 3, \atc2, 0.001,  \dtc2,8,  \rtc2, 0.1,]);
)
//GongCentro
(
Synth(\fm, [             \freq, 440, \carPartial, 0.84,      \at,   0.001, \dt, 2,  \rt, 0.1,
                       \modPartial, 5.7, \index,  12, \at1, 0.001, \dt1, 1,  \rt1, 0.1,
			           \modPartial1, 3.3,  \index2, 7, \at2, 0.001,  \dt2,1,  \rt2, 0.1,
	                   \freq2, 630, \carPartial1, 0.67,     \atb,   0.001, \dtb, 1,  \rtb, 0.1,
                       \modPartialb, 4.3, \indexb,  13, \atb1, 0.001, \dtb1, 2,  \rtb1, 0.1,
			           \modPartialb1, 3.8,  \indexb2, 3, \atb2, 0.001,  \dtb2,1,  \rtb2, 0.1,
	                   \freq3, 220, \carPartial2, 0.67,     \atc,   0.001, \dtc, 1,  \rtc, 0.1,
                       \modPartialc, 4.3, \indexc,  13, \atc1, 0.001, \dtc1, 2,  \rtc1, 0.1,
			           \modPartialc1, 3.8,  \indexc2, 3, \atc2, 0.001,  \dtc2,1,  \rtc2, 0.1,]);
)
//Tarola
(
Synth(\fm, [ \freq, 30030, \carPartial, 1,      \at,   0.001, \dt, 0.3,  \rt, 0.1,
                       \modPartial, 0.4, \index,  9, \at1, 0.001, \dt1, 0.4,  \rt1, 0.1,
	                   \modPartial1, 1.9,  \index2, 11, \at2, 0.001,  \dt2,0.3,  \rt2, 0.1,
	                   \freq2, 420, \carPartial1, 1,     \atb,   0.001, \dtb, 0.2,  \rtb, 0.1,
                       \modPartialb, 0.5, \indexb,  9.8, \atb1, 0.001, \dtb1,0.5,  \rtb1, 0.1,
			           \modPartialb1, 0.25,  \indexb2,0.1, \atb2, 0.001,  \dtb2,1,  \rtb2, 0.1,
	                   \freq3, 600, \carPartial2, 0.67,     \atc,   0.001, \dtc,0.1,  \rtc, 0.1,
                       \modPartialc, 1.7, \indexc,  0.4, \atc1, 0.001, \dtc1, 0.4,  \rtc1, 0.1,
			           \modPartialc1, 9.8,  \indexc2, 1, \atc2, 0.001,  \dtc2,0.3,  \rtc2, 0.1  ,]);
)
//Botella
(
Synth(\fm, [ \freq,1000, \carPartial, 1,      \at,   0.001, \dt, 0.4,  \rt, 0.1,
                       \modPartial, 0.9, \index,  9, \at1, 0.001, \dt1, 1,  \rt1, 0.1,
	                   \modPartial1, 0.8,  \index2, 20, \at2, 0.001,  \dt2,0.01,  \rt2, 0.1,
	                   \freq2, 1230, \carPartial1, 0.8,     \atb,   0.001, \dtb, 0.4,  \rtb, 0.1,
                       \modPartialb, 9.7, \indexb,  3, \atb1, 0.001, \dtb1,1,  \rtb1, 0.1,
			           \modPartialb1, 0.25,  \indexb2,8, \atb2, 0.001,  \dtb2,1,  \rtb2, 0.1,
	                   \freq3, 1230, \carPartial2, 1.37,     \atc,   0.001, \dtc,0.1,  \rtc, 0.1,
                       \modPartialc, 9.7, \indexc,  1000, \atc1, 0.001, \dtc1, 2,  \rtc1, 0.1,
			           \modPartialc1, 9.8,  \indexc2, 0, \atc2, 0.001,  \dtc2,1,  \rtc2, 0.1,]);
)
//Woodblock
(
Synth(\fm, [           \freq, 500, \carPartial, 1,      \at,   0.001, \dt, 0.2,  \rt, 0.1,
                       \modPartial, 0.9, \index, 3 , \at1, 0.001, \dt1, 0.2,  \rt1, 0.1,
	                   \modPartial1, 0.8,  \index2, 0, \at2, 0.001,  \dt2,0.01,  \rt2, 0.1,
	                   \freq2, 500, \carPartial1, 1,     \atb,   0.001, \dtb, 0.1,  \rtb, 0.1,
                       \modPartialb,0.9, \indexb,  3, \atb1, 0.001, \dtb1,0.2,  \rtb1, 0.1,
			           \modPartialb1, 0.25,  \indexb2,0, \atb2, 0.001,  \dtb2,1,  \rtb2, 0.1,
	                   \freq3, 250, \carPartial2, 1,     \atc,   0.001, \dtc,0.2,  \rtc, 0.1,
                       \modPartialc, 1, \indexc,  1, \atc1, 0.001, \dtc1, 0.2,  \rtc1, 0.1,
			           \modPartialc1, 3,  \indexc2, 100, \atc2, 0.001,  \dtc2,1,  \rtc2, 0.1,]);
)
//Platillo
(
Synth(\fm, [           \freq, 530, \carPartial, 0.64,      \at,   0.001, \dt,2.5 ,  \rt, 0.1,
                       \modPartial, 8.7, \index,  25, \at1, 0.001, \dt1,15,  \rt1, 0.1,
			          \modPartial1, 3.9,  \index2, 12.5, \at2, 0.001,  \dt2,8,  \rt2, 0.1,

	                   \freq2, 130, \carPartial1, 3.77,     \atb,   0.001, \dtb, 0.3,  \rtb, 0.1,
                       \modPartialb, 9.3, \indexb,  15, \atb1, 0.001, \dtb1, 7,  \rtb1, 0.1,
			           \modPartialb1, 7.5,  \indexb2, 18, \atb2, 0.001,  \dtb2,9,  \rtb2, 0.1,

	                   \freq3, 1500, \carPartial2, 1.34,     \atc,   0.001, \dtc, 1.5,  \rtc, 0.1,
                       \modPartialc, 8, \indexc,  9, \atc1, 0.001, \dtc1, 13,  \rtc1, 0.1,
			           \modPartialc1, 9,  \indexc2, 12, \atc2, 0.001,  \dtc2, 6,  \rtc2, 0.1]);
)


//Tarols
(
Synth(\fm, [ \freq,80, \carPartial, 1,      \at,   0.001, \dt, 1,  \rt, 0.1,
                       \modPartial, 1, \index,  1200, \at1, 0.001, \dt1, 1,  \rt1, 0.1,
	                   \modPartial1, 1.3,  \index2, 13, \at2, 0.001,  \dt2,0.5,  \rt2, 0.1,
	                   \freq2, 4000, \carPartial1, 1,     \atb,   0.001, \dtb, 0.2,  \rtb, 0.1,
                       \modPartialb, 9.7, \indexb,  40, \atb1, 0.001, \dtb1,1,  \rtb1, 0.1,
			           \modPartialb1, 0.25,  \indexb2,1000, \atb2, 0.001,  \dtb2,1,  \rtb2, 0.1,
	                   \freq3, 0, \carPartial2, 1.37,     \atc,   0.001, \dtc,0,  \rtc, 0.1,
                       \modPartialc, 9.7, \indexc,  1000, \atc1, 0.001, \dtc1, 2,  \rtc1, 0.1,
			           \modPartialc1, 9.8,  \indexc2, 0, \atc2, 0.001,  \dtc2,1,  \rtc2, 0.1,]);
)

//Brush

(
Synth(\fm, [ \freq,60, \carPartial, 1,      \at,   1, \dt, 1.3,  \rt, 0.1,
                       \modPartial, 1, \index,  1200, \at1, 0.001, \dt1, 3,  \rt1, 0.1,
	                   \modPartial1, 1.3,  \index2, 400, \at2, 0.001,  \dt2,1,  \rt2, 0.1,
	                   \freq2, 1000, \carPartial1, 1,     \atb,   0.001, \dtb, 0.5,  \rtb, 0.1,
                       \modPartialb, 9.7, \indexb,  100000, \atb1, 0.001, \dtb1,1,  \rtb1, 0.1,
			           \modPartialb1, 0.25,  \indexb2,0, \atb2, 0.001,  \dtb2,1,  \rtb2, 0.1,
	                   \freq3, 0, \carPartial2, 1.37,     \atc,   0.001, \dtc,0.1,  \rtc, 0.1,
                       \modPartialc, 9.7, \indexc,  1000, \atc1, 0.001, \dtc1, 2,  \rtc1, 0.1,
			           \modPartialc1, 9.8,  \indexc2, 0, \atc2, 0.001,  \dtc2,1,  \rtc2, 0.1,]);
)

//Superball

(
Synth(\fm, [
	\freq, 80, \carPartial, 1,      \at,   0.1, \dt, 2,  \rt, 0.1,
                       \modPartial, 0.5, \index,  12, \at1, 0.1, \dt1, 1,  \rt1, 0.1,
	                   \modPartial1, 1.2,  \index2, 10, \at2, 0.001,  \dt2,0.5,  \rt2, 0.1,
	                   \freq2, 40, \carPartial1, 0.5,     \atb,   0.3, \dtb, 1,  \rtb, 0.1,
                       \modPartialb,1, \indexb,  10, \atb1, 0.001, \dtb1,0.5,  \rtb1, 0.1,
			           \modPartialb1, 0.25,  \indexb2,0, \atb2, 0.001,  \dtb2,1,  \rtb2, 0.1,
	                   \freq3, 0, \carPartial2, 1,     \atc,   0.001, \dtc,0.2,  \rtc, 0.1,
                       \modPartialc, 1, \indexc,  0, \atc1, 0.001, \dtc1, 0.2,  \rtc1, 0.1,
			           \modPartialc1, 3,  \indexc2, 0, \atc2, 0.001,  \dtc2,1,  \rtc2, 0.1,
]);
)

//Sonidochill

(
Synth(\fm, [ \freq,20, \carPartial, 1,      \at,   0.001, \dt, 1,  \rt, 0.1,
                       \modPartial, 1.7, \index,  400, \at1, 0.001, \dt1, 1,  \rt1, 0.1,
	                   \modPartial1,0.4,  \index2, 400, \at2, 0.001,  \dt2,1,  \rt2, 0.1,
	                   \freq2, 100, \carPartial1, 1,     \atb,   0.001, \dtb, 0.5,  \rtb, 0.1,
                       \modPartialb, 9.7, \indexb,  100, \atb1, 0.001, \dtb1,1,  \rtb1, 0.1,
			           \modPartialb1, 0.25,  \indexb2,0, \atb2, 0.001,  \dtb2,1,  \rtb2, 0.1,
	                   \freq3, 0, \carPartial2, 1.37,     \atc,   0.001, \dtc,0,  \rtc, 0.1,
                       \modPartialc, 9.7, \indexc,  0, \atc1, 0.001, \dtc1, 2,  \rtc1, 0.1,
			           \modPartialc1, 9.8,  \indexc2, 0, \atc2, 0.001,  \dtc2,1,  \rtc2, 0.1,]);
)

//tarols2
(
Synth(\fm, [ \freq,200, \carPartial, 1,      \at,   0.001, \dt, 1,  \rt, 0.1,
                       \modPartial, 1.7, \index,  400, \at1, 0.001, \dt1, 1,  \rt1, 0.1,
	                   \modPartial1,0.4,  \index2, 400, \at2, 0.001,  \dt2,1,  \rt2, 0.1,
	                   \freq2, 100, \carPartial1, 1,     \atb,   0.001, \dtb, 0.5,  \rtb, 0.1,
                       \modPartialb, 9.7, \indexb,  100, \atb1, 0.001, \dtb1,0.01,  \rtb1, 0.1,
			           \modPartialb1, 0.25,  \indexb2,0, \atb2, 0.001,  \dtb2,1,  \rtb2, 0.1,
	                   \freq3, 0, \carPartial2, 1.37,     \atc,   0.001, \dtc,0,  \rtc, 0.1,
                       \modPartialc, 9.7, \indexc,  0, \atc1, 0.001, \dtc1, 2,  \rtc1, 0.1,
			           \modPartialc1, 9.8,  \indexc2, 0, \atc2, 0.001,  \dtc2,1,  \rtc2, 0.1,]);
)

(
p = Pbind(
	\instrument, \fm,
	\dur, 1/10,
	\carPartial, Pexprand(20, 10000,inf),
	\at, Pexprand(0.1, 0.5, inf),
	\dt, Pexprand(0.01, 1, inf),
	\rt, Pexprand(0.1, 5, inf),
	\modPartial, Pexprand(20, 10000, inf),
	\index, Pexprand(10, 400, inf),
	\at1, Pexprand(0.001, 1.0, inf),
	\dt1, Pwhite(0.0, 1.0, inf),
	\rt1, Pexprand(0.001, 1, inf),
).play;
)

(
p.stop;
)

Can someone help in saying what is wrong?

sus is 100 by default, maybe you’d like to consider a lower value like 2 or 3

you only need one doneAction=2 in your synthdef. try to remove all the done actions except for the final mix envelope

A useful way to ask questions is “expected vs actual” – “I expected (or wanted) behavior A but it did B.”

From your post, we know the actual behavior – “several seconds.” (Although “works” is vague – I have no idea what that means, concretely. It could mean that it plays as you’d like for awhile and then all the synths fall silent. Or it could mean that the server overloads after some seconds… unclear from the description.)

Also I can’t guess the expected/desired behavior, since it’s unstated.

These aren’t stubborn questions – the correct solution depends on understanding the problem well! (There are two guesses in this thread so far – I suspect that Geoffroy is heading in the right direction if the problem is a server overload. The doneAction thing is probably not it because most of the envelopes are ADSR with a constantly-open gate, so they will never end and the doneAction is irrelevant/redundant for them. But… this is all guessing.)

hjh