Error with multiple GUI sliders

I am trying to map four different sliders to control an synthdef and a trigger button. They are for frequency, duration, vibrato, and amplitude. I keep getting this error: FAILURE IN SERVER /n_free Node 1025 not found

Code:
(
SynthDef.new(\basic, {
arg freq=440, amp=0.125, dur=1, vib=1;
var sig, filter, env;
sig = SinOsc.ar(Vibrato.ar(DC.ar(freq),vib,0.01)) * amp; //choose one of these
//sig = LFSaw.ar(Vibrato.ar(DC.ar(freq),vib,0.01)) * amp;
//sig = Pulse.ar(Vibrato.ar(DC.ar(freq),vib,0.01)) * amp;
//sig = LFTri.ar(Vibrato.ar(DC.ar(freq),vib,0.01)) * amp;
filter = LPF.ar(sig, EnvGen.kr(Env([100, 1000, 100], [1, 4]), doneAction:0)); //Other filter names: LPF, BPF, HPF,
env = EnvGen.kr(Env([0,1,0], [0.01, dur]), doneAction:2);
Out.ar(0, env*filter.dup);
}).add;
)

x = Synth.new(\basic, [\dur, 5, \freq, 440, \vib, 5]);

x.set(\freq, 300); // slider
x.set(\dur, 1); //0.5-10, slider
x.set(\vib, 2); //1-10, slider
x.set(\amp, 0.129); //slider
x.free;

(
Window.closeAll;//this is important because it makes sure things don’t layer on top of each other when you re-evaluate
w = Window(“basic”, Rect(750,50,350,250))
.front
.alwaysOnTop_(true);

//frequency
~freqslider = Slider(w, Rect(20,100,150,30)) //x, y, size x, size y
.background_(Color(0.2,0.75,0.95))
.action_({
arg obj;
var ff;
ff = obj.value.linexp(0,1,100,4000).postln;
if(
x.isPlaying, //takes the failure messages out if the slider is moving while the button is off
{x.set(\freq, ff)}
);
~freqnumberBox.value_(obj.value.linexp(0,1,100,4000));//slider updates the number box
});

//freq number box
~freqnumberBox = NumberBox(w, Rect(180,100,80,30))
.value_(100)
.clipLo_(100)
.clipHi_(4000)
.decimals_(2)
.action_({
arg obj;
~freqslider.valueAction_(obj.value.explin(100,4000,0.1)) //the slider updates the number box
});

//freq label
~freqLabel = StaticText(w, Rect(180,60,80,20))
.string_(“freq”)
.align_(\center);

//----------------------------------------
//duration: 0.5-10, slider
~durslider = Slider(w, Rect(20,35,150,30)) //x, y, size x, size y (20,20,150,30))
.background_(Color(0.2,0.75,0.95))
.action_({
arg obj;
var df;
df = obj.value.linexp(0,1,0.5,10).postln;
if(
x.isPlaying, //takes the failure messages out if the slider is moving while the button is off
{x.set(\dur, df)}
);
~durnumberBox.value_(obj.value.linexp(0,1,0.5,10));//slider updates the number box
});

//dur number box
~durnumberBox = NumberBox(w, Rect(180,30,80,30))
.value_(0.5)
.clipLo_(0.5)
.clipHi_(10)
.decimals_(2)
.action_({
arg obj;
~durslider.valueAction_(obj.value.explin(0.5,10,0.1)) //the slider updates the number box
});

//dur label
~durLabel = StaticText(w, Rect(180,130,80,20))
.string_(“dur”)
.align_(\center);

//---------------------------------------------------------
//vibrato: 1-10, slider
~vibslider = Slider(w, Rect(20,150,150,30)) //x, y, size x, size y (20,20,150,30))
.background_(Color(0.2,0.75,0.95))
.action_({
arg obj;
var vf;
vf = obj.value.linexp(0,1,1,10).postln;
if(
x.isPlaying, //takes the failure messages out if the slider is moving while the button is off
{x.set(\vib, vf)}
);
~vibnumberBox.value_(obj.value.linexp(0,1,1,10));//slider updates the number box
});

//vib number box
~vibnumberBox = NumberBox(w, Rect(180,150,80,30))
.value_(1)
.clipLo_(1)
.clipHi_(10)
.decimals_(2)
.action_({
arg obj;
~vibslider.valueAction_(obj.value.explin(1,10,0.1)) //the slider updates the number box
});

//vib label
~vibLabel = StaticText(w, Rect(180,180,80,20))
.string_(“vib”)
.align_(\center);

//-----------------------------------------------
/*
//amplitude: 0-1
~ampslider = Slider(w, Rect(20,200,150,30)) //x, y, size x, size y (20,20,150,30))
.background_(Color(0.2,0.75,0.95))
.action_({
arg obj;
var af;
af = obj.value.linexp(0,1,0.0,1.0).postln;
if(
x.isPlaying, //takes the failure messages out if the slider is moving while the button is off
{x.set(\amp, af)}
);
~ampnumberBox.value_(obj.value.linexp(0,1,0.0,1.0));//slider updates the number box
});

//amp number box
~ampnumberBox = NumberBox(w, Rect(180,200,80,30))
.value_(0.0)
.clipLo_(0.0)
.clipHi_(1.0)
.decimals_(2)
.action_({
arg obj;
~ampslider.valueAction_(obj.value.explin(0,1,0.1)) //the slider updates the number box
});

//amp label
~ampLabel = StaticText(w, Rect(180,230,80,20))
.string_(“amp”)
.align_(\center);
*/
//-----------------------------------------------

//trigger button
~button = Button(w, Rect(270,30,50,30))
.states_([
[“Trigger”, Color.white, Color(0.2,0.75,0.95)],
[“Trigger”, Color.black, Color.gray(0.8)]
])
.action_({
arg obj;
if(
obj.value == 1,
{
x = Synth(
\basic,
[
\freq,
~freqslider.value.linexp(0,1,100,4000).reciprocal,
\dur,
~durslider.value.linexp(0,1,0.5,10).reciprocal,
\vib,
~vibslider.value.linexp(0,1,1,10).reciprocal,
]
).register},
{x.free}
);
});
)

