Quantcast

Effects On/Off through MIDI

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Effects On/Off through MIDI

astro44448
Hi,

Newbie here. Trying to turn effect on and off through midi notes e.g. assigning reverb to midi note 25 and turning it off with midi note 27. So far I can trigger reverb by hitting note 25, but can't release it. Ultimately I hope to trigger and turn off an effect with the same midi, to work like a stomp box.

Here is my code. Any help would be most appreciated:
(// take in an input
SynthDef("J's Synth", { arg amp;
var input;
        input = AudioIn.ar([1,2]);
        Out.ar(0, input*amp);
                                                }
                        ).writeDefFile;
)



(
SynthDef("Reverb", { arg outbus = 0, inbus;
                var input;
                input = In.ar(inbus, 1); //inbus to be passed in from the outside as an arg

        input= FreeVerb.ar(input,0.50, 0.9)!2;//stereo

                Out.ar(outbus, input); // input is In.ar(inBus, 1)
        }).send(s);
)

(
SynthDef("Filter", { arg outbus = 0, inbus;
                var input;
                input = In.ar(inbus, 1);

        input= PitchShift.ar(input, 1.2, MouseX.kr(0, 4),0, 0.004)!2;

        Out.ar(outbus, input);
        }).send(s);
)

(
SynthDef("piano", { |out=0, freq=440, gate=1|
    var son = MdaPiano.ar(freq, gate, release: 0.9, stereo: 0.3, sustain: 0);
    DetectSilence.ar(son, 0.01, doneAction:2);
    Out.ar(out, son * 0.1);
}).add;
)




(
var keys;
keys = Array.newClear(128);

MIDIClient.init;
MIDIIn.connect(0, MIDIClient.sources.at(0));

g = Group.new;


~noteOn = {arg src, chan, num, vel;
    var node, a,b,c;
    if(num == 24, {
                node = Synth.tail(g, "J's Synth",[\freq, num.midicps, \amp, vel/255] );
        node.map();
        keys.put(num, node)
    },);
       

        if(num ==25, {
                a = Synth.tail(g, "Filter",[\freq, num.midicps, \amp, vel/255] );
        a.map();
        keys.put(num, a)
    },);

        if(num == 26, {
                b = Synth.tail(g, "Reverb",[\freq, num.midicps, \amp, vel/255] );
        b.map();
        keys.put(num, b)
    },);
       
        if(num > 35, {
                node = Synth.head(g, "piano",[\freq, num.midicps, \amp, vel/255] );
        node.map();
        keys.put(num, node)
    },);
if(num == 27, {

        node.free();
        keys.put(num, node)
    },);
if(num == 28, {

        a.free();
        keys.put(num, a)
    },);

        if(num == 29, {

        b.free();
        keys.put(num, b)
    },);
       




};






MIDIIn.addFuncTo(\noteOn, ~noteOn);

~noteOff = {arg src, chan, num, vel;
    var node;
    node = keys.at(num);
    if (node.notNil, {
        keys.put(num, nil);
        s.sendMsg("/n_set", node.nodeID, "gate", 0);
        // or node.release
        // then free it ... or get the NodeWatcher to do it
    });
};
MIDIIn.addFuncTo(\noteOff, ~noteOff);
)
MIDIIn.removeFuncFrom(\noteOn, ~noteOn);
MIDIIn.removeFuncFrom(\noteOff, ~noteOff);

s.free;
Loading...