 
 (def track
   (->>
-    (champernowne/word 16 0)
+    (champernowne/word 16 (rand-int 99999))
     (split-by 15)
-    (map arrange)
+    arrange
     sequentially
     (where :pitch (comp temperament/equal scale/A scale/minor))
     (where :pitch scale/lower)
-    (where :time (bpm 120))
-    (where :duration (bpm 120))))
+    (where :time (bpm 160))
+    (where :duration (bpm 160))))
 
 (comment
             

        (take n s)
        (lazy-seq (chunked-by n (drop n s)))))))

(->> (range 1 18) (chunked-by 3))

(defn split-by [n s]
  (when (seq s)
    (cons
      (take-while (partial not= n) s)
      (lazy-seq (->> s (drop-while #(not= % n)) rest (split-by n))))))

(defn encode [[duration pitch]]
  {:time 0
   :duration (/ duration 4)
   :pitch pitch})

(defn evens [[x _ & zs]]
  (when x
    (cons x (lazy-seq (evens zs)))))

(defn odds [[_ y & zs]]
  (when y
    (cons y (lazy-seq (odds zs)))))

(defn thence [[{duration :duration time :time :as a} b & cs]]
  (cond
    (nil? a) []
    (nil? b) [a]
    :otherwise (cons a (lazy-seq (thence (cons (assoc b :time (+ time duration)) cs))))))

(defn arrange [digits]
  (with
    (->> digits evens (chunked-by 2) (map encode) thence (all :part :dux))
    (->> digits odds (chunked-by 2) (map encode) thence (all :part :comes))))

(defn end [notes]
  (let [{:keys [duration time]} (or (last notes) {:time 0 :duration 0}) ]
    (+ duration time)))

(defn sequentially [[a & bs]]


(definst buzz [freq 110 vol 1.0]
  (-> (saw freq)
      (+ (sin-osc (* 0.505 freq)))
      (rlpf (* 3 440) 1/9)
      (* (env-gen (perc 0.01 0.3) :action FREE))
      (* vol master-volume)))

(definst sing [freq 110 dur 1.0 vol 1.0]
