// This is MY amazzzziiinnnngggg supercolider interface!!! First, you will notice the 4 synthdefs, and then the giant text that is the interface which controls them! have fun! The difference between this and the other supercollider is that this one has presets, although you may have to move the sliders in order to get them to work (that is why I have put both of these projects on the CD!!!)

(
SynthDef("bubbles", { arg freq=20, amp=0, pan=0.5;
	var f, g, osc;
	f = LFSaw.kr(freq*amp, 0, 24, LFSaw.kr([8,7.23], 0, 3, 80)).midicps; // glissando function which makes this sound like bubbles
	osc = CombN.ar(SinOsc.ar(f, 0, 0.04), 0.2, 0.2, 4); // echoing sine wave
	Out.ar(0, [osc*amp*(1-pan), osc*amp*pan]);     // this makes the def able to be panned
}).writeDefFile;
)

(
SynthDef("sprinkler", { arg freq=10, worm=2, amp=0, pan=0.5;	     //this sounds like a sprinkler because of the pulsing whitenoise 
	var f, g, osc;
	osc = BPZ2.ar(WhiteNoise.ar, (LFPulse.kr(MouseX.kr(0.2,50), 0, worm, amp, 0.5)));  // this generates the pulsing white noise
	Out.ar(0, [osc*amp*(1-pan), osc*amp*pan]);     // this makes the def able to be panned
}).writeDefFile;
)

(
SynthDef("pulse", { arg freq=50, amp=0, pan=0.5;    // this sounds like a pulsing siren
	var f, osc;
	osc = CombL.ar(
	f = LFSaw.kr(freq, 0, 24, LFSaw.kr([8,7.23], 0, 3, 80)).midicps; // glissando function and it also makes the freq control the delay
	RLPF.ar(freq*LFPulse.ar(FSinOsc.kr(0.05,0,80,160),0,0.4,0.05), 
		   FSinOsc.kr([0.6,0.7],0,3600,4000), 0.2),
		0.3, [0.2,0.25], 2);

	Out.ar(0, [osc*amp*(1-pan), osc*amp*pan]);     // this makes the def able to be panned
}).writeDefFile;
)

(
SynthDef("haha", { arg freq=4, freq2=5, freq3=20, amp=0, pan= 0.5;    // this is my synthdef i made from scratch!!!
	var osc;
	osc = SinOsc.ar(freq*freq2*freq3);
	Out.ar(0, [osc*amp*(1-pan), osc*amp*pan]);    // this def is also able to be panned
}).writeDefFile;
)

//THE PRESET PANNING BUTTONS WORK BUT YOU MAY HAVE TO MOVE THEM FIRST BEFORE THEY TAKE EFFECT!!!!

