Created
January 19, 2012 11:38
-
-
Save forsakendaemon/1639535 to your computer and use it in GitHub Desktop.
Simple chord analysis in overtone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def notenames '(:C :C# :D :D# :E :F :F# :G :G# :A :A# :B)) | |
(defn subchord [chord] (map - (rest chord) chord)) | |
(defn complete [chord] (concat chord (list (apply - (cons 12 chord))))) | |
(defn rotate [list] (cons (last list) (butlast list))) | |
(defn match [chordlist] | |
(try | |
(if (= (first chordlist) (+ 1 (count (second chordlist)))) (throw (Exception. "Unable to Match"))) | |
(condp = (second chordlist) | |
'(4 3 5) (list (first chordlist) "Major") | |
'(3 4 5) (list (first chordlist) "Minor") | |
'(3 3 6) (list (first chordlist) "Diminished") | |
'(4 4 4) (list (first chordlist) "Augmented") | |
'(4 3 4 1) (list (first chordlist) "Major 7th") | |
'(4 3 3 2) (list (first chordlist) "7th") | |
'(3 4 4 1) (list (first chordlist) "Minor Major 7th") | |
'(3 4 3 2) (list (first chordlist) "Minor 7th") | |
(match (list (+ 1 (first chordlist)) (rotate (second chordlist))))) | |
(catch Exception e (prn e)))) | |
(defn getroot [notes matchlist] | |
(cons (nth notenames (rem (nth notes (mod (- (count notes) (first matchlist)) (count notes))) 12)) matchlist) | |
) | |
(defn procchord [chord] | |
(getroot chord (match (list 0 (complete (subchord chord))))) | |
) | |
; examples | |
(procchord '(60 65 69)) ; -> (:F 2 "Major") | |
(procchord '(60 64 67)) ; -> (:C 0 "Major") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment