 
 (def track
   (->>
-    (champernowne/word 10 410033073307230713083309)
-    (encode {:dux 0 :comes 0}) 
+    (champernowne/word 10 4100410033073307230713083309)
+    (encode {:dux 0 :comes 0 :bass 0})
     (wherever :pitch, :pitch (comp temperament/equal scale/A scale/minor scale/lower))
     (where :time (bpm 120))
     (where :duration (bpm 120))))


(def master-volume 0.03)

; Instruments
;(defonce sweep-bus (audio-bus))
;(defonce sweepers (group "Synths connected to the sweep."))
;(defonce writers (group "Pushing onto the bus." :head sweepers))
;(defonce readers (group "Pulling from the bus." :after writers))

;(defsynth random-walk [out-bus 0 freq 0.3]
;  (out:kr out-bus (-> (lf-noise1:kr freq) (+ 1) (/ 2))))

;(defonce sweeping (random-walk writers sweep-bus))

(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]

   :duration duration
   :part part})

(defn least [m]
  (first (apply min-key second m)))

(defn max-out [m]
  (zipmap (keys m) (repeat (apply max (vals m)))) )

(defn encode [state [a b c d & digits]]
  (if (zero? (* a b))
    (encode (max-out state) digits)
    (let [part (least state)
          duration (/ a b)
          pitch (+ c d)
          time (part state)]
