(
var a, c, d, s, z, y;
// reverberated sine percussion
d = 6; // number of percolators
c = 5; // number of comb delays
a = 4; // number of allpass delays

play({
		// sine percolation sound :
	s = Mix.ar(Array.fill(d, { Resonz.ar(Dust.ar(2/d, 50), 300 + 3000.0.rand, 0.003)}) );
//	s = Dust.ar(2.5, 2.5);
	
		// reverb predelay time :
	z = DelayN.ar(s, 0.048);
	
		// 7 length modulated comb delays in parallel :
	y = Mix.ar(CombL.ar(z, 0.1, LFNoise1.kr(Array.fill(c,{0.1.rand}), 0.04, 0.05), 15)); 
	
		// chain of 4 allpass delays on each of two channels (8 total) :
	a.do({ y = AllpassN.ar(y, 0.050, [0.050.rand,0.050.rand], 1) });
	
		// add original sound to reverb and play it :
	s+(0.2*y)
}))

(
SynthDef("help-Dust", { arg out=0;
	Out.ar(out, 
		Dust.ar(2.5, 0.5)
	)
}).play;
)

(
SynthDef("dust", { arg dustnum = 6, rq = 0.003, g = 15, freq = 300, frand = 3000.0, d = 36;
var a, s, z, y, osc;
// reverberated sine percussion
d = 36; // number of percolators
c = 5; // number of comb delays
a = 4; // number of allpass delays

		// sine percolation sound :
	s = Mix.ar(Array.fill(d, { Resonz.ar(Dust.ar(dustnum/d, 50), freq + 3000.0.rand, rq)}) );
//	s = Dust.ar(2.5, 2.5);
	
		// reverb predelay time :
	z = DelayN.ar(s, 0.048);
	
		// 7 length modulated comb delays in parallel :
	y = Mix.ar(CombL.ar(z, 0.1, LFNoise1.kr(Array.fill(c,{0.1.rand}), 0.04, 0.05), g)); 
	
		// chain of 4 allpass delays on each of two channels (8 total) :
	a.do({ y = AllpassN.ar(y, 0.050, [0.050.rand,0.050.rand], 1) });
	
		// add original sound to reverb and play it :
	osc = s+(0.2*y);
	Out.ar(0, osc);
}).writeDefFile;
s.sendSynthDef("dust");
)

s.sendMsg("/s_new", "dust", 1000, 1, 0, "d", 0.4);

s.sendMsg("/n_set", 1000, "f", 0.004);
s.sendMsg("/n_set", 1000, "e", 57);
s.sendMsg("/n_set", 1000, "g", 10);
s.sendMsg("/n_set", 1000, "freq", 600);
s.sendMsg("/n_set", 1000, "frand", 8600.0);

// Here's the GUI!

(
var w, b1, b2, b3, sl1, sl2, sl3, sl4, sl5, sl6, sl50, num1, num2, num3, num4, num5, num6;    //lots of variables!
var str1, str2, str3, str4, str5, str6, str7, str8, str9, str10, str11, s;
var col, col2;

col = 0.8;
col2 = 0.7;

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

// Create window - 350 x 500 pixels
w = SCWindow("Dust", Rect(100, 800, 650, 500));
// w.view.background = Color.new(0.8, 0.8, 0.8, 0.8);
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.(col, col, col, col)],
//		["Stop Server", Color.white, Color.(col2, col2, col2, col2)],
		["Start Server"],
		["Stop Server"],
			];
b1.action = { arg view;
		if (b1.value == 1, {
				s.boot;
		},{
				s.quit;
		});
};

b2 = SCButton(w, Rect(120, 5, 110, 25));	// This button sends both our SynthDefs
b2.states = [
		["Load Dust", Color.black, Color.(col, col, col, col)]
			];
b2.action = { arg view;
	s.sendSynthDef("scratchy");
//	s.sendSynthDef("liquid");
};

b3 = SCButton(w, Rect(235, 5, 110, 25));	// This one starts and stops the synths
b3.states = [
//		["Play", Color.black, Color.(col, col, col, col)],
//		["Stop", Color.white, Color.(col2, col2, col2, col2)],
		["Play"],
		["Stop"],
			];
b3.action = { arg view;
		if (b3.value == 1, {
				s.sendMsg("/s_new", "dust", 1000, 1, 0);
//				s.sendMsg("/s_new", "liquid", 1001, 0, 0, "freq", 80);
				s.sendMsg("n_map", 1000, \freq2, 10);
				sl2.value = 0.003;	// These two commands set sliders 2 and 4 to values of
//				sl4.value = 1/20;	// 1 and 1/20 whenever you start the synth
		},{
				s.sendMsg("/n_free", 1000);
//				s.sendMsg("/n_free", 1001);
		});
};

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

sl2 = SCSlider(w, Rect(80, 100, 50, 300));
sl2.value = 0.003;
sl2.action = {
		var val;
//		val = sl2.value;
		val = ((0.1*sl2.value));
		s.sendMsg("/n_set", 1000, "rq", val);
		num2.value = val;		// This will set the value of number box 2 = value of slider 2
};

sl3 = SCSlider(w, Rect(140, 100, 50, 300));
sl3.action = {
		var val;
//		val = sl3.value;
		val = ((1000*sl3.value));
		s.sendMsg("/n_set", 1000, "freq", val);
		num3.value = val;		// This will set the value of number box 2 = value of slider 2
};

sl4 = SCSlider(w, Rect(200, 100, 50, 300));
sl4.action = {
		var val;
//		val = sl4.value;
		val = ((100*sl4.value));
		s.sendMsg("/n_set", 1000, "g", val);
		num4.value = val;		// This will set the value of number box 2 = value of slider 2
};

sl5 = SCSlider(w, Rect(260, 100, 50, 300));
sl5.action = {
		var val;
//		val = sl5.value;
		val = ((100*sl5.value));
		s.sendMsg("/n_set", 1000, "d", val);
		num5.value = val;		// This will set the value of number box 2 = value of slider 2
};

sl6 = SCSlider(w, Rect(320, 100, 50, 300));
sl6.action = {
		var val;
//		val = sl6.value;
		val = ((100*sl6.value));
		s.sendMsg("/n_set", 1000, "g", val);
		num6.value = val;
};

sl50 = SCSlider(w, Rect(75, 40, 200, 30));			// This slider will control the pan
sl50.value = 0.5;								// The default position is set to 0.5 (halfway)
sl50.action = {
		var val;
		val = sl50.value;
		s.sendMsg("/n_set", 1000, "pan", val);	// The value of the slider position is sent to the
};											// pan argument of node 1000 (our variablesine synth)

// Create our text strings
str1 = SCStaticText(w, Rect(20, 70, 133, 30));		// All of our text strings are assigned a position,
str1.string = "       Dust       ";		// content and Font type. You can send colour
str1.font = Font("Lucida Grande", 12);			// (or color!) information as well.

str2 = SCStaticText(w, Rect(189, 70, 133, 30));
str2.string = " ";
str2.font = Font("Lucida Grande", 12);

str3 = SCStaticText(w, Rect(20, 400, 55, 25));
str3.string = "DustNum";
str3.font = Font("Lucida Grande", 12);

str4 = SCStaticText(w, Rect(80, 400, 55, 25));
str4.string = "    RQ";
str4.font = Font("Lucida Grande", 12);

str5 = SCStaticText(w, Rect(140, 400, 55, 25));
str5.string = "  Freq";
str5.font = Font("Lucida Grande", 12);

str6 = SCStaticText(w, Rect(200, 400, 55, 25));
str6.string = "    G";
str6.font = Font("Lucida Grande", 12);

str10 = SCStaticText(w, Rect(260, 400, 55, 25));
str10.string = "  Percs";
str10.font = Font("Lucida Grande", 12);

str11 = SCStaticText(w, Rect(320, 400, 55, 25));
str11.string = "D";
str11.font = Font("Lucida Grande", 12);

str7 = SCStaticText(w, Rect(165, 42, 50, 25));
str7.string = "Pan";
str7.font = Font("Lucida Grande", 12);

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(20, 430, 50, 25));		// Finally, we create our number boxes.
num2 = SCNumberBox(w, Rect(80, 430, 50, 25));		// Each one is assigned a size and position.
num3 = SCNumberBox(w, Rect(140, 430, 50, 25));		// You can assign a default value by using
num4 = SCNumberBox(w, Rect(200, 430, 50, 25)); 	// variablename.value = number eg num1.value = 80; 
num5 = SCNumberBox(w, Rect(260, 430, 50, 25));
num6 = SCNumberBox(w, Rect(320, 430, 50, 25));
)