 (defmacro defcounter [counter-name start-id]
   (let [next-fn (symbol (str "next-" (name counter-name) "-id"))]
     `(do
-       (dosync 
+       (dosync
          (alter *counters assoc ~counter-name (ref ~start-id))
          (alter *counter-defaults assoc ~counter-name ~start-id))
-       (defn ~next-fn [] 
-         (dec 
+       (defn ~next-fn []
+         (dec
            (dosync (alter (~counter-name @*counters) inc)))))))
 
 (defn reset-id-counters []
   (doseq [[cname counter] @*counters]
-    (dosync 
+    (dosync
     (ref-set counter (cname @*counter-defaults)))))
 
 (defcounter :group START-GROUP-ID)


(defn- boot-thread [cmd]
  (reset! running?* true)
  (let [proc (.exec (Runtime/getRuntime) cmd) 
        in-stream (BufferedInputStream. (.getInputStream proc))
        err-stream (BufferedInputStream. (.getErrorStream proc))
        read-buf (make-array Byte/TYPE 256)]

    (let [tree (:args (osc-recv @server* "/g_queryTree.reply" REPLY-TIMEOUT))]
      (parse-node-tree tree))))

(defn prepend-node
  "Add a node to the end of a group list."
  [g n]
  (snd "/g_head" g n))

(defn append-node
  "Add a node to the end of a group list."
  [g n]
  (snd "/g_tail" g n))

(defn group-clear
  "Free all child synth nodes in a group."
  [group-id]
  (snd "/g_freeAll" group-id))

(defn clear-msg-queue
  "Remove any scheduled OSC messages from the run queue."
  []
  (snd "/clearSched"))
