 
 
 ;;Implementation of some tuning systems.
+
 (defmethod perfn :ed [[_ divisions multiplier initial freq]]
     "Divides a multiplier-tave (e.g. 2-tave = octave, 3-tave, &c.) into divisions divisions. Maps initial to a note with frequency freq."
     (fn [note]

          octave (quot (- note initial (- (count notemap) 1 )) (count notemap))]
        (* freq (nth notemap pos) (expt (ceil (reduce max notemap)) octave))))


;; Public Face - the tuning multimethods.


(defmethod tunednotes :default [_]
    (tunednotes :midi))

(defn parsemodifiers
    "Parses standard modifiers b, #, es, eh, ih and is for note names. Returns shifts where 1 is equivalent to a semitone."
    [modifiers]
    (let [matches (map first (concat (re-seq #"([ie][sh])" modifiers) (re-seq #"([b#])" modifiers)))]
        (+
            (- (count (filter #(= "b" %) matches)))
            (- (count (filter #(= "es" %) matches)))
            (* -0.5 (count (filter #(= "eh" %) matches)))
            (* 0.5 (count (filter #(= "ih" %) matches)))
            (count (filter #(= "is" %) matches))
            (count (filter #(= "#" %) matches)))))


;; Some other tuning systems

(defmethod perfn :arabic [[symb initial freq]]
    (perfn (list :edo 24 initial freq)))

(defmethod perfn :qcmeantone [[symb initial freq]]
    (fn [note]
        (perfmap note initial freq (note-set-from-generator (expt 5 1/4) -5 7 2))))



