The envelope is re-triggered if the difference between the gate of the current audio cycle and the gate of the previous audio cycle is a positive value. Example:

(in-package :scratch)

(dsp! frrr (amp gate)
  (stereo (* (envelope (make-adsr .2 .1 .5 1) gate 1 #'identity)
             (white-noise amp))))

(defun retrig (node)
  (incf (control-value node 'gate))
  (values))

SCRATCH> (set-rt-block-size 1)

SCRATCH> (rt-start)

SCRATCH> (frrr .3 1 :id 42)

SCRATCH> (set-control 42 :gate 1)   ; ignored because (- gate prev-gate) is zero

SCRATCH> (retrig 42)                ; retrig because (- gate prev-gate) is one

SCRATCH> (retrig 42)                ; idem

SCRATCH> (set-control 42 :gate 0)   ; close
SCRATCH> (retrig 42)                ; open

SCRATCH> (set-control 42 :gate 0)
SCRATCH> (free 42)

The following example shows a simple modulation of the gate:

(dsp! explosions (gain gate-base gate-freq)
  (stereo (* (tanh (* (envelope (make-adsr .001 3 .05 .8)
                                (+ gate-base
                                   (if (< (phasor gate-freq 0) .5) 1 0))
                                1 #'identity)
                      (butter-lp (bpf (fractal-noise .5 2.3) 150 .1)
                                 8000)))
             (db->linear gain))))

;; attack decay sustain (retrig) attack decay sustain (retrig) ...
SCRATCH> (explosions -10 1 1/6 :id #xF35)

;; attack decay release (retrig) attack decay release (retrig) ...
SCRATCH> (set-control #xF35 :gate-base 0)

;; attack decay (retrig) attack decay (retrig) ...
SCRATCH> (set-control #xF35 :gate-freq 1/2)

;; no attack, no decay
SCRATCH> (stop #xF35)

Sourceforge project page