(
Server.default = s = Server.internal;

s.waitForBoot({

var
soundin, soundin1, soundin2,
soundout1, soundout2, soundout3, soundout4, soundout5, soundout6, soundout7, soundout8,
slide1 = 0, slide2 = 0, slide3 = 0, slide4 = 0, slide5 = 0, slide6 = 0, slide7 = 0, slide8 = 0, slide9 = 0,
slidemidi1 = 0, slidemidi2 = 0, slidemidi3 = 0, slidemidi4 = 0, slidemidi5 = 0, slidemidi6 = 0, slidemidi7 = 0, slidemidi8 = 0, slidemidi9 = 0,
knob1 = 0, knob2 = 0, knob3 = 0, knob4 = 0, knob5 = 0, knob6 = 0, knob7 = 0, knob8 = 0, knob9 = 0,
knobmidi1 = 0, knobmidi2 = 0, knobmidi3 = 0, knobmidi4 = 0, knobmidi5 = 0, knobmidi6 = 0, knobmidi7 = 0, knobmidi8 = 0, knobmidi9 = 0;

SynthDef(\micin, { arg out=20, mic=0, amp=0, master=0;
	var micro;
	micro = SoundIn.ar(mic, 2*amp*master);
	Out.ar(out, micro)
}).add;

SynthDef(\outin, { arg mic=0, amp=0, master=0, in=30;
	var som;
	som = In.ar(in, 2);
	Out.ar(0, som*amp*master)
}).add;

SynthDef(\out, { arg mic=0, amp=0, master=0, in=30, lr=0;
	var som;
	som = In.ar(in, 1);
	Out.ar(lr, som*amp*master)
}).add;

s.sync;

//sistema de lag
Routine({
	inf.do{
		slide1= slide1-(slide1-slidemidi1*0.5);
		slide2= slide2-(slide2-slidemidi2*0.5);
		slide3= slide3-(slide3-slidemidi3*0.5);
		slide4= slide4-(slide4-slidemidi4*0.5);
		slide5= slide5-(slide5-slidemidi5*0.5);
		slide6= slide6-(slide6-slidemidi6*0.5);
		slide7= slide7-(slide7-slidemidi7*0.5);
		slide8= slide8-(slide8-slidemidi8*0.5);
		slide9= slide9-(slide9-slidemidi9*0.5);
		
		knob1= knob1-(knob1-knobmidi1*0.5);
		knob2= knob2-(knob2-knobmidi2*0.5);
		knob3= knob3-(knob3-knobmidi3*0.5);
		knob4= knob4-(knob4-knobmidi4*0.5);
		knob5= knob5-(knob5-knobmidi5*0.5);
		knob6= knob6-(knob6-knobmidi6*0.5);
		knob7= knob7-(knob7-knobmidi7*0.5);
		knob8= knob8-(knob8-knobmidi8*0.5);
		knob9= knob9-(knob9-knobmidi9*0.5);
				
		(1/60).wait;
	};
}).play;

//controlador midi
CCResponder.removeAll;
CCResponder({|src,chan,num,val|
	switch(num,
	
		//intensidade out
		2, {slidemidi1= val.lincurve(0, 127, 0, 2, 3)}, 
		3, {slidemidi2= val.lincurve(0, 127, 0, 2, 3)}, 
		4, {slidemidi3= val.lincurve(0, 127, 0, 2, 3)},
		5, {slidemidi4= val.lincurve(0, 127, 0, 2, 3)},
		6, {slidemidi5= val.lincurve(0, 127, 0, 2, 3)},
		8, {slidemidi6= val.lincurve(0, 127, 0, 2, 3)},
		9, {slidemidi7= val.lincurve(0, 127, 0, 2, 3)},
		12, {slidemidi8= val.lincurve(0, 127, 0, 2, 3)},
		13, {slidemidi9= val.lincurve(0, 127, 0, 2, 3)},
		
		//sensibilidade in
		14, {knobmidi1= val.lincurve(0, 127, 0, 2, 3)},
		15, {knobmidi2= val.lincurve(0, 127, 0, 2, 3)},
		16, {knobmidi3= val.lincurve(0, 127, 0, 2, 3)},	
		17, {knobmidi4= val.lincurve(0, 127, 0, 2, 3)},
		18, {knobmidi5= val.lincurve(0, 127, 0, 2, 3)},
		19, {knobmidi6= val.lincurve(0, 127, 0, 2, 3)},
		20, {knobmidi7= val.lincurve(0, 127, 0, 2, 3)},
		21, {knobmidi8= val.lincurve(0, 127, 0, 2, 3)},		
		22, {knobmidi9= val.lincurve(0, 127, 0, 2, 3)}
	)
});

soundout1 = Synth.tail(s, \outin, [\in, 30]); //sinewaves
soundout2 = Synth.tail(s, \outin, [\in, 32]); //fieldrecordings
soundout3 = Synth.tail(s, \outin, [\in, 34]); //spoken text
soundout4 = Synth.tail(s, \outin, [\in, 36]); //contemplo loop

soundout5 = Synth.tail(s, \out, [\in, 38, \lr, 1]); //III4
soundout6 = Synth.tail(s, \out, [\in, 39, \lr, 0]); //III4

soundin = Synth(\micin, [\mic, 0, \out, 22]); //III3
soundin1 = Synth(\micin, [\mic, 0, \out, 20]); //III4
soundin2 = Synth(\micin, [\mic, 1, \out, 21]); //III4

Routine({
	inf.do{

soundout1.set(\amp, slide1, \master, slide9); //sinewaves
soundout2.set(\amp, slide2, \master, slide9); //fieldrecordings
soundout3.set(\amp, slide3, \master, slide9); //spoken text
soundout4.set(\amp, slide4, \master, slide9); //spoken text

soundout5.set(\amp, slide6, \master, slide9); //III4
soundout6.set(\amp, slide5, \master, slide9); //III4

soundin.set(\amp, knob4, \master, knob9); //III3
soundin1.set(\amp, knob5, \master, knob9); //III4
soundin2.set(\amp, knob6, \master, knob9); //III4
				
		(1/60).wait;
	};
}).play;

});
)