[code feedback] - tweak grischa lingberg style composition out of samples

Heyho

I want to do the following with:
- a single ~buffer variable with four buffers in an array
- a single synthdef accepting buffers as a parameter
- a single patter allocating the four samples correctly out of a single synthdef allocation
- changing the patter in real time while keep playing and keep everything sync listening to the music properly

looking forwards, kind regards

T.

// raster noton - mit Samples

(

s.waitForBoot {
	var make_pat, pat;
	var buffer1,buffer2;

	~buffers=[
		Buffer.read(s, "/media/tmm88/2ED5-246E/grischaL1.wav"),
		Buffer.read(s, "/media/tmm88/2ED5-246E/grischaL2.wav"),
		Buffer.read(s, "/media/tmm88/2ED5-246E/grischaL3.wav"),
		Buffer.read(s, "/media/tmm88/2ED5-246E/grischaL4.wav")
	];

	SynthDef(\raster, {arg out = 0, amp = 1, bufnum;
		var osc = PlayBuf.ar(2, bufnum, doneAction:2);
		var env = EnvGen.kr(Env.perc, doneAction: Done.freeSelf);
		Out.ar(out, Pan2.ar(osc+FreeVerb.ar(osc)) * env * amp);
	}).add;

	s.sync;

	TempoClock.default.tempo = 164/60;

	make_pat = {
		| instr_name |
		Pxrand([
			Pbind(
				\instrument, instr_name,
				\dur, Pseq([0.75, 0.25, 0.25, 0.25, 0.5], 1),
				\legato, Pseq([0.9, 0.3, 0.3, 0.3, 0.3], 1),
				\amp, 1, \detune, 1.005
			),

			Pmono(instr_name,
				\dur, Pseq([0.25, 0.25, 0.5], 1),
				\amp, 1, \detune, 1.005
			),

			Pmono(instr_name,
				\dur, Pseq([0.25, 0.25, 0.25, 0.75], 1),
				\amp, 1, \detune, 1.005
			),

			Pmono(instr_name,
				\dur, Pseq([0.25, 0.5, 0.25, 0.5], 1),
				\amp, 1, \detune, 1.005
			)

		], inf)
	};

	pat = Ppar([
		make_pat.(\raster, \bufnum, ~buffers[0]),
		make_pat.(\raster, \bufnum, ~buffers[1]),
		make_pat.(\raster, \bufnum, ~buffers[2]),
		make_pat.(\raster, \bufnum, ~buffers[3])
	], inf);

	fork {
		wait(thisThread.clock.elapsedBeats - thisThread.clock.beats); // needed if you create many and large patterns to avoid losing the first notes
		~player = pat.play(quant:1);
	};
}

)

your make_pat function takes a single argument - instr_name.

but when you call .value on it inside your ppar you give 3 arguments!

also have a look at the .collect method in the help for Array to see how to efficiently create arrays from others. ~buffers.collect{ | i | make_pat.(\raster , \bufnum , i )) will generate the array inside your Ppar (still won’t work until you sort your function args!)

cheers

bufPaths = (1..4).collect {|n| "/media/tmm88/2ED5-246E/grischaL%.wav".format(n) };

(
Pdef(\sequence, Pxrand([
	Pbind(
		\instrument, \playBuf,
		\dur, Pseq([0.75, 0.25, 0.25, 0.25, 0.5], 1),
		\legato, Pseq([0.9, 0.3, 0.3, 0.3, 0.3], 1),
		\amp, 1, \detune, 1.005
	),

	Pbind(
		\instrument, \playBuf,
		\dur, Pseq([0.25, 0.25, 0.5], 1),
		\amp, 1, \detune, 1.005
	),

	Pbind(
		\instrument, \playBuf,
		\dur, Pseq([0.25, 0.25, 0.25, 0.75], 1),
		\amp, 1, \detune, 1.005
	),

	Pbind(
		\instrument, \playBuf,
		\dur, Pseq([0.25, 0.5, 0.25, 0.5], 1),
		\amp, 1, \detune, 1.005
	)
], inf))
)

(

s.waitForBoot {
	~rasterBufs = ~bufPaths.collect(Buffer.read(s,_));

	SynthDef(\playBuf, {arg out = 0, amp = 1, buf = 0;
		var osc = PlayBuf.ar(2, buf);
		var env = EnvGen.kr(Env.perc, doneAction: Done.freeSelf);
		Out.ar(out, Pan2.ar(osc) * env * amp);
	}).add;

	SynthDef(\freeverb) { |out=0, wet=0.5|
		var in = Mix(In.ar(out, 2));
		ReplaceOut.ar(out, FreeVerb.ar(in, wet)!2)
	}.add;

	s.sync;

	TempoClock.default.tempo = 164/60;

	~pat = Pfx(
		Ppar(~rasterBufs.collect{|buf| Pbind(\buf, buf) <> Pdef(\sequence) }),
		//\freeverb, \mix, 0.2
	);
	fork {
		wait(thisThread.clock.elapsedBeats - thisThread.clock.beats); // needed if you create many and large patterns to avoid losing the first notes
		~player = ~pat.play(quant:1);
	};
}

)

here is my attempt to fix this with the help of an italian friend from the supercollider user group meetup from denmark