                                         v)]
                         (assoc new-scopes k new-scope)))
                     {}
-                    @scopes*))))
+                    @scopes*))
+   (scopes-start)))
+
 
 (on-deps #{:synthdefs-loaded :scope-group-created} ::reset-scopes reset-scopes)
-
+(on-sync-event :shutdown ::stop-scopes scopes-stop)
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Testing

     (start-scopes-runner)
     (ref-set scopes-running?* true))))

(defn scopes-stop
  []
  (dosync
   (stop-and-reset-pool! scope-pool*)
   (ref-set scopes-running?* false)))

(defn- start-bus-synth


(defn- mk-scope
  [num kind keep-on-top width height]
  (let [id    (uuid)
        name  (str kind ": " num)
        panel (scope-panel id width height)
        frame (scope-frame panel name keep-on-top width height)
        x-array (int-array width)
        y-a     (int-array width)
        y-b     (int-array width)
        scope {:id id
               :name name
               :size 0
               :num num
               :panel panel
               :kind kind
               :color (Color. 0 130 226)
               :background (Color. 50 50 50)
               :frame frame
               :width width
               :height height
               :x-array x-array
               :y-arrays (atom [y-a y-b])}

        _ (reset-data-arrays scope)]

    (case kind
          :bus (scope-bus scope)
          :buf (scope-buf scope))))
