Pattern: making Pif depend on a previous pattern key

Hello everyone,
I would like to do change some keys in a pattern according to a ‘if’ condition from previously calculated keys. Let me explain this on a very simple example.

I create a simple pattern and whenever the \degree key is at 2, I want the \amp to be set to 0.3. otherwise it should be 0.1. I tried something like this, but the Pkey does not track the proper numeric value. Anybody knows how to ask the proper condition with the right syntax?
I believe the question become clear when looking at the code:

(
Pbind(
	\dur, 0.4,
	\degree, Pwhite(0,2,inf),
	\amp, Pif(Pkey(\degree)==2,0.3,0.1) //this line of code does properly ask the Pkey to be 2
).play
)

Thank you very much!

hey i think this will work:

(
Pbind(
	\dur, 0.4,
	\degree, Pwhite(0,2,inf),
	\amp, Pfunc { |e| [2].includes(e[\degree]).if { 0.3 } { 0.1 } }.trace,
).play
)
2 Likes

Pbinop('==', Pkey(\degree), 2)

There’s a new operator |==| in the development branch, but it has not been merged into the 3.x line yet (after I’d guess close to a year, still not there, I guess it has to wait until 3.12 or something). That will also fix it but it’s not available in a current release.

hjh

1 Like

Thank you very much for this implementation! I actually use this solution now for a couple of other implementations. Its truly very useful!
Finally there is a way to treat the \key of a pbind as a normal variable. quite enjoyable (:

1 Like

According to the changelog for 3.12, |==| has gone into 3.12.x. :+1:

hjh