Thank you both of you for taking the time for that. Shiihs, your code works perfectly but the workflow is kind of the same that updating the values directly on the SynthDef and recompile it while it s running. The only way I found to be able to play with “different prepared presets” using your code was: I declare environemental variables for each args and use them inside the MIDIdef function: like
if (synth.notNil) {
synth.set(\arg1, ~valuearg1);
synth.set(\arg2, ~valuearg2);
And then I can create different blocks outside the SynthDef and the MIDIDef functions like
(
~valuearg1= 3;
~valuearg2= 0.5;
)
So this way I can run each block (preset) on the fly, and change a bunch of values in a one shot, whithout adding new notes, while the synth is running ie “presets” in Max/Msp.
But I feel it’s stupid, heavy and not elegant. How would you do?
Jamshark70, thanks for this discovery of variants, it’s really minimal and convenient but I didn’t manage to implement it with the MIDIdef.noteOn. When I use Pdef/Pbind, it does exactly what I want:
(
~presets = (
a: [freq: 200, ffreq: 1000, rq: 0.1],
b: [freq: 60, ffreq: 200, rq: 0.5],
c: [freq: 60, ffreq: 8000, rq: 0.05],
d: [freq: 120, ffreq: 1600, rq: 0.2]
);
SynthDef(\variant, { |out, gate = 1, freq = 440, ffreq = 2000, rq = 1, amp = 0.1|
var sig = Saw.ar(freq),
eg = EnvGen.kr(Env.adsr, gate, doneAction: 2);
sig = RLPF.ar(sig, ffreq, rq);
Out.ar(out, (sig * (amp * eg)).dup);
}, variants: ~presets).add;
)
(
Pdef(\test, Pbind( \instrument, \variant,
\freq, Pseq([62, 64, 67, 69, 71, 74], inf).midicps,
\dur, Pseq([0.25, 0.5, 0.25, 0.25, 0.5, 0.5], inf)
));
)
a = Pdef(\test).play;
a.set(* ~presets[\c]);
a.set(* ~presets[\a]);
Updating values while it’s running the Pseq sequence, I would like the same with the polyphonic result of MIDIdef.noteOn…I tried hard.
By the way is it possible to implement the MIDIFunc.noteOn incoming value into the \freq arg of this Pbind?