( // Kraftwerk ?, Pink Floyd ??, Tangerine Dream ???
SynthDef("blob", {
	var trig, seq, f1, f2, w, sig, amp;
	trig = Impulse.kr(11);	
	seq = Dxrand([0, 2, 5, 7, 9, 12] + 36 , inf);	
	f1 = Demand.kr(trig, 0, seq ).midicps; 
	w = Pulse.ar([f1, f1*1.01]);				 
	sig = Decay2.ar(K2A.ar(trig), 0.05, 0.2, w );	
	amp = Amplitude.kr(sig/10);				 
	f2 = SinOsc.kr(0.1, 3/2 * pi, 800, 1000);	 
	sig = RLPF.ar(sig, f2*(1+amp), 0.2, 0.01);
	Out.ar(0, sig);		 
	}).play(s);
)

// -------------------------

// Steve Reich, Piano Phases:

(// the piano pattern in a flat and direct notation (as written in the score):
var p1;
p1 = Pseq([64, 66, 71, 73, 74, 66, 64, 73, 71, 66, 74, 73], inf);
// e f# b c# d f# e c# b f# d c#

p = Pbind( 
	\midinote, p1,
	\dur, 1/8,
	\legato, 0.8
).play
)

p.stop;  // stop the EventStreamPlayer

(// the piano pattern expressed in a more structural way (L.H. + R.H., modal scale related):
var h1, h2, p1;
h1 = Pseq([1, 5, 7] - 1, inf);	
h2 = Pseq([2, 6] - 1, inf);

p1 = Pswitch1([h1, h2], Pseq([0, 1], inf));

p = Pbind( 
	\ctranspose, 2,	// chromatic transpose: D-Major (2 semitones above C-Major)
	\mtranspose, 0,	// modal transpose: 1 scale step higher, i.e. from Ionian on D to Dorian on E
	\degree, p1,		// read the degrees (scale steps) from the pattern p1
	\dur, 1/8,
	\legato, 0.8
).play
)

p.stop; 

(// two players, simplified continuous tempo shifting:
var p1;
p1 = Pseq([64, 66, 71, 73, 74, 66, 64, 73, 71, 66, 74, 73], inf);

Ppar([
	Pbind( \midinote, p1, \dur, 1/8, \legato, 0.8, \pan, -1),
	Pbind( \midinote, p1, \dur, (1/8) * 0.99, \legato, 0.8, \pan, 1),
	]
).play
)

(// two players, the true tempo shifting scheme (but abbreviated:
var p1, measures, d2;
measures = 4;
p1 = Pseq([64, 66, 71, 73, 74, 66, 64, 73, 71, 66, 74, 73], inf);
d2 = Pseq([ Pseq([1/8], 12*measures), Pseq([1/8 * (12*measures / (12*measures + 1))], 12*measures)], inf);

Ppar([
	Pbind( \midinote, p1, \dur, 1/8, \legato, 0.8, \pan, -1),
	Pbind( \midinote, p1, \dur, d2, \legato, 0.8, \pan, 1),
	]
).play
)

// ------------------------------------------------

// chords are arrays of pitches (degrees, midinotes, frequencies etc.)
(
Pbind(
	\dur, 0.8,
	\legato, 1.0,
	\instrument, \default,
	\scale, Pseq([Pseq([[0,2,4,5,7,9,11]], 5), Pseq([[0,2,3,5,7,8,10]], 5)], inf),
	\degree, Pseq([[-7, 2,4,7 ], [ -4, 3,5,7], [-3, 1,4,7], [-10, 1,4,6], [-7, 2,4,7 ] ], 2)
).play;
)

// parallel Patterns:
(
var testSequence;
testSequence = Pseq([60,62,64,65,67,69,71,72], inf); // a sequence as Pattern
Ppar([		//define a parallel pattern
	Pbind(			// "voice 1"
		\dur, 0.4, 	// duration
		\midinote, testSequence			// here a stream copy is generated
	),
	Pbind(			// "voice 2"					
		\dur, 0.3, 	// duration
		\midinote, 12 + testSequence	// here a second stream copy is generated
	)
]).play
)

// ------------------------------------------------

// using you own synthdefs and effects with patterns

(
SynthDef(\blah, { arg freq, amp, pan, gate=1;
	var eg, sig;
	eg = EnvGen.kr(Env.adsr(0.04, 0.1, 0.7, 0.1), gate, doneAction: 2);
	sig = GrayNoise.ar(eg * 60);
	sig = Resonz.ar(sig, freq, 0.0005, 4).distort;
	sig = Pan2.ar(sig, pan, eg * amp);
	Out.ar(0, sig);
}).store;

SynthDef(\simplerev, { arg decay=3;
	var sig;
	sig = In.ar(0, 2);
	6.do({ sig = AllpassN.ar(sig, 0.04, [0.01.rand + 0.02, 0.01.rand + 0.02], decay); });
	Out.ar(0, sig);
}).store;
)	

(
// Lindenmayer systems take a trip south of the border
var degdict, durdict;

// the scale degree rewrite dictionary:
degdict = IdentityDictionary[
	0 -> [0, 1, 2],
	1 -> [0, 2],
	2 -> [3, 2],
	3 -> [0, 3, \, 4],
	4 -> [5, 4, 2],
	5 -> [8, 7, 6, 7, 3],
	\ -> [\, 0, \]
];

// the duration rewrite dictionary:
durdict = IdentityDictionary[
	0.5 -> [0.25, 0.5, 0.25],
	1.0 -> [0.5, 0.125, 0.125, 0.25],
	0.25 -> [1.0, 0.5],
	0.125 -> [0.25, 0.25, 0.25]
];

p = Pbind(
		// do six levels of rewrite from a single seed value.
		\degree, Prewrite( Pseq([0]), degdict, 6) + [-7, 0, 2, 4],  
		\dur, Prewrite( Pseq([0.5]), durdict, 6),
		\pan, Pbrown(-0.7, 0.7, 0.2, inf),
		\octave, 6,
		\amp, 0.2,
		\instrument, \blah
	);
	
e = Pfx(p, \simplerev, \decay, 2);		
e.play;	
)