       (let [metro (:metronome state)
             index (mod beat steps)
             next-beat (inc beat)]
+        (swap! state-atom assoc-in [:step] index)
         (doseq [inst instruments]
           (when (nth (get-in state [:rows (:name inst)]) index)
             (at (metro beat) (inst))))

(ns overtone.gui.sequencer
  (:use [overtone.sc server]
        [overtone.music time]
        [seesaw core mig])
  (:require [seesaw.bind :as bind]))

(defn- make-initial-state [metro steps instruments]
  {:playing?  false 
   :metronome metro
   :rows      (into 
                {}
                (for [i instruments]

                                        [:fill-h 5]
                                        "bpm"])
          seq-pane     (mig-panel :constraints [(str "wrap " (inc steps)) "" ""]
                                  :items (concat
                                           [["step" "gap 5px, gapright 10px"]]
                                           (for [lbl step-lbls] [lbl "width 25:25:25"])
                                           (mapcat #(step-row % steps state-atom) instruments)))
          f (frame :title    "Sequencer"
                   :content  (border-panel :north control-pane :center seq-pane)
                   :on-close :dispose)]
      (bind/bind bpm-spinner (bind/b-do [v] (metro :bpm v)))
      (bind/bind
        state-atom
        (bind/b-do [{:keys [step]}]
                   (config! step-lbls :opaque? false)
                   (config! (step-lbls step) :opaque? true)
                   (repaint! step-lbls)))
      (listen play-btn :action
              (fn [e]
                (let [playing? (:playing? (swap! state-atom toggle-playing))] 