This error means that the client is asking the server to free a Node (i.e. a Synth) that doesn’t exist. That often means that the Node has already been freed by some other means.

In your case it seems like this is happening because you have a SynthDef creating Synths that free themselves after a defined amount of time:

env = EnvGen.kr(Env([0,1,0], [0.01, dur]), doneAction:2);

…combined with a button that has two states, the second of which frees the Synth.

.action_({ arg obj;
    if(obj.value == 1, {
        // ...
    }, { x.free });
});

So in practice you’ll click the button once to create a Synth, then one of two things will happen:

  1. You click again before “dur” has elapsed. The Button’s action func frees the Synth. Then after dur has elapsed, the doneAction associated with the EnvGen in your SynthDef will also try to free the Synth. The Synth is already gone, so you’ll see the “Node not found” error.

  2. You click again after “dur” has elapsed. The EnvGen doneAction has already freed the Synth, so the action func is now attempting to free a nonexistent node and you’ll see the same error.

Hope that helps. This is ultimately a design question, so how you want to solve it is up to you. It also bears mentioning that you can evaluate s.plotTree to see a graphical representation of all running Nodes, which can help when tracking down these sorts of issues.

Finally, when you’re posting code here you can use some simple markdown to make sure that indentation is preserved and the code appears monospaced. Just type ``` at the beginning and end of a block of code. This will make it a lot easier for people to see what’s going on. Thanks!

Thanks.
I changed the synthdef so it would just sustain, but I still don’t know why I can’t get any GUIs to work for it. When I click the button I just get an aweful high pitched sound. And I can see the sliders printing in the post window, but they aren’t affecting the sound at all.

x = Synth.new(\basic2, [\freq, 440, \vib, 5]); //this is how it should sound...
x.set(\freq, 300);
x.set(\vib, 2); //1-10
x.set(\amp, 0.129);
x.free;

(
SynthDef.new(\basic2, {
	arg freq=440, amp=0.125, dur=1, vib=1;
	var sig, filter, env;
	sig = SinOsc.ar(Vibrato.ar(DC.ar(freq),vib,0.01)) * amp; //choose one of these
	//sig = LFSaw.ar(Vibrato.ar(DC.ar(freq),vib,0.01)) * amp;
	//sig = Pulse.ar(Vibrato.ar(DC.ar(freq),vib,0.01)) * amp;
	//sig = LFTri.ar(Vibrato.ar(DC.ar(freq),vib,0.01)) * amp;
	filter = LPF.ar(sig, EnvGen.kr(Env([100, 1000, 100], [1, 4]), doneAction:0)); //Other filter names: LPF, BPF, HPF,
	//env = EnvGen.kr(Env([0,1,0], [0.01, dur]), doneAction:2);
	Out.ar(0, filter.dup);
}).add;
)

(
Window.closeAll;//this is important because it makes sure things don't layer on top of each other when you re-evaluate
w = Window("basic2", Rect(750,50,350,250))
.front
.alwaysOnTop_(true);

//frequency
~freqslider = Slider(w, Rect(20,100,150,30)) //x, y, size x, size y
.background_(Color(0.2,0.75,0.95))
.action_({
	arg obj;
	var ff;
	ff = obj.value.linexp(0,1,100,4000).postln;
	if(
		x.isPlaying, //takes the failure messages out if the slider is moving while the button is off
		{x.set(\freq, ff)}
	);
	~freqnumberBox.value_(obj.value.linexp(0,1,100,4000));//slider updates the number box
});

//freq number box
~freqnumberBox = NumberBox(w, Rect(180,100,80,30))
.value_(100)
.clipLo_(100)
.clipHi_(4000)
.decimals_(2)
.action_({
	arg obj;
	~freqslider.valueAction_(obj.value.explin(100,4000,0.1)) //the slider updates the number box
});

//freq label
~freqLabel = StaticText(w, Rect(180,60,80,20))
.string_("freq")
.align_(\center);

/*
//----------------------------------------
//duration: 0.5-10, slider
~durslider = Slider(w, Rect(20,35,150,30)) //x, y, size x, size y (20,20,150,30))
.background_(Color(0.2,0.75,0.95))
.action_({
	arg obj;
	var df;
	df = obj.value.linexp(0,1,0.5,10).postln;
	if(
		x.isPlaying, //takes the failure messages out if the slider is moving while the button is off
		{x.set(\dur, df)}
	);
	~durnumberBox.value_(obj.value.linexp(0,1,0.5,10));//slider updates the number box
});

//dur number box
~durnumberBox = NumberBox(w, Rect(180,30,80,30))
.value_(0.5)
.clipLo_(0.5)
.clipHi_(10)
.decimals_(2)
.action_({
	arg obj;
	~durslider.valueAction_(obj.value.explin(0.5,10,0.1)) //the slider updates the number box
});

//dur label
~durLabel = StaticText(w, Rect(180,130,80,20))
.string_("dur")
.align_(\center);

*/
//---------------------------------------------------------
//vibrato: 1-10, slider
~vibslider = Slider(w, Rect(20,150,150,30)) //x, y, size x, size y (20,20,150,30))
.background_(Color(0.2,0.75,0.95))
.action_({
	arg obj;
	var vf;
	vf = obj.value.linexp(0,1,1,10).postln;
	if(
		x.isPlaying, //takes the failure messages out if the slider is moving while the button is off
		{x.set(\vib, vf)}
	);
	~vibnumberBox.value_(obj.value.linexp(0,1,1,10));//slider updates the number box
});

//vib number box
~vibnumberBox = NumberBox(w, Rect(180,150,80,30))
.value_(1)
.clipLo_(1)
.clipHi_(10)
.decimals_(2)
.action_({
	arg obj;
	~vibslider.valueAction_(obj.value.explin(1,10,0.1)) //the slider updates the number box
});

//vib label
~vibLabel = StaticText(w, Rect(180,180,80,20))
.string_("vib")
.align_(\center);

//-----------------------------------------------

//amplitude: 0-1
~ampslider = Slider(w, Rect(20,200,150,30)) //x, y, size x, size y (20,20,150,30))
.background_(Color(0.2,0.75,0.95))
.action_({
	arg obj;
	var af;
	af = obj.value.linexp(0,1,0.0,1.0).postln;
	if(
		x.isPlaying, //takes the failure messages out if the slider is moving while the button is off
		{x.set(\amp, af)}
	);
	~ampnumberBox.value_(obj.value.linexp(0,1,0.0,1.0));//slider updates the number box
});

//amp number box
~ampnumberBox = NumberBox(w, Rect(180,200,80,30))
.value_(0.0)
.clipLo_(0.0)
.clipHi_(1.0)
.decimals_(2)
.action_({
	arg obj;
	~ampslider.valueAction_(obj.value.explin(0,1,0.1)) //the slider updates the number box
});

//amp label
~ampLabel = StaticText(w, Rect(180,230,80,20))
.string_("amp")
.align_(\center);

//-----------------------------------------------
//trigger button
~button = Button(w, Rect(270,30,50,30))
.states_([
	["Trigger", Color.white, Color(0.2,0.75,0.95)],
	["Trigger", Color.black, Color.gray(0.8)]
])
.action_({
	arg obj;
	if(
		obj.value == 1,
		{
			x = Synth(
				\basic,
				[
					\freq,
					~freqslider.value.linexp(0,1,100,4000).reciprocal,
					\vib,
					~vibslider.value.linexp(0,1,1,10).reciprocal,
					\amp,
					~ampslider.value.linexp(0,1,0.0,1.0).reciprocal
				]
		).register},
		{x.free}
	);
});
) 

Off the top of my head I can see three changes that will hopefully get you closer to what you’re going for…

First in your SynthDef, try K2A.ar(freq) as opposed to DC.ar(freq). The DC UGen can’t be modulated.

Second, when you’re mapping to or from an exponential range with linexp, explin, etc, neither end of the exponential range can be == 0. You’ll need to change all of your mappings related to ~ampslider and ~ampnumberBox to account for this.

Third, in the ~button action func, the use of reciprocal is unneccessary assuming that your intention is to create a Synth with its parameters set to the current values of the GUI controls.

Again, hope that helps!