hi keno,
considering context here, i assume that by changing a single key in your Pdef, you mean modulating it in response to MIDI data.
you can’t change a key in Pbind after it’s been created and started playing. when you write e.g. \dur, 0.1 in a Pbind, that \dur will always be 0.1 — it can’t be changed externally. instead, you can plug special patterns into keys so that you can modulate the parameters you want.
the quickest way in the context of a Pbind is to use Pfuncn, which executes a function over and over again. in this case we write a function which repeatedly returns the value of a variable. changing that variable modulates the parameter in the Pbind:
var dur = 1.0;
Pbind(*[
instrument: \synth,
dur: Pfuncn({ dur }, inf)
]).play;
// now setting 'dur' modulates the \dur key. example:
MIDIdef.cc(\dur, { |val, num, chan, src|
dur = val.linlin(0, 255, 1.0, 3.0);
}, 14);
this is convenient enough when you only have one parameter to deal with, but it gets out of hand when you have 20 of them. for a more scalable approach, i would lump all modulatable keys into a single big event that you can modify at will. use Pfuncn to return it repeatedly and ensure you’re getting the latest updates, and then use Pbindf to supply additional keys.
var baseEvent;
baseEvent = (
dur: 1.0,
freq: 440,
amp: 0.1
);
Pbindf(Pfuncn({ baseEvent }, inf), *[
instrument: \pad,
filterfreq: Pexprand(1000, 8000, inf)
]).play;
// now setting baseEvent[\dur] modulates the \dur key. example:
MIDIdef.cc(\dur, { |val, num, chan, src|
baseEvent[\dur] = val.linlin(0, 255, 1.0, 3.0);
}, 14);
an important limitation is that this will not modulate parameters continuously — parameters are only read at the beginning of each note. the patterns system is a discrete sequencer and doesn’t really have a conception of continuously running control signals. if you do want continuous modulation, let me know and i can describe how to do that instead. (my solution involves instantiating all synths inside a Group and calling .set on that Group, which automatically broadcasts parameter modulations to the synths.)