Why am I getting this error message?

I wrote a simple Routine, but get an error message when the second Synth plays in the Routine.

(
SynthDef.new(\pinknoise, {
	arg s, f, freq;
	var env, sig, filter;
	env = EnvGen.kr(Env([0,1,1,0], [s, f]), doneAction:2);
	sig = PinkNoise.ar(0.1)!2;
	filter = BLowPass.ar(sig, freq);
	Out.ar(0, filter*env);
}).add;
)

Synth.new(\pinknoise, [\s, 0.1, \f, 1, \freq, 1500]);


(
TempoClock.default.tempo = 100/60;

Routine{
	{
		Synth(\pinknoise, [\s, 1, \f, 5, \freq, 1500]);
		
		15.wait;
		
		Synth(\pinknoise, [\s, 1, \f, 5, \freq, 1500]);
	}.play;
}.play;
)

Error message:

ERROR: should not use a Synth inside a SynthDef

Here`s the corrected code. There is just one too many {} within the routine

(
TempoClock.default.tempo = 100/60;

Routine{
	
		Synth(\pinknoise, [\s, 1, \f, 5, \freq, 1500]);
		
		15.wait;
		
		Synth(\pinknoise, [\s, 1, \f, 5, \freq, 1500]);
	
}.play;
)

PS: I deleted my previous answer because I misread the code

EDIT: The reason for the error is because {}.play already creates an instance of Synth: https://sc-users.bham.ac.narkive.com/ZAb27yrz/synth-inside-synthdef

1 Like