I feel like I am forgetting some simpler way to do this, especially given how common this must be… maybe someone can help me out.
Basically I am trying to pass a continuous control from an envelope to a Synth that gets its pitches from a pattern. In the example it’s the modulation index that I’ve helpfully named “param”.
I can’t use Pbind(param: Env()) here, because that will just embed whatever value the Env has when the Event is created.
So what one needs to do is set up a bus, map to it, start the synth, then send that Pattern to the Synth with the \set type, which is what the below code does. So the problem isn’t that it doesn’t work, but rather that I suspect I’m forgetting some other obvious simpler option. Any help appreciated!
(
~voice = {|name, envdef, synthdef, patdef|
Tdef(name, {
var bus = Bus.control(s, 1);
var env = {envdef.kr(gate:1)}.play(target:s, outbus: bus);
var syn = Synth(synthdef);
syn.map(\param, bus);
Pchain(Pbind(\type, \set, \id, syn.nodeID), Pdef(patdef)).play;
}
)
};
SynthDef(\testSynth, { | out, amp, freq, param |
var sound = PMOsc.ar(freq, freq * 277/37, param) * amp;
Out.ar(out, sound);
}).add;
Pdef(\testPat,
Pfindur(20,
Pbind(
dur: Pbrown(0.5, 1.5, 0.125),
db: -15,
midinote: Pseq((60..71),inf),
)
)
);
~voice.(\testTask, Env([0,1,0], [10, 10]), \testSynth, \testPat);
Tdef(\testTask).play;
)