   (* freq (java.lang.Math/pow 2 (/ n-cents 1200))))
 
 ;; MIDI
-(def midi-range (range 128))
-(def middle-C 60)
+(def MIDI-RANGE (range 128))
+(def MIDDLE-C 60)
 
 ;; Manipulating pitch using midi note numbers
 

            (conj result (get phrase (first notes))))
     result)))

; Making MIDI note numbers nicer to look at...
(def NOTE {:C  0  :c  0
           :C# 1  :c# 1  :Db 1  :db 1
           :D  2  :d  2

            (list base)
            (take (* 8 12) (cycle intervals)))))))

(defn nth-interval
  "Return the count of semitones for the nth degree from the start of the diatonic scale in the specifiec mode (or ionian/major by default).
     i.e. the ionian/major scale has an interval sequence of 2 2 1 2 2 2 1
          therefore the 4th degree is (+ 2 2 1 2) semitones from the start of the scale."
  ([n] (nth-interval :ionian n))
  ([scale n]
     (reduce + (take n (cycle (scale SCALE))))))

(def DEGREE {:i   1
             :ii  2
             :iii 3
             :iv  4
             :v   5
             :vi  6
             :vii 7})

(defn degree->interval
  "Converts the degree of a scale given as a roman numeral keyword or integer and converts it to the number
   of intervals (semitones) from the tonic of the specified scale."
  [scale degree]
  (if-let [deg (DEGREE degree)]
    (nth-interval scale (dec deg))
    (nth-interval scale (dec degree))))

(def CHORD
  (let [major  [0 4 7]
        minor  [0 3 7]
        major7 [0 4 7 11]
        dom7   [0 4 7 10]
        minor7 [0 3 7 10]
        aug    [0 4 8]
        dim    [0 3 6]
        dim7   [0 3 6 9]]
    {:major      major
     :M          major
     :minor      minor
     :m          minor
     :major7     major7
     :dom7       dom7
     :7          dom7
     :M7         major7
     :minor7     minor7
     :m7         minor7
     :augmented  aug
     :a          aug
     :diminished dim
     :dim        dim
     :i          dim
     :diminished7 dim7
     :dim7       dim7
     :i7         dim7}))

(defn chord
  "Returns a set of notes for the specified chord at the specified octave (defaulting to 4).
  (chord :c :major)  ; c major           -> #{60 64 67}
  (chord :a :minor 3); a minor           -> #{57 60 64}
  (chord :Bb :dim)   ; b flat diminished -> #{70 73 76}
  "
  ([root chord-name] (chord root chord-name 4))
  ([root chord-name octave]
     (let [root (if (keyword? root) (NOTE root) root)
           chord-name (if (keyword? chord-name) (CHORD chord-name) chord-name)
           base (octave-note octave root)]
       (set (map #(+ % base) chord-name)))))

; midicps
(defn midi->hz
  "Convert a midi note number to a frequency in hz."
  [note]
  (* 440.0 (java.lang.Math/pow 2.0 (/ (- note 69.0) 12.0))))

; cpsmidi
(defn hz->midi
  "Convert from a frequency to the nearest midi note number."
  [freq]
  (java.lang.Math/round (+ 69
                 (* 12
                    (/ (java.lang.Math/log (* freq 0.0022727272727))
                       (java.lang.Math/log 2))))))

; ampdb
(defn amp->db
  "Convert linear amplitude to decibels."
  [amp]
  (* 20 (java.lang.Math/log10 amp)))

; dbamp
(defn db->amp
  "Convert decibels to linear amplitude."
  [db]
  (java.lang.Math/exp (* (/ db 20) (java.lang.Math/log 10))))

(defn chosen-from [notes]
  (let [num-notes (count notes)]