(
var w, b1, b2, b3, b4, b5, b6, b7, b8, sl1, sl2, sl3, sl4, sl5, sl6, sl7, sl8, sl9, sl10, sl11, sl12, num1, num2, num3, num4, num5, num6, num7, num8, num9, num10, num11, num12;    //These are the buttons,sliders, and number boxes!!
var str1, str2, str3, str4, str5, str6, str7, str8, str9, str10, str11, str12, str13, str14, str15, s;   // these are the text strings

s = Server.local;			// instance of a local server

// Create window - 1100 x 500 pixels
w = SCWindow("Jill's creation", Rect(100, 1000, 1100, 500));
w.view.background = Color.red;	// the window background will be red
w.front;						// Bring the window to the front

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

b2 = SCButton(w, Rect(120, 5, 110, 25));	// This button sends all of the synthdefs
b2.states = [
		["Load SynthDefs", Color.black, Color.green]
			];
b2.action = { arg view;
	s.sendSynthDef("bubbles");
	s.sendSynthDef("sprinkler");
	s.sendSynthDef("pulse");
	s.sendSynthDef("haha");
};

b3 = SCButton(w, Rect(235, 5, 110, 25));	// This one starts and stops the synths
b3.states = [
		["On", Color.black, Color.green],
		["Off", Color.white, Color.blue],
			];
b3.action = { arg view;
		if (b3.value == 1, {
				s.sendMsg("/s_new", "bubbles", 1000, 1, 0, "freq", "amp", "pan");
				s.sendMsg("/s_new", "sprinkler", 1001, 1, 0, "worm", 0.01, "amp", "pan");
				s.sendMsg("/s_new", "pulse", 1011, 1, 0, "freq", "amp", "pan");
				s.sendMsg("/s_new", "haha", 1111, 1, 0, "freq", "amp", "pan");
				s.sendMsg("n_map", 1000, \freq2, 10);
				sl1.value = 0;	// These three commands set sliders 1,4,7 and 10 to values of
				sl4.value = 0;
				sl7.value = 0;
				sl10.value = 0;	// 0 so when you turn on the synth the synthdefs are silent
				sl11.value = 0;	
				sl3.value = 0.5;	// this will make the haha freq start at 0
				sl6.value = 0.5;	// sl7 and 10 will start so the panning is on both sides equally
				sl9.value = 0.5;
				sl12.value = 0.5;
		},{
				s.sendMsg("/n_free", 1000);	// this lets all the sounds work in the interface
				s.sendMsg("/n_free", 1001);
				s.sendMsg("/n_free", 1011);
				s.sendMsg("/n_free", 1111);
		});
};

b4 = SCButton(w, Rect(350, 5, 110, 25));	// This button is a preset that changes bubbles!
b4.states = [
		["Preset 1", Color.black, Color.green]
			];
b4.action = { arg view;
		s.sendMsg("/n_set", 1000, "amp", 2.0);
		sl1.value = 0.5;
		num1.value = 2.0; 
		s.sendMsg("/n_set", 1000, "freq", 2.0);
		sl2.value = 0.5;
		num2.value = 0.5; 
		s.sendMsg("/n_set", 1000, "pan", 0.0);
		sl3.value = 1;
		num3.value = 0; 
};

b5 = SCButton(w, Rect(465, 5, 110, 25));	// This button is a preset that changes all of the frequencies!!!!
b5.states = [
		["Preset 2", Color.black, Color.green]
			];
b5.action = { arg view;
		s.sendMsg("/n_set", 1000, "freq", 2.0);
		sl2.value = 1;
		num2.value = 3.0; 
		s.sendMsg("/n_set", 1001, "freq", 2.0);
		sl5.value = 1;
		num5.value = 1; 
		s.sendMsg("/n_set", 1011, "freq", 2.0);
		sl8.value = 1;
		num8.value = 1; 
		s.sendMsg("/n_set", 1111, "freq", 2.0);
		sl11.value = 1;
		num11.value = 1; 
};

b6 = SCButton(w, Rect(580, 5, 110, 25));	// This button is a preset that changes sprinkler and haha
b6.states = [
		["Preset 3", Color.black, Color.green]
			];
b6.action = { arg view;
		s.sendMsg("/n_set", 1001, "freq", 2.0);
		sl4.value = 0.5;
		num4.value = 0.5; 
		s.sendMsg("/n_set", 1001, "amp", 2.0);
		sl3.value = 1;
		num3.value = 1; 
		s.sendMsg("/n_set", 1111, "amp", 2.0);
		sl10.value = 1;
		num10.value = 1.0; 
		s.sendMsg("/n_set", 1111, "freq", 2.0);
		sl11.value = 1;
		num11.value = 1; 
		s.sendMsg("/n_set", 1111, "pan", 2.0);
		sl12.value = 1;
		num12.value = 1; 
};
b7 = SCButton(w, Rect(695, 5, 110, 25));	// This button is a preset that changes the panning, this may be a different side depending on what way the peakers or headphones are set up!!!!
b7.states = [
		["PAN RIGHT", Color.black, Color.green]
			];
b7.action = { arg view;
		s.sendMsg("/n_set", 1000, "pan");
		sl3.value = 0;
		num3.value = 0; 
		s.sendMsg("/n_set", 1001, "pan");
		sl6.value = 0;
		num6.value = 0; 
		s.sendMsg("/n_set", 1011, "pan");
		sl9.value = 0;
		num9.value = 0; 
		s.sendMsg("/n_set", 1111, "pan");
		sl12.value = 0;
		num12.value = 0; 
};

b8 = SCButton(w, Rect(810, 5, 110, 25));	// This button changes the panning as well
b8.states = [
		["PAN LEFT", Color.black, Color.green]
			];
b8.action = { arg view;
		s.sendMsg("/n_set", 1000, "pan");
		sl3.value = 1;
		num3.value = 1; 
		s.sendMsg("/n_set", 1001, "pan");
		sl6.value = 1;
		num6.value = 1; 
		s.sendMsg("/n_set", 1011, "pan");
		sl9.value = 1;
		num9.value = 1; 
		s.sendMsg("/n_set", 1111, "pan");
		sl12.value = 1;
		num12.value = 1; 
};

// Create our sliders
sl1 = SCSlider(w, Rect(25, 100, 50, 300));
sl1.action = {
		var val;
		val = (3*sl1.value);
		s.sendMsg("/n_set", 1000, "amp", val);	// this is the amp of bubbles
		num1.value = val;		// This will set the value of number box 1 = value of slider 1
};

sl2 = SCSlider(w, Rect(107, 100, 50, 300));
sl2.action = {
		var val;
		val = (1*sl2.value);
		s.sendMsg("/n_set", 1000, "freq", val);	// this is the freq of bubbles
		num2.value = val;		// This will set the value of number box 2 = value of slider 2
};

sl3 = SCSlider(w, Rect(191, 100, 50, 300));
sl3.action = {
		var val;
		val = (1*sl3.value);
		s.sendMsg("/n_set", 1000, "pan", val);	// this is the panning of bubbles
		num3.value = val;		// This will set the value of number box 3 = value of slider 3
};

sl4 = SCSlider(w, Rect(274, 100, 50, 300));
sl4.action = {
		var val;
		val = (1*sl4.value);
		s.sendMsg("/n_set", 1001, "amp", val);	// this is the amp of sprinkler
		num4.value = val;		// Sets number box to slider
};

sl5 = SCSlider(w, Rect(350, 100, 50, 300));
sl5.action = {
		var val;
		val = (1*sl5.value);
		s.sendMsg("/n_set", 1001, "worm", val);	// this is the freq (represented by worm) of pulse
		num5.value = val;		// This will set the value of number box 3 = value of slider 3
};

sl6 = SCSlider(w, Rect(440, 100, 50, 300));
sl6.action = {
		var val;
		val = (1*sl6.value);
		s.sendMsg("/n_set", 1001, "pan", val);	// this is the panning of sprinkler
		num6.value = val;		// Sets number box to slider
};

sl7 = SCSlider(w, Rect(530, 100, 50, 300));
sl7.action = {
		var val;
		val = (1*sl7.value);
		s.sendMsg("/n_set", 1011, "amp", val);	// this is the amp of pulse
		num7.value = val;		// Sets number box to slider

};

sl8 = SCSlider(w, Rect(620, 100, 50, 300));
sl8.action = {
		var val;
		val = (50*sl8.value);
		s.sendMsg("/n_set", 1011, "freq", val);	// this is freq (and delay) of pulse
		num8.value = val;		// This will set the value of number box 3 = value of slider 3
};

sl9 = SCSlider(w, Rect(710, 100, 50, 300));
sl9.action = {
		var val;
		val = (1*sl9.value);
		s.sendMsg("/n_set", 1011, "pan", val);	// this is the panning of pulse
		num9.value = val;		// Sets number box to slider
};

sl10 = SCSlider(w, Rect(800, 100, 50, 300));
sl10.action = {
		var val;
		val = (1*sl10.value);
		s.sendMsg("/n_set", 1111, "amp", val);	// this is the amp of bubbles
		num10.value = val;		// Sets number box to slider
};

sl11 = SCSlider(w, Rect(890, 100, 50, 300));
sl11.action = {
		var val;
		val = (50*sl11.value);
		s.sendMsg("/n_set", 1111, "freq", val);	// this is the freq of bubbles
		num11.value = val;		// Sets number box to slider
};

sl12 = SCSlider(w, Rect(980, 100, 50, 300));
sl12.action = {
		var val;
		val = (1*sl12.value);
		s.sendMsg("/n_set", 1111, "pan", val);	// this is the panning of haha
		num12.value = val;		// Sets number box to slider
};

// Create our text strings
str1 = SCStaticText(w, Rect(23, 70, 1330, 30));		// All of our text strings are assigned a position,
str1.string = "|----------------------------Bubbles-----------------------------|";		// content and Font type. You can send colour
str1.font = Font("Futura-Medium", 14);			// (or color!) information as well. there are 9 of them.

str2 = SCStaticText(w, Rect(260, 70, 1330, 30));
str2.string = "|----------------------------Sprinkler----------------------------|";
str2.font = Font("Futura-Medium", 14);

str3 = SCStaticText(w, Rect(530, 70, 1330, 30));
str3.string = "|-----------------------------Pulse------------------------------|";
str3.font = Font("Futura-Medium", 14);

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

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

str5 = SCStaticText(w, Rect(189, 400, 55, 25));
str5.string = "PAN";
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(350, 400, 55, 25));
str7.string = "FREQ";
str7.font = Font("Futura-Medium", 14);

