// { PinkNoise.ar(0.2 ! 2) }.play;
Ndef(\ro).play;

(
Ndef(\ro, {
	var exc, freqs, son, amps;
	amps = \amps.kr(1 ! 9);
	exc = PinkNoise.ar(1);
	freqs = (0..8).linexp(0, 8, 100, 3000);
	son = BPF.ar(exc, freqs, 0.01) * amps;
	
	son.sum ! 2 * 60
	
}).play;
)

(
Tdef(\x, {
		loop {
			0.2.wait;
			Ndef(\ro).setn(\amps, { 1.0.rand } ! 9);
		}
}).play
);

(
q.cleanData = q.data.slice(nil, nil, 8).select { |x| 
		x[0].isNaN.not
};
);

(
var all = q.data.slice(nil, nil, 8).drop(8);
var prev = all.at(0);
q.cleanData = all.collect { |x| 
		if(x[0].isNaN) { prev }{ x }
};
);

q.data.slice(nil, nil, 8).detectIndex { |x| x[0].isNaN.not }

(q.cleanData - q.cleanData.mean).flop[4..5].plot2
q.cleanData.shape

q.cleanData.mean

q.cleanData.flop.collect { |x| [x.minItem, x.maxItem] }.postcs

(q.cleanData - [q.cleanData.mean]).flop.collect { |x| [x.minItem, x.maxItem] }.postcs

(q.cleanData - [q.cleanData.mean]).flat.sort.first;

(
Tdef(\x, {
		var data, mean, mask;
		data = q.cleanData;
		mean = data.mean;
		data = data - [mean];
		//mask = [1, 1, 1, 0, 0, 0, 0, 0, 0];
		//mask = [0, 0, 0, 0, 0, 0, 0, 1, 1];
		//mask = [0, 0, 0, 0, 0, 0, 1, 1, 1];
		//mask = 1 ! 9;
		mask = [0.2, 0.3, 0.5, 0.7, 1, 1, 1, 1, 1];
		loop {
			data.do { |dT|
				var amp;
					amp = dT.linexp(-8, 8, 0.01, 1);
					Ndef(\ro).setn(\amps, amp * mask);
				
					0.03.wait;
			};
			Ndef(\ro).setn(\amps, 0 ! 9);
			1.wait;
			
		};
}).play;
Ndef(\ro).play;
);

///////////////////////////////////////////////////

(
Ndef(\ro, {
	var exc, freqs, son, amps;
	amps = \amps.kr(1 ! 9).lag(0.1);
	exc = PinkNoise.ar(1);
	freqs = (0..8).linexp(0, 8, 100, 3000);
	freqs = freqs * amps.linlin(0, 1, 1 - 0.02, 1 + 0.02);
	son = BPF.ar(exc, freqs, 0.01) * amps;
	
	son.sum ! 2 * 60
	
}).play;
)

(
var lat = 8;
var all = q.data.slice(nil, nil, lat).drop(8);
var prev = all.at(0);
q.cleanData = all.collect { |x| 
		if(x[0].isNaN) { prev }{ x }
};
Tdef(\x).reset;
Ndef(\ro).play;
);

//////////////////////////////////////////////////

(
var lat = 4;
var all = q.data.slice(nil, nil, lat).drop(8);
var prev = all.at(0);
q.cleanData2 = all.collect { |x| 
		if(x[0].isNaN) { prev }{ x }
};
Tdef(\x).reset;
Ndef(\ro).play;
);

(
Ndef(\ro2, {
	var exc, freqs, son, amps;
	amps = \amps.kr(1 ! 9).lag(0.1);
	exc = PinkNoise.ar(1);
	freqs = (0..8).linexp(0, 8, 100, 3000);
	freqs = freqs * amps.linlin(0, 1, 1 - 0.02, 1 + 0.02);
	son = BPF.ar(exc, freqs, 0.01) * amps;
	
	son.sum ! 2 * 60
	
}).play;
)

(
Tdef(\y, {
		var data, mean, mask;
		data = q.cleanData2;
		mean = data.mean;
		data = data - [mean];
		//mask = [1, 1, 1, 0, 0, 0, 0, 0, 0];
		//mask = [0, 0, 0, 0, 0, 0, 0, 1, 1];
		//mask = [0, 0, 0, 0, 0, 0, 1, 1, 1];
		//mask = 1 ! 9;
		mask = [0.2, 0.3, 0.5, 0.7, 1, 1, 1, 1, 1];
		loop {
			data.do { |dT|
				var amp;
					amp = dT.linexp(-8, 8, 0.01, 1);
					Ndef(\ro).setn(\amps, amp * mask);
				
					0.07.wait;
			};
			Ndef(\ro).setn(\amps, 0 ! 9);
			1.wait;
			
		};
}).play;
Ndef(\ro).play;
);

(
q.breiten = { NodeProxy.audio(s, 2) } ! 18;

(
q.breiten.do { |px| px.source = { |pan|
	var exc, freqs, son, amps;
	amps = \amps.kr(1 ! 9);
	exc = PinkNoise.ar(1);
	freqs = (0..8).linexp(0, 8, 100, 3000);
	son = BPF.ar(exc, freqs, 0.01) * amps;
	
	Pan2.ar(son.sum * 5, pan)
	
} }
);
);

q.breiten.do(_.stop);
q.breiten.do(_.play);

(
(0..17).normalize(-1, 1).do { |pan, i| q.breiten[i].set(\pan, pan) };
);

(
q.cleanAllData = 18.collect { |i|
	var all = q.data.slice(nil, nil, i).drop(8);
	var prev = all.at(0);
	all.collect { |x| 
			if(x[0].isNaN) { prev }{ x }
	};
};
);

q.cleanAllDataMean = q.cleanAllData.collect { |month|
		month.mean
};

q.cleanAllDataMean.shape

(
Tdef(\x, {
		var data, mean;
		data = q.cleanAllData;
		mean = q.cleanAllDataMean;
		data = data - [mean];
		loop {
			data.do { |latData, i|
				latData.do { |dT|
					var amp;
						amp = dT.linexp(-5, 5, 0.01, 1);
						q.breiten[i].setn(\amps, amp);
				};
				0.07.wait;
			};
			q.breiten.do { |px| px.setn(\amps, 0 ! 9) };
			1.wait;
			
		};
}).play;
q.breiten.do(_.play);
);