GUI in Patterns

I made a GUI to control the frequency values and ‘dur’ values in a pattern through a couple of buttons. The first button is supposed to change between the different Pseq’s, but nothing happens when I press the button. The second button works for the ‘dur’ values. How come this happens? Why can’t I change between the different Pseq’s? I’d appreciate any help.

Server.killAll;
s.boot;

(
SynthDef.new(\sinesynth, {
	arg freq;
	var env, sig;
	env = EnvGen.kr(Env([0,1,0], [0.01, 0.5]), doneAction:2);
	sig = SinOsc.ar(freq, 0, 1.0);
	Out.ar(0, env*sig.dup);
}).add;
)

x = Synth.new(\sinesynth, [\freq, 600]);



(
Pbind(
	\instrument, \sinesynth,
	\freq, Pswitch([
		Pseq([100, 200, 300, 400], inf),
		Pseq([600, 700, 700, 900], inf),
		Pseq([400, 500, 500, 600], inf),
		Pseq([1000, 700, 700, 500], inf)], Pdefn(\which, 0)),
	\dur, Pswitch([1/4, 1/8, 1/16, 1/32], Pdefn(\which2, 0)),
	\stretch, 2.0,
	\out, 0,
).play;
)


(
w = Window.new("gui", Rect.new(100, 100, 200, 200));
w.front;
w.alwaysOnTop_(true);
w.view.background_(Color.fromHexString("#292939"));



~whichbutton = Button(w, Rect(20, 70, 80, 40))
.states_([
	["which 1", Color.white, Color(0.0, 0.2, 0.2)],
    ["which 2", Color.white, Color(0.0, 0.2, 0.2)],
    ["which 3", Color.white, Color(0.0, 0.2, 0.2)],
	["which 4", Color.white, Color(0.0, 0.2, 0.2)],
])
.font_(Font("Futura", 10))
.action_({
	arg obj;
	Pdefn(\which, obj.value);
});



~whichbutton2 = Button(w, Rect(20, 120, 80, 40))
.states_([
	["which 1", Color.white, Color(0.0, 0.2, 0.2)],
    ["which 2", Color.white, Color(0.0, 0.2, 0.2)],
    ["which 3", Color.white, Color(0.0, 0.2, 0.2)],
	["which 4", Color.white, Color(0.0, 0.2, 0.2)],
])
.font_(Font("Futura", 10))
.action_({
	arg obj;
	Pdefn(\which2, obj.value);
});
)

I should have paid more attention to the help file for ‘Pswitch’. I changed it to ‘Pswitch1’ which fixed my problem. I’ll leave this here for future reference, if needed.

2 Likes