# HG changeset patch # User Marcus Pearce # Date 1184691065 -3600 # Node ID 7a0ee88f1edb00f344998f91605b6994549eb4df # Parent c81375b9304f21991cead93a84b7a8bbda4e3338 base/: new generics DIATONIC-PITCH-ACCIDENTAL and OCTAVE darcs-hash:20070717165105-c0ce4-9f6acb06961d3413ceca604ca0285ababcdda377.gz diff -r c81375b9304f -r 7a0ee88f1edb base/generics.lisp --- a/base/generics.lisp Tue Jul 17 17:49:46 2007 +0100 +++ b/base/generics.lisp Tue Jul 17 17:51:05 2007 +0100 @@ -39,6 +39,16 @@ (defgeneric mips-pitch (pitch-designator)) (defgeneric frequency (object)) ;? +(defgeneric octave (pitch-designator) + (:documentation "Return an integer representing the octave of +pitch-designator where middle c is defined to be the lowest pitch in +octave 4.")) + +(defgeneric diatonic-pitch-accidental (pitch-designator) + (:documentation "Return an integer representing the inflection of a +diatonic pitch where where negative values indicate numbers of flats, +0 indicates natural and positive values indicate numbers of sharps.")) + (defgeneric middle-c (pitch-designator) (:documentation "Returns the value of middle C in the particular representation of pitch used by PITCH-DESIGNATOR.")) diff -r c81375b9304f -r 7a0ee88f1edb base/methods.lisp --- a/base/methods.lisp Tue Jul 17 17:49:46 2007 +0100 +++ b/base/methods.lisp Tue Jul 17 17:51:05 2007 +0100 @@ -2,6 +2,12 @@ ;;; diatonic pitch +(defmethod octave ((dp diatonic-pitch)) + (%diatonic-pitch-octave dp)) + +(defmethod diatonic-pitch-accidental ((dp diatonic-pitch)) + (%diatonic-pitch-accidental dp)) + (defmethod pitch= ((p1 diatonic-pitch) (p2 diatonic-pitch)) (let ((n1 (%diatonic-pitch-name p1)) (a1 (%diatonic-pitch-accidental p1)) @@ -47,6 +53,12 @@ ;;; MIPS pitch +(defmethod octave ((mp mips-pitch)) + (octave (diatonic-pitch mp))) + +(defmethod diatonic-pitch-accidental ((mp mips-pitch)) + (diatonic-pitch-accidental (diatonic-pitch mp))) + (defmethod pitch= ((p1 mips-pitch) (p2 mips-pitch)) (let ((c1 (meredith-chromatic-pitch-number p1)) (m1 (meredith-morphetic-pitch-number p1)) @@ -95,6 +107,9 @@ ;;; Chromatic pitch +(defmethod octave ((cp chromatic-pitch)) + (1- (/ (%chromatic-pitch-number cp) 12))) + (defmethod middle-c ((cp chromatic-pitch)) (make-chromatic-pitch 60)) diff -r c81375b9304f -r 7a0ee88f1edb base/package.lisp --- a/base/package.lisp Tue Jul 17 17:49:46 2007 +0100 +++ b/base/package.lisp Tue Jul 17 17:51:05 2007 +0100 @@ -118,4 +118,6 @@ #:diatonic-pitch-name #:middle-c #:make-mips-pitch + #:octave + #:diatonic-pitch-accidental ))