I would like to be able to change the parameters of a synth while a note is holding - amount of modulation, etc. In the code below, I am trying something simple by trying to change the amplitude while holding a note. I am using a control bus so that I can change the volume while the note is holding, but it’s not working.
Something is going wrong between the bus and MIDIdef.
Thank you for any help!
MIDIIn.connectAll;
// MIDIClient.init;
(
// ~myControl = 0.5;
// A SynthDef with ADSR envelope
SynthDef(“quick2”, {arg freq = 440, amp = 0.1, gate = 1;
var snd, env;
env = Env.adsr(0.01, 0.1, 0.3, 2, amp).kr(2, gate);
snd = Saw.ar(freq: [freq, freq*1.5], mul: env);
Out.ar(0, snd)
}).add;
)
// Play it with a MIDI keyboard
(
var noteArray = Array.newClear(128); // array has one slot per possible MIDI note
MIDIdef.noteOn(\myKeyDown, {arg vel, note;
noteArray[note] = Synth(“quick2”, [\freq, note.midicps, \amp, vel.linlin(0, 127, 0, 1)]);
[“NOTE ON”, note].postln;
});
MIDIdef.noteOff(\myKeyUp, {arg vel, note;
noteArray[note].set(\gate, 0);
[“NOTE OFF”, note].postln;
});
)
~myControl = Bus.control(s,1);
x = Synth(\quick2)
x.free;
x.map(1, ~myControl.index);
x.map([\amp, ~myControl.index]);
// Synth(\quick2, [\amp, In.kr(~myControl).range(0.1, 0.7)]);
(
MIDIdef.cc(\myAmp, {
arg val, ccNum, channel;
val.postln;
~myControl = val.linlin(0, 127, 0.1, 0.7);
}, 2
);
)