str8 = SCStaticText(w, Rect(440, 400, 55, 25));
str8.string = "PAN";
str8.font = Font("Futura-Medium", 14);

str9 = SCStaticText(w, Rect(530, 400, 55, 25));
str9.string = "AMP";
str9.font = Font("Futura-Medium", 14);

str10 = SCStaticText(w, Rect(800, 70, 1330, 30));
str10.string = "|-------------------------------Haha--------------------------------|";
str10.font = Font("Futura-Medium", 14);

str11 = SCStaticText(w, Rect(620, 400, 55, 25));
str11.string = "FREQ";
str11.font = Font("Futura-Medium", 14);

str12 = SCStaticText(w, Rect(710, 400, 55, 25));
str12.string = "PAN";
str12.font = Font("Futura-Medium", 14);

str13 = SCStaticText(w, Rect(800, 400, 55, 25));
str13.string = "AMP";
str13.font = Font("Futura-Medium", 14);

str14 = SCStaticText(w, Rect(890, 400, 55, 25));
str14.string = "FREQ";
str14.font = Font("Futura-Medium", 14);

str15 = SCStaticText(w, Rect(980, 400, 55, 25));
str15.string = "PAN";
str15.font = Font("Futura-Medium", 14);

//create our number boxes
num1 = SCNumberBox(w, Rect(25, 430, 50, 25));		// Finally, we create our number boxes.
num2 = SCNumberBox(w, Rect(107, 430, 50, 25));		// Each one is assigned a size and position.
num3 = SCNumberBox(w, Rect(191, 430, 50, 25));		// You can assign a default value by using
num4 = SCNumberBox(w, Rect(274, 430, 50, 25)); 	// variablename.value = number eg num1.value = 80; 
num5 = SCNumberBox(w, Rect(350, 430, 50, 25));		
num6 = SCNumberBox(w, Rect(440, 430, 50, 25));		
num7 = SCNumberBox(w, Rect(530, 430, 50, 25)); 	 
num8 = SCNumberBox(w, Rect(620, 430, 50, 25));		
num9 = SCNumberBox(w, Rect(710, 430, 50, 25));		
num10 = SCNumberBox(w, Rect(800, 430, 50, 25)); 	 
num11 = SCNumberBox(w, Rect(890, 430, 50, 25)); 	
num12 = SCNumberBox(w, Rect(980, 430, 50, 25)); 	
)