-(ns audio-utils.worker)
+(ns audio-utils.worker
+  (:require [audio-utils.util :as u]))
 
 ;;;; General interface for audio processing nodes in web workers
 

    (connect [this destination])
    (disconnect [this])
    (process-audio [this data]
      (let [convert? (not (array? data))]
        (.postMessage js/self (doto #js []
                                (aset "name" "main-process-audio")
                                (aset "converted?" convert?)
                                (aset "data" (cond-> data
                                               convert?
                                               clj->js))))))))

(defn main-exit-node
  [worker data-fn]
  (set! (.-onmessage worker)
        (fn [msg]
          (let [name       (aget (.-data msg) "name")
                converted? (aget (.-data msg) "converted?")
                data       (aget (.-data msg) "data")]
            (when (= name "main-process-audio")
              (when data-fn
                (data-fn (cond-> data
                           converted?
                           js->clj))))))))

                   (process-audio @next data))))]
    (set! (.-onmessage js/self)
          (fn [msg]
            (let [name         (aget (.-data msg) "name")
                  data         (aget (.-data msg) "data")]
              (js/console.log "WORKER ENTRY NODE / ONMESSAGE")
              (when (= name "worker-process-audio")
                (process-audio node data)))))
    node))

(defn worker-exit-node
