diff base/constructors.lisp @ 106:8528c316fbcc

delete diatonic-pitch (as was) Delete the diatonic-pitch class, in preparation for MIPS pitch being our single representation. Add a DIATONIC-PITCH-OCTAVE generic, and make OCTAVE return the octave based on a MIDI-PITCH-NUMBER (and make sure that it returns an integer, too). darcs-hash:20070726121235-dc3a5-4cbd1058145163eecbfc84384234904e2353fead.gz
author c.rhodes <c.rhodes@gold.ac.uk>
date Thu, 26 Jul 2007 13:12:35 +0100
parents 7f139c81752e
children a9a1c7aa86a9
line wrap: on
line diff
--- a/base/constructors.lisp	Thu Jul 26 10:29:52 2007 +0100
+++ b/base/constructors.lisp	Thu Jul 26 13:12:35 2007 +0100
@@ -24,10 +24,19 @@
   (make-instance 'chromatic-pitch :number pitch-number))
 
 (defun make-diatonic-pitch (name accidental octave)
-  (make-instance 'diatonic-pitch
-		 :name name
-		 :accidental accidental
-		 :octave octave))
+  (flet ((asa-string (name accidental octave)
+           (with-output-to-string (s)
+             (write-char name s)
+             (if (zerop accidental)
+                 (write-char #\n s)
+                 (let ((achar (if (plusp accidental) #\s #\f)))
+                   (dotimes (i (abs accidental))
+                     (write-char achar s))))
+             (write octave :stream s :base 10 :radix nil :pretty nil))))
+    (let* ((name (if (numberp name) (elt "ABCDEFG" name) name))
+           (asa-string (asa-string name accidental octave))
+           (p (mips:pn-p asa-string)))
+      (make-instance 'mips-pitch :cp (first p) :mp (second p)))))
 
 (defun make-mips-pitch (cp mp)
   (make-instance 'mips-pitch :cp cp :mp mp))