// Lets look at a few other GUI objects

(			// create a window to play around with
var w, rsl, dsl, pop, l, multi;
w = SCWindow("GUI Examples", Rect(100, 800, 500, 500));
w.front;

// SCRangeSlider - uncomment different bits to see what they do
rsl = SCRangeSlider(w, Rect(5, 5, 40, 200));
rsl.action = {
// rsl.lo.value.postln;		// This will print the lower value
// rsl.hi.value.postln;		// This will print the higher value
rsl.range.value.postln;		// This will print the difference between the two values
};

// SC2DSlider
dsl = SC2DSlider(w, Rect(50, 5, 200, 200));
dsl.action = {
dsl.x.value.postln;
//dsl.y.value.postln;
};

// Pop-up Menus
pop = SCPopUpMenu(w, Rect(300, 5, 180, 30));
pop.items = [
"item1","item2","item3","item4","Oh I'm so original"
];
pop.action = {
pop.value.postln;
};

// or you could do....
// pop = SCPopUpMenu(w, Rect(300, 5, 180, 30));
// l = [
// "item1","item2","item3","item4","Oh I'm so original"
// ];
// pop.items = l;
// pop.action = {
// [pop.value, l.at(pop.value)].postln;
// };
// What do you think the difference is?

// MultiSlider
multi = SCMultiSliderView(w, Rect(5, 250, 100, 60));
multi.action = {
//[multi.index, multi.currentvalue].postln;
multi.value.postln;
};
)

// Here is our example from before. Let's see if we can modify it so we use 2DSliders
// to control the freq and amp of our synths

(
SynthDef("variablesine", { arg freq=80, freq2=1, amp=1, pan=0.5;
	var osc;
	osc = SinOsc.ar(freq*freq2);
	Out.ar(0, [osc*amp*(1-pan), osc*amp*pan]);
}).writeDefFile;
)

(
SynthDef("modulator", { arg freq=80, amp=1;
	var osc;
	osc = SinOsc.ar(freq);
	ReplaceOut.kr(10, osc*amp);
}).writeDefFile;
)

(
var w, b1, b2, b3, sl1, sl2, sl3, sl4, sl5, num1, num2, num3, num4;
var str1, str2, str3, str4, str5, str6, str7, str8, str9, s;

s = Server.local;

// Create window - 350 x 500 pixels
w = SCWindow("Simple FM Controller", Rect(100, 800, 350, 500));
w.view.background = Color.blue;
w.front;

// Create our 3 buttons
b1 = SCButton(w, Rect(5, 5, 110, 25));
b1.states = [
		["Start Server", Color.black, Color.green],
		["Stop Server", Color.white, Color.red],
			];
b1.action = { arg view;
		if (b1.value == 1, {
				s.boot;
		},{
				s.quit;
		});
};

b2 = SCButton(w, Rect(120, 5, 110, 25));
b2.states = [
		["Load SynthDefs", Color.black, Color.green]
			];
b2.action = { arg view;
	s.sendSynthDef("variablesine");
	s.sendSynthDef("modulator");
};

b3 = SCButton(w, Rect(235, 5, 110, 25));
b3.states = [
		["Play", Color.black, Color.green],
		["Stop", Color.white, Color.red],
			];
b3.action = { arg view;
		if (b3.value == 1, {
				s.sendMsg("/s_new", "variablesine", 1000, 1, 0, "freq", 80, "freq2", 1);
				s.sendMsg("/s_new", "modulator", 1001, 0, 0, "freq", 80);
				s.sendMsg("n_map", 1000, \freq2, 10);
				sl2.value = 1;
				sl4.value = 1/20;
		},{
				s.sendMsg("/n_free", 1000);
				s.sendMsg("/n_free", 1001);
		});
};

// Create our sliders - -------- This is the section we will have to amend
sl1 = SCSlider(w, Rect(25, 100, 50, 300));
sl1.action = {
		var val;
		val = ((800*sl1.value)+80);
		s.sendMsg("/n_set", 1000, "freq", val);
		num1.value = val;
};

sl2 = SCSlider(w, Rect(107, 100, 50, 300));
sl2.action = {
		var val;
		val = sl2.value;
		s.sendMsg("/n_set", 1000, "amp", val);
		num2.value = val;
};

sl3 = SCSlider(w, Rect(191, 100, 50, 300));
sl3.action = {
		var val;
		val = ((1000*sl3.value)+1);
		s.sendMsg("/n_set", 1001, "freq", val);
		num3.value = val;
};

sl4 = SCSlider(w, Rect(274, 100, 50, 300));
sl4.action = {
		var val;
		val = (20*sl4.value);
		s.sendMsg("/n_set", 1001, "amp", val);
		num4.value = val;
};

sl5 = SCSlider(w, Rect(75, 40, 200, 30));
sl5.value = 0.5;
sl5.action = {
		var val;
		val = sl5.value;
		val.postln;
		s.sendMsg("/n_set", 1000, "pan", val);
};

// Create our text strings ---- you can change this if you like, or just get rid of it if you 
str1 = SCStaticText(w, Rect(23, 70, 133, 30));			// can't be bothered!
str1.string = "|-------Variablesine-------|";
str1.font = Font("Futura-Medium", 14);

str2 = SCStaticText(w, Rect(189, 70, 133, 30));
str2.string = "|---------Modulator---------|";
str2.font = Font("Futura-Medium", 14);

str3 = SCStaticText(w, Rect(23, 400, 55, 25));
str3.string = "Freq(Hz)";
str3.font = Font("Futura-Medium", 14);

str4 = SCStaticText(w, Rect(112, 400, 55, 25));
str4.string = "Amp.";
str4.font = Font("Futura-Medium", 14);

str5 = SCStaticText(w, Rect(189, 400, 55, 25));
str5.string = "Freq(Hz)";
str5.font = Font("Futura-Medium", 14);

str6 = SCStaticText(w, Rect(280, 400, 55, 25));
str6.string = "Amp.";
str6.font = Font("Futura-Medium", 14);

str7 = SCStaticText(w, Rect(165, 42, 50, 25));
str7.string = "Pan";
str7.font = Font("Futura-Medium", 14);

str8 = SCStaticText(w, Rect(62, 42, 10, 25));
str8.string = "L";
str8.font = Font("Futura-Medium", 14);

str9 = SCStaticText(w, Rect(279, 42, 10, 25));
str9.string = "R";
str9.font = Font("Futura-Medium", 14);

//create our number boxes
num1 = SCNumberBox(w, Rect(25, 430, 50, 25));
num2 = SCNumberBox(w, Rect(107, 430, 50, 25));
num3 = SCNumberBox(w, Rect(191, 430, 50, 25));
num4 = SCNumberBox(w, Rect(274, 430, 50, 25)); 

)