            kind (if (= -1 buf) :bus :buf)
            num  (if (= -1 buf) bus buf)
            s (mk-scope num kind keep-on-top WIDTH HEIGHT)]
-       (swap! scopes* assoc (:id s) s)
+       (dosync (alter scopes* assoc (:id s) s))
        (scopes-start))))
 
 (defn pscope
   "Creates a 'perminent' scope, i.e. one where the window is always kept on top of other OS windows. See scope."
   ([& args]
      (apply scope (concat args [:keep-on-top true]))))
+
+(defn- reset-scopes
+  "Restart scopes if they have already been running"
+  []
+  (dosync
+   (ref-set scopes*
+            (reduce (fn [new-scopes [k v]]
+                      (let [new-scope (if (= :bus (:kind v))
+                                        (scope-bus v)
+                                        v)]
+                        (assoc new-scopes k new-scope)))
+                    {}
+                    @scopes*))))
+
+(on-deps #{:synthdefs-loaded} ::reset-scopes reset-scopes)
 
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

            [clojure.set :as set]))

(def SCOPE-BUF-SIZE 4096)
(def FPS 10)
(def scopes* (atom {}))
(def scope-pool* (atom nil))
(def scopes-running?* (atom false))
(def WIDTH 600)
(def HEIGHT 400)
(def X-PADDING 5)
(def Y-PADDING 10)

(defn- update-scope [s]
  (let [{:keys [buf size width height panel y-array x-array panel]} s
        frames (buffer-data buf)
        step (int (/ (buffer-size buf) width))
        y-scale (/ (- height (* 2 Y-PADDING)) -2)
        y-shift (+ (/ height 2) Y-PADDING)]
    (dotimes [x width]
      (aset ^ints y-array x
            (int (+ y-shift
                    (* y-scale
                       (aget ^floats frames (unchecked-multiply x step)))))))
    (.repaint panel)))

(defn- update-scopes []
  (doall (map update-scope (vals @scopes*))))

(defn- paint-scope [g id]
  (if-let [scope (get @scopes* id)]

      (.drawRect ^Graphics g 0 0 width height)
      (.setColor ^Graphics g ^Color color)
      (.drawPolyline ^Graphics g ^ints x-array ^ints y-array width))))

(defn scope-panel [id width height]
  (let [panel (proxy [JPanel] [true]
