Iteration with Pmono

Hey, im trying to convert the Iteration attempt to play different soundfiles from a folder with a routine to be used with a Pmono and get the same results. Im not sure if i have to use \timingOffset or \lag or something to mimic the waittime of the routine example inside the Pmono. any ideas?

here is the code:

// Iteration with Routines

(
SynthDef(\resonator_routine, {
	arg sndBuf=0;

	var freqs = (51 + ([3, 7, 12, 14, 15, 24, 26] +.x [0, 12])).midicps *.x [1, 1.008];
	var sig, env, exc;

	env = EnvGen.ar(Env([0,1,1,0],[\atk.kr(0.01),\sus.kr(1),\rel.kr(3)],[0,\c1.kr(1),0,\c2.kr(-1)]), doneAction:2);
	exc = PlayBuf.ar(1, sndBuf, \rate.kr(1) * BufRateScale.ir(sndBuf), startPos: \spos.kr(0));
	exc = exc * -50.dbamp * env;
	exc = HPF.ar(exc, 100);

	sig = Klank.ar(`[freqs, 1 ! freqs.size, BufDur.ir(sndBuf) ! freqs.size], exc, decayscale: \dec.kr(0.18));

	sig = Pan2.ar(sig, \pan.kr(0), \amp.kr(0.25));
	Out.ar(\out.kr(0), sig);
}).add;
)

(
r = Routine({
	loop {
		15.do{|i|
			Synth(\resonator_routine,
				[
					\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[\sawblade_long].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),
				]
			);

			rrand(0.2, 0.4).wait;
		};

		rrand(2.0, 3.0).wait;
	};
}).play;
)

r.stop;

// Iteration with Pmono

(
SynthDef(\resonator_pmono, {
	arg sndBuf=0;

	var freqs = (51 + ([3, 7, 12, 14, 15, 24, 26] +.x [0, 12])).midicps *.x [1, 1.008];
	var sig, env, exc;

	env = EnvGen.ar(Env([0,0,1,1,0], [0,\atk.kr(0.01),\sus.kr(1),\rel.kr(3)], [0,\c1.kr(1),0,\c2.kr(-1)]), \trig.tr);
	exc = PlayBuf.ar(1, sndBuf, \rate.kr(1) * BufRateScale.ir(sndBuf), startPos: \spos.kr(0));
	exc = exc * -50.dbamp * env;
	exc = HPF.ar(exc, 100);

	sig = Klank.ar(`[freqs, 1 ! freqs.size, BufDur.ir(sndBuf) ! freqs.size], exc, decayscale: \dec.kr(0.18));

	sig = sig * \amp.kr(0.25);

	Out.ar(\out.kr(0), sig);
}).add;
)

(
Pdef(\resonator_pmono,
	Ppar({ |i|
		Pmono(\resonator_pmono,
			\dur, Pwhite(2.0, 3.0),

			\timingOffset, i / 2 + 0.02,

			\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, Pfunc { ~samples[\sawblade_long].choose },
			\rate, Pwhite(0.95, 1.05),

			\amp, Pexprand(0.08, 0.18),
			\spos, Pwhite(0, 10000),

			\dec, Pexprand(0.08, 0.18),
			
			\amp, 0.15,
			\out, i.wrap(0,1),
		)
	} !15 )
).play;
)

Pdef(\resonator_pmono).stop;

If it’s mono, then you’ll need to retrigger the PlayBuf, but it looks like you haven’t done this.

If it’s a regular Pbind, then retriggering happens by starting a new synth. In Pmono, there is no “start a new synth” so you have to make the retriggering explicit, with a \trig.tr(1) control.

hjh

hey thanks for your help.
the retriggering works now specifying a trig = trig.tr(1); for the PlayBuf.

In the Synth iteration example a Synth is created and a time of rrand(0.2, 0.4).wait; is waited until another Synth is created. after having iterated over all 15 Synth the waittime of rrand(2.0, 3.0).wait; is waited until the loop starts again (when im not mistaken).
could this behaviour be done with Iteration and Pmono?

the combination of \timingOffset and \dur as ive tried is not the right approach to get a waittime of rrand(2.0, 3.0).wait; after all the 15 different synth have been created.

(
SynthDef(\resonator, {
	arg sndBuf=0;
	
	var trig = \trig.tr(1);
	var freqs = (51 + ([3, 7, 12, 14, 15, 24, 26] +.x [0, 12])).midicps *.x [1, 1.008];
	var sig, env, exc;

	env = EnvGen.ar(Env([0,0,1,1,0], [0,\atk.kr(0.01),\sus.kr(1),\rel.kr(3)], [0,\c1.kr(1),0,\c2.kr(-1)]), trig);
	
	exc = PlayBuf.ar(1, sndBuf, \rate.kr(1) * BufRateScale.ir(sndBuf), trig, \spos.kr(0));
	exc = exc * -50.dbamp * env;

	sig = Klank.ar(`[freqs, 1 ! freqs.size, BufDur.ir(sndBuf) ! freqs.size], exc, decayscale: \dec.kr(0.18));

	sig = sig * \amp.kr(0.25);

	Out.ar(\out.kr(0), sig);
}).add;
)

(
Pdef(\resonator,
	Ppar({ |i|
		Pmono(\resonator,
			\dur, Pwhite(2.0, 3.0),
			//\trig, Pwhite(0.5, 1.0),

			\timingOffset, Pwhite(0.2, 0.4),
			//\lag, Pwhite(0.2, 0.4),

			\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, Pfunc { ~samples[\sawblade_long].choose },
			\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),

			\amp, 0.15,
			\out, i.wrap(0,1),
		)
	} !15 )
).play;
)