(
	var padOne, padTwo, padThree, padFour, padFive, padSix, padSeven, padEight,
		keys=Array.newClear(25), window, but1, but2, quartz;
	
	w = SCWindow.new("fullscreen", Rect(1281, 0, 1024, 800), border: false).front;
	window = SCWindow.new("closefull", Rect(400, 200, 400, 100)).front;
	
	q = SCQuartzComposerView(w, Rect(0,0,1024,800))
		.path_("/Users/chriswig/Desktop/ACTLab Final Project/quartz/final.qtz")
		.start;
	
	but1 = SCButton.new(window, Rect(20, 20, 340, 30))
		.states_([["close", Color.black, Color.grey]])
		.action_({w.close;});
	
	SynthDef(\pad, {arg midi=48, offSet=0, third=1.2599, gate=0, den=20, dur=0.05;
		var out, freq, grains;
		freq = (midi + offSet).midicps;
		grains = Array.new(8);
		grains = grains.add(GrainIn.ar(1, Dust.kr(den)*gate, dur, SinOsc.ar(freq)));
		grains = grains.add(GrainIn.ar(1, Dust.kr(den)*gate, dur, SinOsc.ar(freq*third)));
		grains = grains.add(GrainIn.ar(1, Dust.kr(den)*gate, dur, SinOsc.ar(freq*1.49831)));
		grains = grains.add(GrainIn.ar(1, Dust.kr(den)*gate, dur, SinOsc.ar(freq*2)));
		grains = grains.add(GrainIn.ar(1, Dust.kr(den)*gate, dur, SinOsc.ar(freq*third*2)));
		grains = grains.add(GrainIn.ar(1, Dust.kr(den)*gate, dur, SinOsc.ar(freq*1.49831*2)));
		grains = grains.add(GrainIn.ar(1, Dust.kr(den)*gate, dur, SinOsc.ar(freq*4)));
		grains = grains.add(GrainIn.ar(1, Dust.kr(den)*gate, dur, SinOsc.ar(freq*third*4)));
		out = Mix.new(grains*0.3);
		Out.ar([0,1], (out*0.4));
	}).store;
	SynthDef(\keys, {arg freq=440, gate=0;
		var out;
		out = CombC.ar(WhiteNoise.ar(EnvGen.kr(Env.perc(0.01,0.01))), 1, freq.reciprocal, 1);
		out = out * EnvGen.kr(Env.adsr(0.02,0.05,0.8,0.3,1,'sine'),gate,doneAction:2);
		Out.ar([0,1], out);
	}).store;
	
	padOne = Synth(\pad, [\offSet, 0]);
	padTwo = Synth(\pad, [\offSet, 2, \third, 1.1892]);
	padThree = Synth(\pad, [\offSet, 4, \third, 1.1892]);
	padFour = Synth(\pad, [\offSet, 5]);
	padFive = Synth(\pad, [\offSet, 7]);
	padSix = Synth(\pad, [\offSet, 9, \third, 1.1892]);
	padSeven = Synth(\pad, [\offSet, 10]);
	padEight = Synth(\pad, [\offSet, 12]);

	NoteOnResponder({ |src, chan, note, vel|
		padOne.set(\gate, 1);
	}, nil, 9, 50, nil);
	NoteOffResponder({ |src, chan, note, vel|
		padOne.set(\gate, 0);
	}, nil, 9, 50, nil);
	
	NoteOnResponder({ |src, chan, note, vel|
		padTwo.set(\gate, 1);
		q.padTwo = 30;
	}, nil, 9, 45, nil);
	NoteOffResponder({ |src, chan, note, vel|
		padTwo.set(\gate, 0);
		q.padTwo = 0;
	}, nil, 9, 45, nil);
	
	NoteOnResponder({ |src, chan, note, vel|
		padThree.set(\gate, 1);
		q.padThree = 30;
	}, nil, 9, 51, nil);
	NoteOffResponder({ |src, chan, note, vel|
		padThree.set(\gate, 0);
		q.padThree = 0;
	}, nil, 9, 51, nil);
	
	NoteOnResponder({ |src, chan, note, vel|
		padFour.set(\gate, 1);
		q.padFour = 30;
	}, nil, 9, 49, nil);
	NoteOffResponder({ |src, chan, note, vel|
		padFour.set(\gate, 0);
		q.padFour = 0;
	}, nil, 9, 49, nil);
	
	NoteOnResponder({ |src, chan, note, vel|
		padFive.set(\gate, 1);
		q.padFive = 30;
	}, nil, 9, 36, nil);
	NoteOffResponder({ |src, chan, note, vel|
		padFive.set(\gate, 0);
		q.padFive = 0;
	}, nil, 9, 36, nil);
	
	NoteOnResponder({ |src, chan, note, vel|
		padSix.set(\gate, 1);
		q.padSix = 30;
	}, nil, 9, 38, nil);
	NoteOffResponder({ |src, chan, note, vel|
		padSix.set(\gate, 0);
		q.padSix = 0;
	}, nil, 9, 38, nil);
	
	NoteOnResponder({ |src, chan, note, vel|
		padSeven.set(\gate, 1);
		q.padSeven = 30;
	}, nil, 9, 46, nil);
	NoteOffResponder({ |src, chan, note, vel|
		padSeven.set(\gate, 0);
		q.padSeven = 0;
	}, nil, 9, 46, nil);
	
	NoteOnResponder({ |src, chan, note, vel|
		padEight.set(\gate, 1);
		q.padEight = 30;
	}, nil, 9, 42, nil);
	NoteOffResponder({ |src, chan, note, vel|
		padEight.set(\gate, 0);
		q.padEight = 0;
	}, nil, 9, 42, nil);
	
	for (48, 72, {arg i;
		NoteOnResponder({|src,chan,note,vel|
			keys.put((i-48), 
				Synth.new(\keys, [\freq, i.midicps, \gate, 1]));
		}, nil, 0, i, nil);
		NoteOffResponder({|src,chan,note,vel|
			keys.at((i-48)).release;
		}, nil, 0, i, nil);
	});
	
	/*r = Routine.new({
		while(true, {q.structure = [true, true, Color.blue, Color.red, 0, 100,
			0, 0, 0, 0, 0, 0, 0, 0];
		0.5.wait;});
	});
	AppClock.play(r);*/
)

(
	NoteOnResponder.removeAll;
	NoteOffResponder.removeAll;
	CCResponder.removeAll;
	MIDIResponder.removeAll;
)
q.padOne = 0;
SCWindow.closeAll;
q.stop;
q.inputKeys.postln;