Main Page       Index


mnt.lsp


 mnt.lsp
 Version 1.00  24 December 2004
 Author Steven Jones

 Contact jones57@swbell.net include the word "nyquist" in subject line  

 The contents of this file are released under the terms of the GNU General
 Public License. See the file LICENSE.txt

 Display table of MIDI key numbers.


function

mnt:get-octave

 (mnt:get-octave p)
 Get octave value of p

 p      - flonum. A MIDI key number
 return - integer. The octave value of p


function

mnt:get-pitch-class

 (mnt:get-pitch-class p)
 Get the pitch class of p

 p      - flonum. A MIDI key number
 return - integer. The pitch class of p, p:{0,1,2,3,4,5,6,7,8,9,10,11}


function

mnt:get-mnemonic

 (mnt:get-mnemonic p [pad])
 Get string representation of MIDI key number.

 p      - flonum. A MIDI key number
 pad    - integer. The string width of the result, default 5
 return - string. The result has the form c[a]o[u] 
          Where 
          c is a pitch class "A", "B", "C", "D", "E", "F" or "G"
          a is an accidental, either '' or 'S' for sharp
          o is the octave, a single digit
          u is either '' to indicate p is exact or '+' to indicate
          p is sharp of the indicated pitch.


function

mnt

 (mnt [echo])
 Format and print table of MIDI key numbers
 
 echo   - bool. If true display result, if false return string
 return - string | nil


View the Sourcecode :



;; mnt.lsp
;; Version 1.00  24 December 2004
;; Author Steven Jones
;;
;; Contact jones57@swbell.net include the word "nyquist" in subject line  
;;
;; The contents of this file are released under the terms of the GNU General
;; Public License. See the file LICENSE.txt
;;
;; Display table of MIDI key numbers.
;;

(require 'su)
(provide 'mnt)
(current-file "mnt")


(setq mnt:notes (vector "C" "CS" "D" "DS" "E" "F" "FS" "G" "GS" "A" "AS" "B"))


;; @doc function mnt:get-octave
;; (mnt:get-octave p)
;; Get octave value of p
;;
;; p      - flonum. A MIDI key number
;; return - integer. The octave value of p
;;

(defun mnt:get-octave (p)
  (- (/ (truncate p) 12) 1))


;; @doc function mnt:get-pitch-class
;; (mnt:get-pitch-class p)
;; Get the pitch class of p
;;
;; p      - flonum. A MIDI key number
;; return - integer. The pitch class of p, p:{0,1,2,3,4,5,6,7,8,9,10,11}
;;

(defun mnt:get-pitch-class (p)
  (rem (truncate p) 12))


;; @doc function mnt:get-mnemonic
;; (mnt:get-mnemonic p [pad])
;; Get string representation of MIDI key number.
;;
;; p      - flonum. A MIDI key number
;; pad    - integer. The string width of the result, default 5
;; return - string. The result has the form c[a]o[u] 
;;          Where 
;;          c is a pitch class "A", "B", "C", "D", "E", "F" or "G"
;;          a is an accidental, either '' or 'S' for sharp
;;          o is the octave, a single digit
;;          u is either '' to indicate p is exact or '+' to indicate
;;          p is sharp of the indicated pitch.
;;

(defun mnt:get-mnemonic (p &optional (pad 5))
  (let (oct pclass acc)
    (setf oct (mnt:get-octave p))
    (setf pclass (mnt:get-pitch-class p))
    (setf acc (format nil "~a~a" (aref mnt:notes pclass) oct))
    (if (> p (truncate p))
	(setf acc (strcat acc "+")))
    (if pad
	(su:ljust acc pad)
      acc)))


;; @doc function mnt
;; (mnt [echo])
;; Format and print table of MIDI key numbers
;; 
;; echo   - bool. If true display result, if false return string
;; return - string | nil
;;

(defun mnt (&optional (echo 't))
  (let (head row acc pad pitch)
    (setf pad 5)
    (setf pitch 12)
    (setf head "Octave   ")
    (dotimes (n (length mnt:notes))
      (setf head (strcat head (su:ljust (aref mnt:notes n) pad))))
    (setf acc (format nil "~a~%" head))
    (dotimes (n 10)
      (setf row (strcat (su:zfill n 2) "   -   "))
      (dotimes(n 12)
	(setf row (strcat row (su:ljust (su:zfill pitch 3) pad)))
	(setf pitch (+ 1 pitch)))
      (setf acc (format nil "~a~a~%" acc row)))
    (format echo "~%~a" acc)))


Main Page       Index