Hi!
I’m struggling to figure out how to go about connecting MIDIdef.noteOn/Off objects to VSTPlugin UGens. I’ve managed to figure out how to play VSTPlugins with Pbinds but I would like to use incoming MIDI data instead.
The following code (ever so slightly adjusted from a tutorial of Eli’s) works fine for me when playing SynthDefs made up of regular UGens;
~notes = Array.newClear(128);
(
SynthDef.new(\tone, { |freq=440, amp=0.3, out=0|
var env = EnvGen.kr(Env.perc, doneAction:2);
var sig = LFTri.ar(freq);
sig = sig * env * amp;
Out.ar(out, sig!2);
}).add;
)
(
MIDIdef.noteOn(
\noteOnTest,
{ |vel, nn, chan, src|
[vel, nn, chan, src].postln;
~notes[nn] = Synth.new(
\tone,
[
\freq, nn.midicps,
\amp, vel.linexp(1,127,0.01,0.3),
\gate, 1,
]
);
},
chan: 0,
srcID: 1092319143
);
MIDIdef.noteOff(
\noteOffTest,
{ |vel, nn, chan, src|
[vel, nn, chan, src].postln;
~notes[nn].set(\gate, 0);
~notes[nn] = nil;
},
chan: 0,
srcID: 1092319143
);
)
And the following VSTPlugin code works totally fine when using a Pbind;
SynthDef(\vst, {
arg in=0, out=0, amp=1;
var sig;
sig = VSTPlugin.ar(nil, 2) * amp;
Out.ar(out, sig);
}).add;
~surge = VSTPluginController(Synth(\vst, [\in: 0, \out: 0]));
~surge.open("Surge XT.vst3", editor: true, verbose: true);
Pbind(
\type, \vst_midi,
\vst, ~element,
\midicmd, \noteOn,
\dur, Pwhite(0.05, 0.5, inf),
\midinote, Pseq([35], inf).trace,
\harmonic, Pexprand(1, 80, inf).round.trace,
\amp, Pkey(\harmonic).reciprocal * 0.3,
).play;
So I know that everything is working on either side, but how can I go about playing VSTPlugins with MIDIdefs?
Thanks!