       (fn [x] (or (= 1 x) (rand-nth distribution)))
       notes)))
 
+;; --- Scales --- ;;;
+
+(defn generate-random-scale []
+  "Generate a random scale (Example - :E3 :Dorian)."
+  (let [scale-type (rand-nth (keys SCALE))
+        ninth-octave-count 131
+        note-name (find-note-name (rand-int ninth-octave-count))]
+    (scale note-name scale-type)))
+
+;; --- Measures --- ;;;
+
 (defn segment-measure [measure
                        & {:keys [running-count result note-value sparseness]
                           :or {running-count 0 result '()
                                note-value 16 sparseness 1}}]
+  "Segment a measure into beats and further segment the beats,
+  essentially breaking the measure down into sixteenth-notes."
   (if (empty? measure)
     result
     (let [result (concat result (map #(+ running-count %)

(ns tenor.constructs
  (:use [overtone.live]))

(defn make-note [notation]
  (let [notation-re #"^([A-G])([#b]?)([1-9])$"
        components (re-matches notation-re notation)]
    (if components
      (keyword (reduce str (rest components)))
      (throw (Exception. "Invalid notation")))))

(defn time-signature [note-count & [sig]]
  (cond
    (> note-count 3)
    (let [beat (rand-nth [2 3 4])

      (time-signature 0 sig))
    :else sig))

;; --- Beats --- ;;;

(defn segment-beat [note-count note-value
                    & {:keys [sparseness]
                       :or {sparseness 1}}]
  "Break a beat down into sixteenth-note positions and
  assign notes and rests to each position by iteration."
  (let [sixteenth-count (* (/ 16 note-value) note-count)
        notes (range 1 (inc sixteenth-count))
        distribution (cons true (repeat sparseness false))]
