// some set theory.

q = q ? ();

q.x = Set[1, 3, 5, 6, 11];
q.y = Set[0, 2, 5, 8, 11];

q.x | q.y

(
SynthDef("pine", { |out, freq, amp=0.1, pan, sustain=1.0|
	var f, u, d;
	f = XLine.ar(freq, freq * [1, 1.5], sustain * Rand(0.01, 0.05));
	f = f * 1;
	d = LFSaw.ar(f.neg);
	u = BPF.ar(
		d * 4,
		freq * 1, 
		0.01
	);
	u = u * d;
	u = u.sum;
	Out.ar(out, 
		Pan2.ar(
			u,
			pan,
			EnvGen.kr(Env.perc(0, sustain, amp), doneAction:2)
		)
	)

}).store;

)

(
Pdef(\y, 
	Pbind(
		\instrument, \pine,
		\scale, (q.x & q.y).asArray.sort,
		\degree, Pbrown(-5, 10, 1, inf),
		\dur, Pseq([1, 1, Pn(3/2, 4), 0.25, 0.25, 0.5], inf) * (1/3),

		\legato, Prand([0.1, 0.2, 0.1, 0.2], inf),
		\pan, Pseq([-1, 1, 0.5], inf)
	)
).play
);

(
Pdef(\z, 
	Pbind(
		\instrument, \pine,
		\scale, q.x.asArray.sort,
		\degree, Pbrown(-5, 10, 1, inf),
		\octave, 4,
		\dur, Pseq([1, 1, Pn(3/2, 4), 0.5, 0.5], inf),
		\legato, Prand([0.1, 0.2, 0.1, 0.2], inf),

		\pan, Prand([-1, 1], inf)
	)
).play
);

Pdefn(\scale_y, q.x.asArray.sort);
Pdefn(\scale_z, q.x.asArray.sort);

(
Pdef(\y, 
	Pbind(
		\instrument, \pine,
		\scale, Pdefn(\scale_y),
		\degree, Pn(Pbrown(-5, 10, 1, 14)),
		\dur, Pseq([1, 1, Pn(3/2, 4), 0.5, 0.5], inf) * 0.125,
		\pan, Pseq([-1, 1, 0.5], inf)
	)
).play
);

(
Pdef(\z, 
	Pbind(
		\instrument, \pine,
		\scale, Pdefn(\scale_z),
		\degree, Pbrown(-5, 10, 1, inf),
		\octave, 4,
		\dur, Pseq([1, 1, Pn(3/2, 4), 0.5, 0.5], inf) * 0.125,
		\pan, Prand([-1, 1], inf)
	)
).play
);

Pdef(\z).fadeTime = 15;
Pdef(\y).fadeTime = 15;
Pdef(\z).fadeTime = nil;
Pdef(\y).fadeTime = nil;

Pdefn(\scale_y, (q.x | q.y & q.z).asArray.sort.postln);
Pdefn(\scale_y, (q.x & q.y | q.z).asArray.sort.postln);

Pdefn(\scale_z, (q.x -- q.y | q.y).asArray.sort.postln);
Pdefn(\scale_z, (q.x -- q.y -- q.y).asArray.sort.postln);
Pdefn(\scale_z, (q.x & q.y & q.y).asArray.sort.postln);
Pdefn(\scale_y, (q.x | q.y | q.z).asArray.sort.postln);

q.x = Set[1, 3, 5, 6, 10];
q.y = Set[0, 1, 5, 8, 11];
q.z = Set[0, 4, 6, 10];