Iteration and Pattterns

hey, could this routine easily be rewritten with Pdef / Pbind or Pdef / Pmono?
Im not sure about the iteration and the wait times and what the pattern aequivalent would be when there is one. is the iteration needed when using patterns? thanks

(
r = Routine({
	loop {
		15.do{|i|
			Synth(\resonator,
				[
					\atk, rrand(0.1, 2.0),
					\sus, rrand(0.5, 2.0),
					\rel, exprand(2.0, 6.0),
					\c1, exprand(1,8),
					\c2, exprand(-8,-1),

					\sndBuf, [
						~samples[\icebell_long].choose,
						~samples[\tamtam_shimmer].choose
					].choose,

					\rate, rrand(0.95, 1.05),

					\amp, exprand(0.08, 0.18),
					\pan, rrand(-0.9, 0.9),
					\spos, rrand(0, 10000),

					\dec, exprand(0.08, 0.18),

					\out, i.wrap(0,1),
				],
				~mainGrp
			);

			rrand(0.2, 0.4).wait;
		};

		rrand(2.0, 3.0).wait;
	};
}).play(t, quant:1);
)

Does this come close? (It’s a bit difficult to test with partial code only)

(
Pbind(
	\instrument, \resonator,
	\atk, Pfunc { rrand(0.1, 2.0) },
	\sus, Pfunc { rrand(0.5, 2.0) },
	\rel, Pfunc { exprand(2.0, 6.0) },
	\c1, Pfunc { exprand(1,8) },
	\c2, Pfunc { exprand(-8,-1) },
	\sndBuf, Pseq([
		Prand(~samples[\icebell_long] ++ ~samples[\tamtam_shimmer], 15),
		Pseq([Rest(1)], 1)
	], inf),
	\dur, Pseq([
		Pfuncn({ rrand(0.2, 0.4)}, 15),
		Pfuncn({ rrand(2.0, 3.0)} , 1)
	], inf),
	\rate, Pfunc { rrand(0.95, 1.05) },
	\amp, Pfunc { exprand(0.08, 0.18) },
	\pan, Pfunc { rrand(-0.9, 0.9) },
	\spos, Pfunc { rrand(0, 10000) },
	\dec, Pfunc {exprand(0.08, 0.18)},
	\group, ~mainGrp,
	\out, Pseq([0,1], inf),
).play(t, quant:1);
)

shiihs version is good, but can be made a bit more pattern-idiomatic (e.g. Pfunc { rrand(x, y) } == Pwhite(x, y)).

(
Pbind(
	\instrument, \resonator,
	\atk, Pwhite(0.1, 2.0),
	\sus, Pwhite(0.5, 2.0),
	\rel, Pexprand(2.0, 6.0),
	\c1, Pexprand(1, 8),
	\c2, Pexprand(-8, -1),
	\sndBuf, Pseq([
		// actually this doesn't work
		// unless ~samples is an array-of-arrays
		Prand(~samples[\icebell_long] ++ ~samples[\tamtam_shimmer], 15),
		Pseq([Rest(1)], 1)
	], inf),
	\dur, Pseq([
		Pwhite(0.2, 0.4, 15),
		Pwhite(2.0, 3.0, 1)
	], inf),
	\rate, Pwhite(0.95, 1.05),
	\amp, Pexprand(0.08, 0.18),
	\pan, Pwhite(-0.9, 0.9),
	\spos, Pwhite(0, 10000),
	\dec, Pexprand(0.08, 0.18),
	\group, ~mainGrp,
	\out, Pseq([0,1], inf),
).play(t, quant:1);
)

I sometimes feel that pairing keys (sndBuf and dur) by numbers of items can be fragile. Another way is like this:

(
p = Pseq([
	Pbind(
		\instrument, \resonator,
		\atk, Pwhite(0.1, 2.0),
		\sus, Pwhite(0.5, 2.0),
		\rel, Pexprand(2.0, 6.0),
		\c1, Pexprand(1, 8),
		\c2, Pexprand(-8, -1),
			// actually this doesn't work
			// unless ~samples is an array-of-arrays
		\sndBuf, Prand(~samples[\icebell_long] ++ ~samples[\tamtam_shimmer], 15),
		\dur, Pwhite(0.2, 0.4, inf),
		\rate, Pwhite(0.95, 1.05),
		\amp, Pexprand(0.08, 0.18),
		\pan, Pwhite(-0.9, 0.9),
		\spos, Pwhite(0, 10000),
		\dec, Pexprand(0.08, 0.18),
		\group, ~mainGrp,
		\out, Pseq([0,1], inf),
	),
	Pfuncn({ Event.silent(rrand(2.0, 3.0)) }, 1)
], inf).play(t, quant:1);
)

Or, moving the flow-of-control number 15 to the top for more visibility:

(
p = Pseq([
	Pfin(15, Pbind(
		\instrument, \resonator,
		\atk, Pwhite(0.1, 2.0),
		\sus, Pwhite(0.5, 2.0),
		\rel, Pexprand(2.0, 6.0),
		\c1, Pexprand(1, 8),
		\c2, Pexprand(-8, -1),
		// actually this doesn't work
		// unless ~samples is an array-of-arrays
		\sndBuf, Prand(~samples[\icebell_long] ++ ~samples[\tamtam_shimmer], inf),
		\dur, Pwhite(0.2, 0.4, inf),
		\rate, Pwhite(0.95, 1.05),
		\amp, Pexprand(0.08, 0.18),
		\pan, Pwhite(-0.9, 0.9),
		\spos, Pwhite(0, 10000),
		\dec, Pexprand(0.08, 0.18),
		\group, ~mainGrp,
		\out, Pseq([0,1], inf),
	)),
	Pfuncn({ Event.silent(rrand(2.0, 3.0)) }, 1)
], inf).play(t, quant:1);
)

22-05-04 edited to use Pfuncn for the rests (otherwise it will repeat the rest forever, oops…).

hjh

1 Like

thank you very much, the last example is perfect.
the arrays are indeed arrays of arrays, so connecting them by ++ works fine :slight_smile: