s.boot;
SynthDescLib.global.read;

// 1. Simple pattern

(
p = Pbind(
	\degree, Pseq((0..7), inf),
	\delta, 0.25,
	\sustain, 0.2,
	\db, -30
).play;
)

p.stop;

// 2. Pattern in a process prototype

(
Proto({
	~event = Event.default;
	~asPattern = {
		Pbind(
			\degree, Pseq((0..7), inf),
			\delta, 0.25,
			\sustain, 0.2,
			\db, -30
		)
	};
}) => PR(\cmaj);
)

PR(\cmaj) => BP(\cmaj);
BP(\cmaj).play;

BP(\cmaj).stop;

BP(\cmaj).free;

// 3. Pattern with variable streams

(
PR(\abstractProcess).clone({
		// create component streams
	~prep = {
		~degree = Pseq((0..7), inf);
		~delta = 0.25;
		~sus = 0.2;
		~db = -30;
	};

		// use them in a pattern
	~asPattern = {
		Pbind(
			\degree, BPStream(\degree),
			\delta, BPStream(\delta),
			\sustain, BPStream(\sus),
			\db, BPStream(\db)
		)
	};
}) => PR(\cmaj2);
)

PR(\cmaj2) => BP(\cmaj);

BP(\cmaj).play;

Pbrown(0, 7, 2, inf) =>.degree BP(\cmaj);
Prand([0.25, Pseq([0.5, 0.25], 1), Pseq([0.25, 0.125], 1)], inf) =>.delta BP(\cmaj);
// make up your own for sus and db

BP(\cmaj).stop;
BP(\cmaj).free;

// 4. Prototype with parameters

(
TempoClock.default.tempo = 2.1366279069767;

PR(\bufPerc).chuck(BP(\kik), parms: (
	bufPaths: ["sounds/a11wlk01-44_1.aiff"],
	bufCoords: [[18000, 1632]] * 4,
	amps: [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
	rates: [0.5]
));
)

BP(\kik).play;

(
PR(\bufPerc).chuck(BP(\snare), parms: (
	bufPaths: ["sounds/a11wlk01-44_1.aiff"],
	bufCoords: [[3816, 816]] * 4,
	amps: [0, 0, 0, 0, 1, 0, 0, 0.7, 0, 0, 0, 0, 1, 0, 0, 0],
	rates: [1.6]
));
)

BP(\snare).play;

// snare isn't loud enough, so increase its MixerChannel level
BP(\snare).chan.level = 1.7;

(
PR(\bufPerc).chuck(BP(\hh), parms: (
	bufPaths: "sounds/a11wlk01-44_1.aiff" ! 2,
	bufCoords: [[19968, 3288], [1104, 2640]] * 4,
	amps: [0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0],
	bufs: { 2.rand } ! 4
));
)

BP(\hh).play;

(
PR(\break).chuck(BP(\break), parms: (
	bufPaths: ["sounds/a11wlk01-44_1.aiff"],
	segStart: [[2712, 7872, 13032, 18192]] * 4,
	start: [0, 1, 2, 3],
	amps: [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
	inChannels: 2,
	def: \bufGrainPan
));
)

BP(\break).play;

(
BP(\break).pbindPreAction = {
	~start = ~start.scramble;
};
)

(
BP(\break).pbindPreAction = {
	~amps = { 0.4.coin.binaryValue } ! 16;
	~start = Array.new(16);
	~amps.do({ |amp|
		(amp > 0).if({ ~start.add(4.rand) });
	});
};
)

(
BP(\break).pbindPreAction = {
	~amps = { 0.4.coin.binaryValue } ! 16;
	~start = Array.new(16);
	~rates = Array.new(16);
	~amps.do({ |amp|
		(amp > 0).if({
			~start.add(4.rand);
			~rates.add(#[0.5, 1.0, 2.0].wchoose(#[0.2, 0.7, 0.1]));
		});
	});
};
)

BP(\break).argPairs = [\pan, Pwhite(-1, 1, inf)];

// you can experiment and replace rhythm patterns here

BP(#[break, hh, snare, kik]).stop;

// release all resources
BP(#[break, hh, snare, kik]).free;