 
 (native!)
 
-(def SLIDER-MAX 1000)
+(defn scale-val [[from-min from-max] [to-min to-max] v]
+  (let [from-min (double from-min)
+        from-max (double from-max)
+        to-min   (double to-min)
+        to-max   (double to-max)
+        v        (double v)]
+    (+ to-min
+     (* (/ (- v from-min)
+           (- from-max from-min))
+        (- to-max to-min)))))
 
 (defn- control-slider
-  [name init-val min-val max-val step val-atom]
-  (let [spin-model (spinner-model (double init-val)
-                                  :from (double min-val) :to (double max-val) :by (double step))
-        spinner (spinner :model spin-model)
-        scaled-init (* (/ (- init-val min-val)
-                          (double (- max-val min-val)))
-                       SLIDER-MAX)
-        slider (slider :id (keyword name) :class :synth-control-slider
-                       :value scaled-init :min 0 :max SLIDER-MAX :orientation :horizontal)
+  [name min-val max-val step val-atom]
+  (let [init-val   @val-atom
+        spin-model  (spinner-model (double init-val)
+                                   :from (double min-val) 
+                                   :to (double max-val) 
+                                   :by (double step))
+        spinner     (spinner :class :synth-control-spinner
+                             :model spin-model)
+        slider-max  (int (/ (- max-val min-val) step))
+        scaled-init (scale-val [min-val max-val] [0 slider-max] init-val)
+        slider      (slider :class :synth-control-slider
+                            :value scaled-init :min 0 :max slider-max 
+                            :orientation :horizontal)
         label  (label name)
         items  [[label "width 80:80:100"]
                 [spinner "width 80:80:80"]

                    " (e.g.  [freq {:default 80 :min 40 :max 880 :step 1}])"))
        (let [control-panes (map
                              (fn [{:keys [name default min max step value]}]
                                (control-slider name default min max step value))
                              full-params)
              cleanup       (apply juxt (map second control-panes))
              pane (mig-panel :constraints ["" "[right][center][center]" ""]

     (juxt 
       (bind/bind 
         slider
         (bind/transform (partial scale-val [0 slider-max] [min-val max-val]))
         val-atom
         (bind/transform (partial scale-val [min-val max-val] [0 slider-max]))
         ; if the value's "close enough" to the spinner, stop. Otherwise,
         ; we get infinite loops caused by rounding error.
         (bind/filter #(>= (Math/abs (- % (value slider))) 0.01))
