
// MIDI triggered DADSR
// v 2.0
// by Sault
//
// cleaned a little, uses an import library, delay added


desc:MIDI-triggered DADSR

slider1:0<0,15,1>MIDI channel (0 = all)
slider2:0<0,1000,1>Delay (ms)
slider3:1<1,1000,1>Attack (ms)
slider4:50<1,500,1>Decay (ms)
slider5:-9<-90,0,1>Sustain (dB)
slider6:50<1,1000,1>Release (ms)
slider7:0<0,1,1{off,on}>Velocity-sensitive

import st.dadsr.jsfx-inc


@init

dadsr.dadsr_init(slider2,slider3,slider4,slider5,slider6);

@block

while (
 midirecv(ts,msg1,msg23) ? (
  m = msg1 & 240;
  channel = msg1 & $x0F;
  vel = (msg23/256) | 0;
  vol = vel/127;

  ((slider1 == 0) || (channel == slider3)) ? (

   ((m == 9*16) && (vol > 0)) ? (
	val = 1;
	slider7 ? val = vol;
	dadsr.dadsr_scale(val);
	dadsr.dadsr_trigger();
     ); // noteon?

   ((m == 8*16) || ((m == 9*16) && (vol == 0)) ?
	dadsr.dadsr_release();
     );

   ); // checking against MIDI channel or allow all

  midisend(ts,msg1,msg23);
  ); // midirecv

); // while

@slider

  dadsr.dadsr_update(slider2,slider3,slider4,slider5,slider6);


@sample

  dadsr.dadsr_process();

  spl0 *= dadsr.env;
  spl1 *= dadsr.env;
