Ive been trying to think about how to conditionally switch between an array Pbinds/Pdefs in a sequence. This simple approach works quite well, by putting each one in a Ppar and setting the event to Rest if it doesn’t match the index
(
~pChainSwitch = {|patt, switch|
var patternList = List.new;
patt.do({|elem, i|
patternList.add(
Pbind(
\switch, switch,
\switchIdx, i,
\dur, Pfunc({|ev|
var val;
if(ev[\switchIdx] == ev[\switch]){ val = ev[\dur]}{ val = Rest(ev[\dur]) };
val
})
)
<> elem
);
});
Ppar(patternList, inf);
};
a = Pbind(\instrument, \default, \dur, 1);
b = Pbind(\instrument, \default, \degree, Prand([1,3,4,5], inf), \octave, 4, \dur, 0.5);
c = Pbind(\instrument, \default, \degree, Prand([2,5,7,8], inf), \octave, 6, \dur, 1);
~pChainSwitch.([a, b, c], Pseq([1, 0, 1, 2], inf)).trace.play(t);
)
However, I’d like to be able to do something like:
Pdef(\p1,
~pChainSwitch.([a, b, c], Pkey(\seq), inf))
<> Pbind(\seq, Pseq([1, 0, 1, 2], inf)
).trace.play(t);
…and set the the index from a key downstream. I think I can see why it doesn’t work but I’m not sure how to change the design to allow for this - any ideas?