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

//trying some fm synthesis
~out.ar(2)
p.fadeTime_(3)
~fm= {|maxfreq= 200, amp= 0.1, freq2= 202, amp2= 0.1| Pan2.ar(SinOsc.ar(SinOsc.ar(freq2, 0, amp2).range(0, maxfreq), 0, amp))}
~out= ~fm
~out.play

Tdef(\amp).play(c)
Tdef(\amp, {inf.do{|i| ~fm.set(\amp, 0.rrand(i%4)/8); 1.wait}})

Tdef(\freq, {inf.do{|i| ~fm.set(\freq2, [202, 100.rand].wchoose([0.7, 0.3])); 0.25.wait}})
Tdef(\freq).play(c)

~fm2= {|maxfreq= 600, amp= 0.05, freq2= 602, amp2= 0.1| Pan2.ar(SinOsc.ar(Pulse.ar(freq2, SinOsc.kr(0.3, 0, 0.2, 0.5), amp2).range(0, maxfreq), 0, Lag.kr(amp, 0.5)))}
~out= ~fm+~fm2

Tdef(\amp2).play(c)
Tdef(\amp2, {inf.do{|i| if(i%6==0, {~fm2.set(\amp, [0.05.rand, 0].choose)}); (1/3).wait}})

Tdef(\maxfreq2).play(c)
Tdef(\maxfreq2, {inf.do{|i| ~fm2.set(\maxfreq, (3-(i%16).clip(0, 3))*602); 0.25.wait}})

Tdef(\freq2).play(c)
Tdef(\freq2, {inf.do{|i| ~fm2.set(\freq2, 1.rrand(10).round(2)*[1, 10, 100].choose); 1.wait}})

~pm= {|freq= 1000, amp= 0.01| var pb, pn; pn= LFNoise1.kr(0.3).max(0.1); pb= Pulse.ar(pn, pn); SinOsc.ar(freq, pb, amp)}
~out= ~fm+~fm2+~pm
~pm.release
~pm.clear
~pm= {|freq= 1000, amp= 0.01, lag= 1| var pb, pn; pn= LFNoise1.kr(0.3).max(0.1); pb= Pulse.ar(pn, pn); Pan2.ar(SinOsc.ar(Lag2.kr(freq, lag), pb, amp), SinOsc.kr(0.3))}
~out= ~fm+~fm2+~pm

~pm.set(\amp, 0.005)
Tdef(\pm, {inf.do{|i| if(i%8==3, {~pm.set(\lag, 1.0.rand, \amp, 2.rand*0.005, \freq, [1000, 200].choose)}); 1.wait}})
Tdef(\pm).play(c)

(
Tdef(\amp, {inf.do{|i|
	if(0.9.coin, {
		~fm.set(\amp, 0.rrand(i%4)/8);
		~fm.set(\maxfreq, 200);
	}, {
		if(0.3.coin, {
			8.do{|j| ~fm.set(\maxfreq, [10, 100, 200].choose); ~fm.set(\amp, (j%2)*0.3); (2/8).wait};
		}, {
			~fm.set(\amp, 0.3);
			~fm.set(\maxfreq, 100);
			2.wait;
		});
	}); 1.wait}})
)

Tdef(\amp2, {inf.do{|i| if(i%6==0, {~fm2.set(\amp, [0.05.rand, 0, 0.1].choose)}); (0.25/3).wait}})
(Tdef(\maxfreq2, {inf.do{|i| 
	if(0.3.coin, {
		10.do{~fm2.set(\maxfreq, (1-(i%16).clip(0, 3))*802); 0.125.wait}
	}, {
		10.do{~fm2.set(\maxfreq, (3-(i%16).clip(0, 3))*602); 0.25.wait}
	});
}}))

~pm= {|freq= 1000, amp= 0.01| var pb, pn; pn= LFNoise1.kr(LFSaw.kr(0.3, 0, 0.2, 0.4)).max(0.1); pb= Pulse.ar(pn, pn); SinOsc.ar(freq, pb, amp)}

Tdef(\disrupt).play(c)
(Tdef(\disrupt, {
	inf.do{|i|
		~pm.set(\freq, 10000.rand.round(100));
		~pm.set(\amp, 0.05.rand);
		~fm2.set(\maxfreq, 10000.rand.round(100));
		15.15.wait;
	}
}))

Tdef(\disrupt2).play(c)
(Tdef(\disrupt2, {
	inf.do{|i|
		~fm2.set(\freq2, 10000.rand.round(100));
		~fm2.set(\amp, 0.05.rand);
		~fm.set(\freq2, 2000.rand.round(50));
		16.16.wait;
	}
}))

~pm2= {|freq= 1200, spread= 10, amp= 0.05, dur= 2| Pan2.ar(SinOsc.ar(
	0,
	SinOsc.ar(LFSaw.ar(30, 0, Lag.kr(spread, dur), Lag.kr(freq, dur)), 0, pi/2),
	Line.kr(amp, 0, dur))
)}
~out= ~fm+~fm2+~pm+~pm2

(Tdef(\disrupt2, {
	inf.do{|i|
		~fm2.set(\freq2, 10000.rand.round(100));
		~fm2.set(\amp, 0.05.rand);
		~fm.set(\freq2, 2000.rand.round(50));
		~pm2.rebuild;
		~pm2.set(\dur, 1.5.rrand(3), \freq, 400.rrand(4000).round(300), \spread, 100.rand);
		16.16.wait;
	}
}))

p.end