         beat-width (/ measure-width 4)
         note-width (/ beat-width 4)
         note-height NOTE_HEIGHT
+        creating-note (atom false)
+        current-count (atom 0)
         ]
 
     (listen piano-roll

                measure (int (/ piano-roll-width MEASURE_WIDTH))]
                (swap! notes-atom (fn [old-matrix] (update-note old-matrix x-cell y-cell (if (zero? (nth (nth old-matrix x-cell) y-cell)) 1 0))))

            (update-active-notes notes-atom active-notes-atom x-cell y-cell)
            ))
      :mouse-dragged
        (fn [e])

      :mouse-released
        (fn [e] (.repaint (.getSource e))))
    panel))

(defn create-piano-roll 

          ;; paint the active notes last
          (paint-active-notes notes active-notes g note-width note-height)))

(defn update-active-notes [notes-atom active-notes-atom creating-note x-cell y-cell]
  (let [x x-cell
        y y-cell]
    (if 
      (= 1 (nth (nth @notes-atom x-cell) y-cell))
          (do
            ; (println "adding new note @" x-cell y-cell)
            ; (println @active-notes-atom)
            (swap! creating-note (fn [b] true))
            (swap! active-notes-atom (fn [notes] (conj notes [x-cell y-cell])))
            ; (println @active-notes-atom)
            )
          (do 
            ; (println "removing a note @" x-cell y-cell)
            ; (println @active-notes-atom)
            (swap! active-notes-atom (fn [notes] (remove #{[x-cell y-cell]} @active-notes-atom)))
            ; (println @active-notes-atom)
            ))))

(defn piano-roll-widget
  [num-measures num-bars num-beats num-steps-per-beat num-octaves]
  (let [notes-atom (atom (note-matrix (atom nil) num-octaves num-measures num-bars num-beats num-steps-per-beat))
        active-notes-atom (atom [])
        piano-roll (canvas  :id :piano-roll
                            :paint (partial paint-piano-roll 4 4 4 4 4 notes-atom active-notes-atom))
        panel (border-panel :center piano-roll)
