The Pattern Cookbook discusses triggering patterns using MIDI: https://doc.sccode.org/Tutorials/A-Practical-Guide/PG_Cookbook03_External_Control.html
However I need to sequentially trigger different versions of a Pbind/Pbinddef pattern (each sharing the same name). Thus far when doing this manually i simply “⌘+enter” to execute each iteration of the pattern.
That’s fine if live coding with the computer in front of me. But I need to trigger different iterations from a MIDI controllers various softkeys. How do I associate a particular Pbind section such that i can play different iterations that share the same name?
Different Pbindefs can’t have the same name by definition. If you need several versions of such a pattern, you should use the unnamed variant PbindProxy.
You can draw it out of the Pbindef (or Pdef with the same name, which is identical) as follows: pat = Pbindef(\x).source. All these versions of pat you can then keep in an array, maybe under the key in a dictionary:
~versions = IdentityDictionary.new;
~saveVersion = { |key|
var pat = Pdef(key).source;
~versions[key] = ~versions[key].add(pat)
};
~loadVersion = { |key, index|
var versions = ~versions[key];
index = index ?? { versions.lastIndex };
Pdef(key, versions.wrapAt(index))
};
I think I’ve figured it out. I simply throw the different Pbinds with the same name into functions, assign these to variables, and then call .value on them using a MIDIdef.cc. It only dawned on me to use a pbind in a function when i was looking at cuePlayer which is basically what i meant by “iterations” (iterations = cue).