<commit_before>(ns overtone.gui.control
  (:use [overtone.gui dial]
        [seesaw core mig])
  (:require [seesaw.bind :as bind]))

(native!)

(def SLIDER-MAX 1000)

(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)
        label  (label name)
        items  [[label "width 80:80:100"]
                [spinner "width 80:80:80"]
                [slider "wrap"]]]
    (bind/bind slider
               (bind/transform (fn [v]
                                 (let [val (+ min-val (* (- max-val min-val)
                                                         (/ v (double SLIDER-MAX))))]
                                   val)))
               val-atom)
    (bind/bind val-atom
               (bind/transform #(* (/ (- % min-val) (- max-val min-val)) SLIDER-MAX))
               slider)
    (bind/bind spinner val-atom)
    (bind/bind val-atom spinner)
    items))<commit_msg>Somewhat yucky fix for infinite loops in synth control bindings.<commit_after>(ns overtone.gui.control
  (:use [overtone.gui dial]
        [seesaw core mig])
  (:require [seesaw.bind :as bind]))

(native!)

(def SLIDER-MAX 1000)

(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)
        label  (label name)
        items  [[label "width 80:80:100"]
                [spinner "width 80:80:80"]
                [slider "wrap"]]]
    (bind/bind slider
               (bind/transform (fn [v]
                                 (let [val (+ min-val (* (- max-val min-val)
                                                         (/ v (double SLIDER-MAX))))]
                                   val)))
               val-atom)
    (bind/bind val-atom
               (bind/transform #(* (/ (- % min-val) (- max-val min-val)) 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))
               slider)
    (bind/bind spinner val-atom)
    (bind/bind val-atom 
               ; if the value's "close enough" to the slider, stop. Otherwise,
               ; we get infinite loops caused by rounding error.
               (bind/filter #(>= (Math/abs (- % (value spinner))) 0.01))
               spinner)
    items))
{'fraction_non_alphanumeric': 0.13014324900944835, 'fraction_numerical': 0.012800975312404754, 'mean_word_length': 1.4584269662921348, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2107523', 'n_tokens_mistral': 1005, 'n_tokens_neox': 929, 'n_words': 266}