Hi guys,
I’ trying to understand if is there a way for providing continuous control to synths instantiated by a Pbindef
the same way I normally do using the .map
method (or .asMap
) when manually instantiating a synth.
Here’s a code example for the “manual” case:
// 1. define a test synth
(
SynthDef(\test, {
|
atk=0.01,rls=1,amp=1,freq=440,out=0,gate = 1.0
|
var sig = 0, env;
env = EnvGen.kr(Env.asr(atk, 1.0, rls),gate, doneAction:2);
sig = SinOsc.ar(freq) * env * amp;
Out.ar(out, sig);
}).add;
)
// 2. set an utility environment variable to store the amplitude value
~amp = 0.0;
// 3. create a control bus to be used to control the amplitude of the synth
b = Bus.control(s,1);
// 4. initialize the bus value
b.set(~amp);
// 5. if you want you can look at the control value via its scope
b.scope;
// 6. then define a midi func to bind a MIDI CC to the bus
(
k = MIDIFunc.cc({
arg ...args;
~amp = args[0].linlin(0,127,0.0, 1.0);
b.set(~amp);
},0);
)
// 7. create the synth instance
// Note we are "mapping" the bus as a continuous control the the amp argument of the synth
x = Synth(\test, [\freq,440,\amp, b.asMap]);
// 8. now you can play with the MIDI controller to change the amplitude of the synth
// 9. eventually you can:
x.set(\gate, 0); // free the synth when done
k.free; // free the midi func
b.free; // free the bus
Now how to do something similar when using Pbindef
?
I’m used to take advantage of Pfunc
but this is not gonna doing the job.
I would like to have something capable of changing constantly some argument
of the instantiated synths (not only at evaluation time say).
Can it be possible?
(
Pbindef(\pbindef_test,
\instrument, \test,
\octave, 5,
\degree, Prand((0..7), inf),
\dur, Prand((1..4)/4, inf),
\amp, Pfunc({ ~amp }), // it is not working the way i like
\amp, Pmap({ b }), // does something like this exists?
).quant_(4).play;
)
Pbindef(\pbindef_test).stop;
Thank you very much for your support, hope my question can be useful also for someone else