Realtime Spontaneous Auto Fade
I'm trying to figure out a way to fade out the audio on a track spontaneously and in real time during playback.
I searched the form a while back and discovered a thread that I cannot find anymore about a JS plugin that could autofade when receiving a midi note. I cannot get the plugin to work and so I thought I would reach out and see if anyone can offer some help either with this plugin or any other ideas.
I copied the code below into a textedit document (on mac) and saved it as plain text. I deleted the extension and put in the proper folder for JS plugins. It shows up in the JS folder in Reaper and I see the GUI and parameters, but I can't get the midi note to trigger the fade.
Here is the code...
desc: MIDI triggered Autofade
slider1:1<0,10,0.1>Fade In Time (seconds)
slider2:1<0,20,0.1>Fade Out Time (seconds)
slider3:3<0,3,1{-inf,Fading OUT,Fading IN,0dB}>Status
//////////////////////////////////////
// Adapt this sliders to your needs //
////////////////////////////////////////////
//
slider4:60<0,127,1>MIDI Note number
slider5:1<1,16,1>MIDI channel
//
////////////////////////////////////////////
@init
fade_dir = 1;
slider3 = 3;
fade_step = 0.05;
db_min = -70;
fade_in_time = slider1 * srate * fade_step / (db_min * -1);
fade_out_time = slider2 * srate * fade_step / (db_min * -1);
fade_time_cntr = 0;
attenuation = 0;
trig_event = 0;
fade_event = 0;
@slider
fade_in_time = slider1 * srate * fade_step / (db_min * -1);
fade_out_time = slider2 * srate * fade_step / (db_min * -1);
@block
///////////////////////////////////////////////////////////////
// Please adapt the MIDI code to your needs. //
// Set trig_event = 1 if the desired event has occurred //
////////////////////////////////////////////////////////////////////////////////
//
midi_event_chn = $x90 + slider5 - 1;
midirecv(offset,msg1,msg23);
msg2 = msg23 & $xff;
msg3 = (msg23 / 256) & $xff;
(msg1 & $xFF) == midi_event_chn ? (
msg2 == slider4 ? (
msg3 > 0 ? trig_event = 1;
);
);
//
////////////////////////////////////////////////////////////////////////////////
trig_event != 0 ? (
trig_event = 0;
fade_event = 1;
fade_dir *= -1;
fade_time_cntr = fade_in_time;
fade_dir == -1 ? fade_time_cntr = fade_out_time;
);
@sample
fade_event == 1 ? (
fade_dir == -1 ? (
fade_time_cntr -= 1;
fade_time_cntr <= 0 ? (
fade_time_cntr = fade_out_time;
attenuation -= fade_step;
attenuation <= db_min ? (
attenuation = db_min;
fade_event = 0;
slider3 = 0;
) : slider3 = 1;
);
)
:
(
fade_time_cntr -= 1;
fade_time_cntr <= 0 ? (
fade_time_cntr = fade_in_time;
attenuation += fade_step;
attenuation >= 0 ? (
attenuation = 0;
fade_event = 0;
slider3 = 3;
) : slider3 = 2;
);
);
);
spl0 *= 10^(attenuation/20);
spl1 *= 10^(attenuation/20);
Thanks!!!!
|