     (let [buffer ((<< buffers) channel)
           sample (peek buffer)]
       (pop buffer)
-      sample)))
+      sample))
+
+  (maybe-toggle-gate [this new-state]
+    (when (not= (<< state) new-state)
+      (>> state new-state)
+      (when (:trigger config)
+        ((:trigger config) new-state)))))
 
 (defn default-trigger
   [gate state])

  (add-to-rms [this channel sample])
  (calculate-rms [this channel])
  (queue-in-buffer [this channel sample])
  (dequeue-from-buffer [this channel]))

(defrecord Gate [config next buffers rms-buffers samples-held]
  w/IWorkerAudioNode
  (connect [this destination]
    (reset! next destination))

      (if (>= (calculate-rms this channel) threshold)
        (do
          (>> samples-held 0)
          (maybe-toggle-gate this :open)
          (dequeue-from-buffer this channel))
        (if (<= (<< samples-held) hold)
          (do
            (aswap! samples-held inc)
            (maybe-toggle-gate this :open)
            input-sample)
          (do
            (maybe-toggle-gate this :closed)
            0.0)))))

  (add-to-rms [this channel sample]
    (aswap! rms-buffers update channel
