Pattern variable exchange like Pkey for multiple patterns

Hello again, also got another questions to pattern.

I was wondering how it would be possible to exchange the variable of a pattern to another pattern. Similar to Pkey(\variable) within a single Pbind, just by exchanging it to another.

I try to clarify this in some code, i hope the comments make it clear:

TempoClock.tempo=1;
//b plays the same note as a, because its hard coded in it
(
l = [60,65,64,67,65,60,57,62];
a = Pbind(\dur, 1, \midinote, Pseq(l)-12).play;
b = Pbind(\dur,0.5,\midinote, Pstutter(2,Pseq(l))).play;
)
(
//now, there is no easy way to hard code it, is it possible for b to track the midi note of a?
l = [60,67,67,65,64,62,60,60];
a = Pbind(\midinote, Pseq(l)-12).play;
b = Pbind(
	\dur,Prand([Pseq([1/3],3),Pseq([1/2],2)],8),//randomized pattern
	\midinote,Pstutter(2,Pseq(l,inf)), //how to track a's midinote?
).play;
)
//i wish to make b let the same note play as a in the same time frame.

If something is unclear, maybe i can reformulate it, but basically, I want the pattern b to allways play the same note as pattern a, by some kind of information exchange from the a pattern.

Thanks for your help/reading.

[EDIT]: Changed the code formatting style

I want the pattern b to allways play the same note as pattern a, by some kind of information exchange from the a pattern.

i believe you’re after something like this…

(
l = [60,67,67,65,64,62,60,60];
a = Pbind(
	\midinote, Pseq(l)-12,
);
b = Pbindf(a,
	\dur,Prand([Pseq([1/3],3),Pseq([1/2],2)],8),//randomized pattern
	\midinote,Pstutter(2,Pkey(\midinote)).trace,
);
a.play;
b.play;
)

which can also be written like this if you prefer…

(
l = [60,67,67,65,64,62,60,60];
a = Pbind(
	\midinote, Pseq(l)-12,
);
Ppar([
	a,
	Pbindf(a,
		\dur,Prand([Pseq([1/3],3),Pseq([1/2],2)],8),//randomized pattern
		\midinote,Pstutter(2,Pkey(\midinote)).trace,
	)
]).play;
)

or perhaps like this - using a different technique…

(
l = [60,67,67,65,64,62,60,60];
a = Pbind(
	\midinote, Plet(\mynotes, Pseq(l)-12),
);
b = Pbind(
	\dur,Prand([Pseq([1/3],3),Pseq([1/2],2)],8),//randomized pattern
	\midinote, Pstutter(2,Pget(\mynotes).repeat).trace
);
Plambda(
	Ppar([a, b])
).play
)

in any case, read more in Pkey, Pbindf and Plambda helpfiles.
_f

#|
fredrikolofsson.com musicalfieldsforever.com

1 Like

Please use code formatting tags for code blocks. You’re currently using quotation blocks – they’re not the same thing.

It’s the </> formatting button in the toolbar.

This will solve the * problem that you mentioned in the other thread.

hjh

1 Like

Im not entirely sure, but i think the first two options do not work, because it converts the pattern to a stream. Since the randomized dur (duration) values, demand a repetition of the midinote, but the stream is only able to give the correct order, not the amount of repetition.
It would be interesting, if there is a way to implement this, to make it work with Pbindf, but I don’t see how.

Your third example however solves it mostly. I changed/simplified it a bit. However I feel like there might be a systematical mistake from a float issue. When the ‘a’-Pbind is running a note every 1 second, and lets say the ‘b’-Pbind does so, for every 1/3 (0.333333333) seconds. At some points they are not exactly on point anymore. I think this is why the b Pbind, might be a little bit faster than the ‘a’-Pbind, even though its not audiable. I fixxed it in the folloxing code, u need to uncomment one line in the b-Pbind, to see what i mean:

(
l = [60,67,67,65,64,62,60,60];
a = Pbind(
	\midinote, Plet(\mynotes, Pseq(l,inf)-12),
);
b = Pbind(
	\dur, 1/3, //stops working after a while
	//uncomment the next line!!!!!!
	// \dur,Pseq([0.000001,Pseq([1/3],inf)] //this works all the way
	//uncomment the previous line!!
	\midinote,12+Pget(\mynotes,repeats:inf)
);
Plambda(
	Ppar([a, b])
).play
)

Im wondering if it would be possible to quantize the b-Pbind within the Ppar, with a very tiny offset. ‘.play(quant:[0,0.0001,0])’ should’ve done the trick for the b-Pbind, but I’m not sure how to set a different offset for the quantization in the Ppar. Is that possible?

Anyhow, thank you very much, this was very helpful!!

Have a look at the data sharing chapter in the Pattern Guide

https://doc.sccode.org/Tutorials/A-Practical-Guide/PG_06g_Data_Sharing.html

For a different approach, you might try out the PTChain class. It works like Pchain - it takes a list of patterns e.g. PTChain(a, b, c), and pulls Events in reverse order, passing the Event from the previous pattern into the next one c -> b -> c. The only difference with PTChain is that each pattern runs independently according to it’s own \dur. The \durs of the first pattern control how often Events are actually played, though naturally if the first pattern is a Ppar you can have parallel streams with different durations.

Here’s a little example of something that may be like what you are looking for: one pattern of notes, playing at it’s own speed, with two other patterns pulling notes from it in a synchronized way. In my example, I have another downstream pattern running at a different speed to continuously vary the \chorus param over time.

Required classes are here: https://gist.github.com/scztt/87bf6542e3cd60844113fd201258a82a

Example
(
SynthDef(\saw, {
	var sig, env, freq, velocity, amp;
	
	velocity = \velocity.kr.poll;
	amp = \amp.kr * velocity.linlin(0, 128, 0.0, 1.0);
	
	env = Env.adsr().kr(
		gate:\gate.kr(1), 
		timeScale: velocity.linlin(0, 128, 0.4, 2),
		doneAction:2
	);

	freq = \freq.kr;
	freq = freq * (
		\chorus.kr(0.1) * [-1, 0.5, 0, 0.5, 1]
	).midiratio;
	
	sig = LFSaw.ar(freq, Rand(0, 2), amp * 0.3).sum;
	sig = BLowPass4.ar(sig, env.lincurve(0, 1, 1200, 8000, 4));
	sig = env * sig;
	
	Out.ar(\out.kr, sig ! 2)
}).add
)

(
Pdef(\parNotes, PTChain(
	Ppar([
		Pbind(
			\dur, Pseq([1, 3], inf),
			\legato, 1.1,
			\velocity, 120,
		),
		Pbind(
			\dur, 1/8,
			\legato, 2,
			\octave, Pkey(\octave) + 2,
			\degree, Pkey(\degree) + Place([0, 0, [5, 3, 5+12]], inf),
			\velocity, Pseq([50, 30, 20, 40, 30], inf)
		)
	]),
	Pbind(
		\instrument, \saw,
		\dur, 1/5,
		\octave, 3,
		\scale, Scale.chromatic,
		\degree, Pseq([0, -4, -7], inf)
	),
	Pbind(
		\dur, 1/8,
		\chorus, Pseg([0.04, 0.15, 0.04], [8, 8], repeats:inf)
	)
)).play
)