p= ProxySpace.push(s.boot)
p.makeTempoClock(2)
c= p.clock

//pulses
~puls1= {|freq= 2.0, w= 0.5| LFPulse.ar(freq, 0, w)};
~puls2= {|freq= 2.1, w= 0.5| LFPulse.ar(freq, 0, w)};
~puls3= {|freq= 2.1, w= 0.5| LFPulse.ar(freq, 0, w)};

~pulses= ~puls1*~puls2*~puls3
~sine1= {|freq= 400, amp= 0.1, pan= 0| Pan2.ar(SinOsc.ar(freq*#[1, 1.01], 0, ~pulses.ar), pan)}
~sine2= {|freq= 400, amp= 0.1, pan= 0| Pan2.ar(SinOsc.ar(freq*#[1, 1.01], 0, ~pulses.ar), pan)}
~sine3= {|freq= 400, amp= 0.1, pan= 0| Pan2.ar(SinOsc.ar(freq*#[1, 1.01], 0, ~pulses.ar), pan)}

~out.ar(2)
~out.play
~out= ~sine1
~out.fadeTime_(10)
~out= ~sine1+~sine2
~out= ~sine1+~sine2+~sine3
~sine1.set(\freq, 440)
~sine1.set(\freq, 400)
~sine1.set(\freq, 40)
~sine1.set(\freq, 400)
~sine1.fadeTime_(1)
~sine2.fadeTime_(1)
~sine3.fadeTime_(1)
~sine1.xset(\freq, 440)
Tdef(\sine1).quant_(4).play(c)
(Tdef(\sine1, {
	inf.do{|i|
		~sine1.xset(\freq, [400, 440, 400, 40].wrapAt(i.div(4)));
		~sine2.xset(\freq, [400, 440, 400, 40].wrapAt(i.div(5)));
		~sine3.xset(\freq, [400, 440, 400, 40].wrapAt(i.div(6)));
		0.5.wait;
	}
}))

(Tdef(\sine2, {
	inf.do{|i|
		~puls1.xset(\w, [0.5, 0.25, 0.5, 0.75].wrapAt(i.div(4)));
		~puls2.xset(\w, [0.5, 0.25, 0.5, 0.75].wrapAt(i.div(5)));
		~puls3.xset(\w, [0.5, 0.25, 0.5, 0.75].wrapAt(i.div(6)));
		(1/3).wait;
	}
}))
Tdef(\sine2).quant_(4).play(c)

~puls1.fadeTime_(0.2)
~puls2.fadeTime_(0.2)
~puls3.fadeTime_(0.2)

(Tdef(\sine3, {
	inf.do{|i|
		~puls1.set(\freq, [1, 1.1, 2, 2.1].wrapAt(i.div(4)));
		~puls2.set(\freq, [1, 1.1, 2, 2.1].wrapAt(i.div(5)));
		~puls3.set(\freq, [1, 1.1, 2, 2.1].wrapAt(i.div(6)));
		1.wait;
	}
}))
Tdef(\sine3).quant_(4).play(c)

~out= {Limiter.ar(~sine1.ar+~sine2.ar+~sine3.ar)}

~pulses.fadeTime_(3)
~pulses= ~puls1+~puls2+~puls3*0.5
~pulses= ~puls1|~puls2|~puls3
~pulses= ~puls1&~puls2&~puls3
~pulses= ~puls1.round(~puls2).round(~puls3)
~pulses= ~puls1.pow(~puls2).sqrt(~puls3)
~pulses= ~puls1*~puls2*~puls3

p.fadeTime_(0.4)
p.fadeTime_(0.14)
p.fadeTime_(0.04)

(Tdef(\sine1, {
	inf.do{|i|
		~sine1.set(\freq, [400, 440, 400, 40].wrapAt(i.div(4)));
		~sine2.set(\freq, [400, 440, 400, 40].wrapAt(i.div(5)));
		~sine3.set(\freq, [400, 440, 400, 40].wrapAt(i.div(3)));
		0.5.wait;
	}
}))

(Tdef(\diss, {
	inf.do{|i|
		~sine1.set(\freq, ([400, 440, 300]/2).wrapAt(i.div(4)));
		~sine2.set(\freq, ([400, 440, 400]/2).wrapAt(i.div(5)));
		~sine3.set(\freq, ([400, 440, 400]/2).wrapAt(i.div(9)));
		0.5.wait;
	}
}))
Tdef(\diss).quant_(4).play(c)

(Tdef(\sine3, {
	inf.do{|i|
		~puls1.set(\freq, [1, 1.1, 2, 4.1].wrapAt(i.div(5)));
		~puls2.set(\freq, [1, 1.1, 2, 5.1].wrapAt(i.div(6)));
		~puls3.set(\freq, [1, 1.1, 2, 6.1].wrapAt(i.div(7)));
		1.wait;
	}
}))

(Tdef(\sine2, {
	inf.do{|i|
		~puls1.set(\w, {1.0.rand}.dup(8).wrapAt(i.div(4)));
		~puls2.set(\w, {1.0.rand}.dup(8).wrapAt(i.div(5)));
		~puls3.set(\w, {1.0.rand}.dup(8).wrapAt(i.div(6)));
		(1/3).wait;
	}
}))

(Tdef(\sine2, {
	inf.do{|i|
		~puls1.set(\w, {1.0.rand}.dup(8).wrapAt(i));
		~puls2.set(\w, {1.0.rand}.dup(8).wrapAt(i));
		~puls3.set(\w, {1.0.rand}.dup(8).wrapAt(i));
		(1/3).wait;
	}
}))

(Tdef(\sine2, {
	inf.do{|i|
		~puls1.set(\w, {1.0.rand.round(0.1)}.dup(8).wrapAt(i));
		~puls2.set(\w, {1.0.rand.round(0.1)}.dup(8).wrapAt(i));
		~puls3.set(\w, {1.0.rand.round(0.1)}.dup(8).wrapAt(i));
		(1/3).wait;
	}
}))

(Tdef(\sine2, {
	inf.do{|i|
		~puls1.set(\w, {0.5.rand.round(0.25)+0.4}.dup(8).wrapAt(i));
		~puls2.set(\w, {0.5.rand.round(0.25)+0.4}.dup(8).wrapAt(i));
		~puls3.set(\w, {0.5.rand.round(0.25)+0.4}.dup(8).wrapAt(i));
		(1/3).wait;
	}
}))

(Tdef(\sine2, {
	inf.do{|i|
		~puls1.set(\w, {0.5.rand.round(0.25)+0.4}.dup(4).wrapAt(i));
		~puls2.set(\w, {0.5.rand.round(0.25)+0.4}.dup(4).wrapAt(i));
		~puls3.set(\w, {0.5.rand.round(0.25)+0.4}.dup(4).wrapAt(i));
		(1/3).wait;
	}
}))

~pulses= ~puls1&~puls2&~puls3
~pulses= ~puls1|~puls2|~puls3

(Tdef(\sine3, {
	inf.do{|i|
		~puls1.set(\freq, [1, 1.1, 2, 4.1].wrapAt(i.div(3)));
		~puls2.set(\freq, [1, 1.1, 2, 5.1].wrapAt(i.div(2)));
		~puls3.set(\freq, [1, 1.1, 2, 6.1].wrapAt(i.div(1.5)));
		1.wait;
	}
}))

(Tdef(\sine3, {
	inf.do{|i|
		~puls1.set(\freq, [1, 1.25, 2, 4.25].wrapAt(i.div(3)));
		~puls2.set(\freq, [1, 1.25, 2, 5.25].wrapAt(i.div(2)));
		~puls3.set(\freq, [1, 1.25, 2, 6.25].wrapAt(i.div(1.5)));
		1.wait;
	}
}))

~sine1= {|freq= 400, amp= 0.1, pan= 0| Pan2.ar(BPF.ar(Saw.ar(freq*#[1, 1.01], ~pulses.ar), 200), pan)}
~sine2= {|freq= 400, amp= 0.1, pan= 0| Pan2.ar(BPF.ar(Pulse.ar(freq*#[1, 1.01], 0.25, ~pulses.ar), 200), pan)}
~sine3= {|freq= 400, amp= 0.1, pan= 0| Pan2.ar(BPF.ar(LFTri.ar(freq*#[1, 1.01], 0, 0.5, ~pulses.ar), 200), pan)}

~sine1= {|freq= 400, amp= 0.1, pan= 0| Pan2.ar(BPF.ar(SinOsc.ar*Saw.ar(freq*#[1, 1.01], ~pulses.ar), 200), pan)}
~sine2= {|freq= 400, amp= 0.1, pan= 0| Pan2.ar(BPF.ar(~sine1.ar*Pulse.ar(freq*#[1, 1.01], 0.25, ~pulses.ar), 200), pan)}
~sine3= {|freq= 400, amp= 0.1, pan= 0| Pan2.ar(BPF.ar(~sine2.ar*LFTri.ar(freq*#[1, 1.01], 0, 0.5, ~pulses.ar), 200), pan)}

~sine1= {|freq= 400, amp= 0.1, pan= 0| Pan2.ar(BPF.ar(SinOsc.ar(SinOsc.kr(~tempo.kr/8, 0, 20, 400))*Saw.ar(freq*#[1, 1.01], ~pulses.ar), 200), pan)}

(Tdef(\sine3, {
	inf.do{|i|
		~puls1.set(\freq, [1, 1.25, 2, 4.25].pow(2).wrapAt(i.div(3)));
		~puls2.set(\freq, [1, 1.25, 2, 5.25].pow(2).wrapAt(i.div(2)));
		~puls3.set(\freq, [1, 1.25, 2, 6.25].pow(2).wrapAt(i.div(1.5)));
		1.wait;
	}
}))

(Tdef(\sine1, {
	inf.do{|i|
		~sine1.set(\freq, [400, 440, 400, 40].scramble.wrapAt(i.div(4)));
		~sine2.set(\freq, [400, 440, 400, 40].scramble.wrapAt(i.div(5)));
		~sine3.set(\freq, [400, 440, 400, 40].scramble.wrapAt(i.div(3)));
		0.5.wait;
	}
}))

~sine2= {|freq= 400, amp= 0.1, pan= 0| var src= ~sine1.ar*Pulse.ar(freq*#[1, 1.01], 0.25, ~pulses.ar); Pan2.ar(BPF.ar(src+CombN.ar(src, 0.5, 0.5), 200), pan)}
~sine3= {|freq= 400, amp= 0.1, pan= 0| var src= ~sine2.ar*LFTri.ar(freq*#[1, 1.01], 0, 0.5, ~pulses.ar); Pan2.ar(BPF.ar(src*CombN.ar(src, 0.5, 0.5), 200), pan)}
~sine1= {|freq= 400, amp= 0.1, pan= 0| var src= SinOsc.ar(SinOsc.kr(~tempo.kr/8, 0, 20, 400))*Saw.ar(freq*#[1, 1.01], ~pulses.ar); Pan2.ar(BPF.ar(src, 400), pan)}

p.fadeTime_(1)
~sine1= {|freq= 400, amp= 0.1, pan= 0| var src= SinOsc.ar(SinOsc.kr(~tempo.kr/8, 0, 20, 400))*Saw.ar(freq*#[1, 1.01], ~pulses.ar); Pan2.ar(HPF.ar(src+CombN.ar(src, 1, 1), 800, 0.1), pan)}

~sine1= {|freq= 400, freq2= 800, amp= 0.1, pan= 0| var src= SinOsc.ar(SinOsc.kr(~tempo.kr/8, 0, 20, 400))*Saw.ar(freq*#[1, 1.01], ~pulses.ar); Pan2.ar(HPF.ar(src+CombN.ar(src, 1, 1), freq, 0.1), pan)}

(Tdef(\sine1, {
	inf.do{|i|
		if(i%4==0, {
			~sine1.set(\freq2, [800, 880, 800, 80].scramble.wrapAt(i)*(i%2+1));
		});
		~sine1.set(\freq, [400, 440, 400, 40].scramble.wrapAt(i.div(4)));
		~sine2.set(\freq, [400, 440, 400, 40].scramble.wrapAt(i.div(5)));
		~sine3.set(\freq, [400, 440, 400, 40].scramble.wrapAt(i.div(3)));
		0.5.wait;
	}
}))

~sine1= {|freq= 400, freq2= 800, amp= 0.1, pan= 0| var src= SinOsc.ar(SinOsc.kr(~tempo.kr/8, 0, 20, 400))*Saw.ar(freq*#[1, 1.01], ~pulses.ar); Pan2.ar(RHPF.ar(src+CombN.ar(src, 0.2, 0.2), freq, 0.3), pan)}

(Tdef(\sine1, {
	inf.do{|i|
		if(i%4==0, {
			~sine1.set(\freq2, [800, 880, 800, 80].scramble.wrapAt(i)*(i%2+1));
		});
		~sine1.set(\freq, [400, 440, 400, 80, 40].scramble.wrapAt(i.div(4)));
		~sine2.set(\freq, [400, 440, 400, 80, 40].scramble.wrapAt(i.div(3)));
		~sine3.set(\freq, [400, 440, 400, 80, 40].scramble.wrapAt(i.div(2)));
		0.5.wait;
	}
}))

(Tdef(\sine1, {
	inf.do{|i|
		if(i%4==0, {
			~sine1.set(\freq2, [800, 880, 800, 80].scramble.wrapAt(i)*(i%3+1));
		});
		~sine1.set(\freq, [400, 440, 400, 80, 40].scramble.wrapAt(i.div(4)));
		~sine2.set(\freq, [400, 440, 400, 80, 40].scramble.wrapAt(i.div(3)));
		~sine3.set(\freq, [400, 440, 400, 80, 40].scramble.wrapAt(i.div(2)));
		0.5.wait;
	}
}))

~pulses= ~puls1.pow(~puls2).sqrt(~puls3)
~pulses= ~puls1.sqrt(~puls2).pow(~puls3)
~pulses= ~puls1.sqrt(~puls2).sqrt(~puls3)

(Tdef(\sine3, {
	inf.do{|i|
		~puls1.set(\freq, [1, 1.25, 2, 4.25].scramble.pow(3).wrapAt(i.div(3)));
		~puls2.set(\freq, [1, 1.25, 2, 5.25].scramble.pow(3).wrapAt(i.div(2)));
		~puls3.set(\freq, [1, 1.25, 2, 6.25].scramble.pow(3).wrapAt(i.div(1.5)));
		2.wait;
	}
}))

~puls1.lag(\freq, 1)
~puls2.lag(\freq, 1)
~puls3.lag(\freq, 1)
~puls1.lag(\freq, 2, \w, 1)
~puls2.lag(\freq, 2, \w, 1)
~puls3.lag(\freq, 2, \w, 1)

a= 0.25
(Tdef(\sine2, {
	inf.do{|i|
		~puls1.set(\w, {0.5.rand.round(0.25)+a}.dup(4).wrapAt(i));
		~puls2.set(\w, {0.5.rand.round(0.25)+a}.dup(4).wrapAt(i));
		~puls3.set(\w, {0.5.rand.round(0.25)+a}.dup(4).wrapAt(i));
		(1/3).wait;
	}
}))

a= 0.1
(Tdef(\diss, {
	inf.do{|i|
		~sine1.set(\freq, ([400, 440, 300]/3).wrapAt(i.div(1.5)));
		~sine2.set(\freq, ([400, 440, 400]/3).wrapAt(i.div(2)));
		~sine3.set(\freq, ([400, 440, 400]/3).wrapAt(i.div(3)));
		0.5.wait;
	}
}))
a= 0.09
a= 0.08

~sine1.lag(\freq, 1)
~sine2.lag(\freq, 1)
~sine3.lag(\freq, 1)

(Tdef(\diss, {
	inf.do{|i|
		~sine1.set(\freq, ([400, 440, 300]/3).wrapAt(i.div(1.5)));
		~sine2.set(\freq, ([400, 440, 400]/3).wrapAt(i.div(2)));
		~sine3.set(\freq, ([400, 440, 400]/3).wrapAt(i.div(3)));
		0.4.wait;
		c.tempo_(1.5.rrand(2.5).round(0.5));
		a= 0.05.rrand(0.1);
	}
}))

~pulses= ~puls1.sqrt(~puls2)*(~puls3)
~pulses= ~puls1*(~puls2)*(~puls3)

(Tdef(\diss, {
	inf.do{|i|
		~sine1.set(\freq, ([400, 440, 300]/2).wrapAt(i.div(1.5)));
		~sine2.set(\freq, ([400, 440, 400]).wrapAt(i.div(2)));
		~sine3.set(\freq, ([400, 440, 400]*2).wrapAt(i.div(3)));
		0.4.wait;
		c.tempo_(1.5.rrand(2.5).round(0.5));
		a= 0.1.rrand(0.15);
	}
}))

Tdef(\diss).stop

(Tdef(\sine3, {
	inf.do{|i|
		~puls1.set(\freq, [1, 2, 2, 3].scramble.wrapAt(i.div(3)));
		~puls2.set(\freq, [1, 3, 2, 5].scramble.wrapAt(i.div(3)));
		~puls3.set(\freq, [1, 4, 2, 7].scramble.wrapAt(i.div(3)));
		2.wait;
	}
}))

(Tdef(\sine3, {
	inf.do{|i|
		~puls1.set(\freq, [1, 2, 2, 3].wrapAt(i.div(4)));
		~puls2.set(\freq, [1, 3, 2, 5].wrapAt(i.div(4)));
		~puls3.set(\freq, [1, 4, 2, 7].wrapAt(i.div(4)));
		2.wait;
	}
}))

a= 0.2

(Tdef(\sine1, {
	inf.do{|i|
		if(i%4==0, {
			~sine1.set(\freq2, [800, 880].wrapAt(i)*(i%3+1));
		});
		~sine1.set(\freq, [400, 440, 400, 80, 40].wrapAt(i.div(4)));
		~sine2.set(\freq, [400, 440, 400, 80, 40].wrapAt(i.div(4)));
		~sine3.set(\freq, [400, 440, 400, 80, 40].wrapAt(i.div(4)));
		0.5.wait;
	}
}))

a= 0.25

(Tdef(\sine3, {
	inf.do{|i|
		~puls1.set(\freq, [4, 2, 2, 3].wrapAt(i.div(4)));
		~puls2.set(\freq, [4, 3, 2, 5].wrapAt(i.div(4)));
		~puls3.set(\freq, [4, 4, 2, 7].wrapAt(i.div(4)));
		2.wait;
	}
}))

~sine1= {|freq= 400, freq2= 800, amp= 0.1, pan= 0| var src= SinOsc.ar(SinOsc.kr(~tempo.kr/8, 0, 20, 400))*Saw.ar(freq*#[1, 1.01], ~pulses.ar); Pan2.ar(RHPF.ar(src+CombC.ar(src, 1, (~tempo.kr.reciprocal/3).min(1), 1, 2), freq, 0.3), pan)}

(Tdef(\sine3, {
	inf.do{|i|
		~puls1.set(\freq, [4, 2, 2, 3].wrapAt(i.div(4)));
		~puls2.set(\freq, [4, 3, 2, 5].wrapAt(i.div(4)));
		~puls3.set(\freq, [4, 4, 2, 7].wrapAt(i.div(4)));
		~sine1.set(\pan, 0.3.rand2);
		2.wait;
	}
}))

a= 0.4
~sine1= {|freq= 400, freq2= 800, amp= 0.1, pan= 0| var src= SinOsc.ar(SinOsc.kr(~tempo.kr/8, 0, 20, freq2/1.5))*Saw.ar(freq*#[1, 1.01], ~pulses.ar); Pan2.ar(RHPF.ar(src+CombC.ar(src, 1, (~tempo.kr.reciprocal/3).min(1), 1, 2), freq, 0.3), pan)}

~sine1= {|freq= 400, freq2= 800, amp= 0.1, pan= 0| var src= SinOsc.ar(SinOsc.kr(~tempo.kr/2, 0, 20, freq2/1.5))*Saw.ar(freq*#[1, 1.01], ~pulses.ar); Pan2.ar(RHPF.ar(src+CombC.ar(src, 1, (~tempo.kr.reciprocal/3).min(1), 1, 2), freq, 0.1), pan)}

~sine2= {|freq= 400, amp= 0.1, pan= 0| var src= ~sine1.ar*Pulse.ar(freq*#[1, 1.01], 0.25, ~pulses.ar); Pan2.ar(RLPF.ar(src+CombN.ar(src, 0.5, 0.5), 300, 0.2), pan)}
~sine3= {|freq= 400, amp= 0.1, pan= 0| var src= ~sine2.ar*LFTri.ar(freq*#[1, 1.01], 0, 0.5, ~pulses.ar); Pan2.ar(RLPF.ar(src*CombN.ar(src, 0.5, 0.5), 400, 0.2), pan)}

~sine2= {|freq= 400, amp= 0.1, pan= 0| var src= ~sine1.ar*Pulse.ar(freq*#[1, 1.01], 0.25, ~pulses.ar); Pan2.ar(RLPF.ar(src+CombN.ar(src, 0.25, 0.25), 300, 0.1), pan)}
~sine3= {|freq= 400, amp= 0.1, pan= 0| var src= ~sine2.ar*LFTri.ar(freq*#[1, 1.01], 0, 0.5, ~pulses.ar); Pan2.ar(RLPF.ar(src*CombN.ar(src, 0.33, 0.33), 400, 0.1), pan)}

(Tdef(\sine3, {
	inf.do{|i|
		~puls1.set(\freq, [4, 2, 2].wrapAt(i.div(4)));
		~puls2.set(\freq, [4, 3, 2].wrapAt(i.div(4)));
		~puls3.set(\freq, [2, 4, 2].wrapAt(i.div(4)));
		~sine1.set(\pan, 0.3.rand2);
		2.wait;
	}
}))

a= 0.3

(Tdef(\sine3, {
	inf.do{|i|
		~puls1.set(\freq, [4, 3].wrapAt(i.div(4)));
		~puls2.set(\freq, [3, 4].wrapAt(i.div(4)));
		~puls3.set(\freq, [2, 4].wrapAt(i.div(4)));
		~sine1.set(\pan, 0.3.rand2);
		2.wait;
	}
}))

a= 0.25

(Tdef(\sine2, {
	inf.do{|i|
		~puls1.set(\w, {a+0.05.rand2}.dup(4).wrapAt(i));
		~puls2.set(\w, {a+0.05.rand2}.dup(4).wrapAt(i));
		~puls3.set(\w, {a+0.05.rand2}.dup(4).wrapAt(i));
		(1/3).wait;
	}
}))

a= 0.4

(Tdef(\sine3, {
	inf.do{|i|
		~puls1.set(\freq, [4, 3].wrapAt(i.div(4)));
		~puls2.set(\freq, [3, 4].wrapAt(i.div(5)));
		~puls3.set(\freq, [2, 4].wrapAt(i.div(6)));
		~sine1.set(\pan, 0.3.rand2);
		2.wait;
	}
}))

a= 0.9
a= 0.5
Tdef(\a).quant_(4).play(c)
Tdef(\a, {inf.do{|i| a= i%16/20+0.1; 0.25.wait}})
Tdef(\diss).play(c)
Tdef(\sine3).stop
Tdef(\diss).stop
Tdef(\sine2).stop
Tdef(\sine2).play(c)
Tdef(\sine1).stop
Tdef(\a).stop
a= 0.9
a= 0.5
a= 0.9
a= 0.5
a= 0.55
~sine2.release(20)
~sine3.release(20)
~puls2.release(20)
~puls3.release(20)

~puls1.release(20)
~sine1.release(20)
Tdef(\sine2).stop
p.clear
Tdef.all
p.pop