   (:use [overtone.sc.machinery allocator]
         [overtone.sc.machinery.server comms]
         [overtone.sc synth ugens defaults server node]
+        [overtone.sc.cgens.tap]
         [overtone.helpers lib]
         [overtone.sc.foundation-groups :only [foundation-monitor-group]]
         [overtone.libs.deps            :only [on-deps]])

;; but in SC they are implemented using a simple integer referenced
;; array of float values.

(defonce ^{:private true} bus-monitors* (atom {}))
(defonce ^{:private true} bus-monitor-pool (at-at/mk-pool))
(defonce ^{:private true} audio-bus-monitor-group* (atom nil))


(on-deps :foundation-groups-created ::create-monitor-group create-monitor-group)

(defonce __BUS-MONITOR-SYNTH__
  (defsynth mono-audio-bus-level [in-a-bus 0]
    (let [sig   (in:ar in-a-bus 1)
          level (amplitude sig)
          level (lag-ud level 0.1 0.3)]
      (tap "level" 20 level))))

(defn audio-bus-monitor
  "Mono bus amplitude monitor. Returns an atom containing the current
   amplitude of the audio bus. Note that this isn't the current value,
   rather it's the peak amplitude of the signal within the audio bus.

   For multi-channel buses, an offset may be specified. Current
   amplitude is updated within the returned atom every 50 ms.

   Note - only creates one monitor per audio bus - subsequent calls for
   the same audio bus idx will return a cached monitor."
