# Combining Pfunc and Pswitch?

Hello I’d like to have a Pattern, Pswitch, which depends on an array, here ~a, which whenever it gets changed, the Pswitch should adapt to this. Usually one could do it with Pfunc. It would look like this:

``````~a = [1,0,1];
(
Pbind(
\dur, 0.3,
\amp, 0.15 * Pswitch(~a,Pseries(0,1)).trace,
).play;
)
//changing this should change the rhythm, similiar to Pfunc
~a = [1,0,0];
~a = [1,0,1];
``````

I mean after all, one could do it like this, but i feel like i’d prefere a solution in the upper style:

``````(
Pbind(
\dur, 0.3,
\amp_helper, Pseq([0,1,2],inf),
\amp, Pfunc{|e| ~a[e[\amp_helper]]},
).play;
)
~a = [1,0,0];
~a = [1,0,1];
``````

I’m glad for any hints. thank you!

I mean the main question is, is there a way to put a Pseq into a Pfunc? Or a way for put a Pfunc into the Pswitch?

Pfunc is expected to return a value, not a pattern so you cannot let it return a Pseq.
You are looking for Plazy instead.

``````~a = [1,0,1];
(
Pbind(
\dur, 0.3,
\amp, 0.15 * Pn(Plazy({Pseq(~a, 1)}), inf),
).play;
)
//changing this should change the rhythm, similiar to Pfunc
~a = [1,0,0];
~a = [1,0,1];
``````
1 Like

Yes thats it!! I wish it would’ve been refered on the Pfunc help page. Anyhow Thank you very much!!

1 Like