I’m trying to code GUI for this synth. I would like to call the synth on the server, then use my GUI to set the parameters, then when I hit a button, it will play the synth. I’m having trouble when it comes to the “which buttons”. I’m getting syntax errors. Not sure why. I don’t have much experience with GUI, I’d appreciate any help.
(
SynthDef.new(\envelope1, {
arg s, f, freq, amp, width, which, which2, freqfilter;
var env, selectsig, selectfilter;
env = EnvGen.kr(Env([0,1,0], [s, f]), doneAction:2);
selectsig = Select.ar(which, [SinOsc.ar(freq, 0, amp), Saw.ar(freq, amp), Pulse.ar(freq, width, amp), LFTri.ar(freq, 0, amp)])*env;
selectfilter = Select.ar(which2, [BLowPass.ar(selectsig, freqfilter), BHiPass.ar(selectsig, freqfilter), BBandPass.ar(selectsig, freqfilter)]);
Out.ar(0, selectfilter.dup);
}).add;
)
~envelope1 = Synth.new(\envelope1, [\s, 1, \f, 1, \freq, 400, \amp, 0.5, \which, 2, \width, 0.5, \which2, 0, \freqfilter, 200]);
~startenvelope = Slider.new(w.view, Rect.new(780,502,150,20))
.background_(Color(0.05, 0.2, 0.0))
.thumbSize_(10)
.knobColor_(Color.black)
.action_({
arg obj;
var cf;
cf = obj.value.linexp(0,1,0.01,5).postln;
if(
~envelope1.isPlaying,
~envelope1.set(\s, cf);
);
});
~finishenvelope = Slider.new(w.view, Rect.new(780,552,150,20))
.background_(Color(0.05, 0.2, 0.0))
.thumbSize_(10)
.knobColor_(Color.black)
.action_({
arg obj;
var cf;
cf = obj.value.linexp(0,1,0.01,5).postln;
if(
~envelope1.isPlaying,
~envelope1.set(\f, cf);
);
});
~pulsewidthslider = Slider.new(w.view, Rect.new(780,742,150,20))
.thumbSize_(10)
.knobColor_(Color.black)
.action_({
arg obj;
var cf;
cf = obj.value.linexp(0,1,0.1,0.9).postln;
if(
~envelope1.isPlaying,
~envelope1.set(\width, cf);
);
});
~freqfilter = Slider.new(w.view, Rect.new(980,742,20,150))
.thumbSize_(10)
.orientation_(\vertical)
.knobColor_(Color.black)
.action_({
arg obj;
var cf;
cf = obj.value.linexp(0,1,100,3500).postln;
if(
~envelope1.isPlaying,
~envelope1.set(\filterfreq, cf);
);
});
~whichbutton1 = Button(w, Rect(100, 100, 50, 30))
.states_([
["OFF", Color.white, Color(0.0, 0.2, 0.2)],
["sine", Color.white, Color(0.0, 0.2, 0.2)],
["saw", Color.white, Color(0.0, 0.2, 0.2)],
["pulse", Color.white, Color(0.0, 0.2, 0.2)],
["triangle", Color.white, Color(0.0, 0.2, 0.2)]
])
.font_(Font("Futura", 18))
.action_({
arg obj;
if(
obj.value == 1,
{
\which, 1
},
obj.value == 2,
{
\which, 2
},
obj.value == 3,
{
\which, 3
},
obj.value == 4
{
\which, 4
}
});
~whichbutton2 = Button(w, Rect(100, 100, 50, 30))
.states_([
["OFF", Color.white, Color(0.0, 0.2, 0.2)],
["lowpass", Color.white, Color(0.0, 0.2, 0.2)],
["highpass", Color.white, Color(0.0, 0.2, 0.2)],
["bandpass", Color.white, Color(0.0, 0.2, 0.2)],
])
.font_(Font("Futura", 18))
.action_({
arg obj;
if(
obj.value == 1,
{
\which2, 1
},
obj.value == 2,
{
\which2, 2
},
obj.value == 3,
{
\which, 3
}
})
});
~button = Button(w, Rect(700, 498, 50, 30))
.states_([
["ON", Color.white, Color(0.0, 0.2, 0.2)],
["OFF", Color.white, Color(0.0, 0.75, 0.55)]
])
.font_(Font("totally bogus", 18))
.action_({
arg obj;
if(
obj.value == 1,
{
~envelope1 = Synth.new(
\envelope,
[
\s, ~startenvelope
\f, ~finishenvelope
\freq, 65.41,
\amp, ~sineampslider.value.linexp(0,1,0.1, 1.0),
\width, ~pulsewidthslider
\freqfilter, ~freqfilter
\which, ~whichbutton1
\which2, ~whichbutton2
]
).register;
},
{~envelope1.free}
)
});