comparison utils/utils.lisp @ 54:df1482ef96fe

utils.lisp: fix and extend krumhansl-key-finder darcs-hash:20070621120851-c0ce4-bde38534beea40f71e8206f85583111fdfbe1fcd.gz
author Marcus Pearce <m.pearce@gold.ac.uk>
date Thu, 21 Jun 2007 13:08:51 +0100
parents e3d86a0f25b3
children 13033824fa7d
comparison
equal deleted inserted replaced
53:ce4a90427366 54:df1482ef96fe
124 (aref vector2 j)))) 124 (aref vector2 j))))
125 equation-tr) 125 equation-tr)
126 (aref results-array i) (/ equation-t equation-b)))))) 126 (aref results-array i) (/ equation-t equation-b))))))
127 127
128 128
129 (defparameter *krumhansl-schmuckler-minor-key*
130 (make-array 12 :initial-contents '(6.33 2.68 3.52 5.38 2.6 3.53 2.54 4.75 3.98 2.69 3.34 3.17)))
131
129 (defparameter *krumhansl-schmuckler-major-key* 132 (defparameter *krumhansl-schmuckler-major-key*
130 (make-array 12 :initial-contents '(6.33 2.68 3.52 5.38 2.6 3.53 2.54 4.75 3.98 2.69 3.34 3.17)))
131
132 (defparameter *krumhansl-schmuckler-minor-key*
133 (make-array 12 :initial-contents '(6.35 2.23 3.48 2.33 4.38 4.09 2.52 5.19 2.39 3.66 2.29 2.88))) 133 (make-array 12 :initial-contents '(6.35 2.23 3.48 2.33 4.38 4.09 2.52 5.19 2.39 3.66 2.29 2.88)))
134 134
135 (defun krumhansl-key-finder (anchored-period composition 135 (defun krumhansl-key-finder (anchored-period composition
136 &key (major *krumhansl-schmuckler-major-key*) 136 &key (major *krumhansl-schmuckler-major-key*)
137 (minor *krumhansl-schmuckler-minor-key*)) 137 (minor *krumhansl-schmuckler-minor-key*))
145 best-score (aref majors i)))) 145 best-score (aref majors i))))
146 (loop for i from 0 to 11 146 (loop for i from 0 to 11
147 do (when (> (aref minors i) best-score) 147 do (when (> (aref minors i) best-score)
148 (setf key (list i :minor) 148 (setf key (list i :minor)
149 best-score (aref minors i)))) 149 best-score (aref minors i))))
150 key)) 150 (values key (key->midi-key-signature key anchored-period))))
151
152 (defvar *line-of-fifths* (list 5 10 3 8 1 0 7 2 9 4 11 6))
153
154 (defun key->midi-key-signature (key anchored-period)
155 (let* ((tonic (car key))
156 (mode (cadr key))
157 (sharps (- (ecase mode
158 (:major (position tonic *line-of-fifths*))
159 (:minor (position (mod (- tonic 9) 12) *line-of-fifths*)))
160 5))
161 (mode (ecase mode (:major 0) (:minor 9))))
162 (amuse:make-midi-key-signature sharps mode
163 (timepoint anchored-period)
164 (duration anchored-period))))
151 165
152 (defun levenshtein-distance (s1 s2 &key (insertion-cost 1) 166 (defun levenshtein-distance (s1 s2 &key (insertion-cost 1)
153 (insertion-function) (deletion-cost 1) 167 (insertion-function) (deletion-cost 1)
154 (deletion-function) (substitution-cost 1) 168 (deletion-function) (substitution-cost 1)
155 (substitution-test #'equal) (substitution-function)) 169 (substitution-test #'equal) (substitution-function))