anchor.diff:                ((= 8 octave)
                  (cond ((string= "C" note) 88)
                        (T (invalid-key-notation-error key))))
  -              (T (+ 4 (* octave 7) (note-order note))))))))
  +              (T (+ 3 (* octave 7) (note-order note))))))))
       (T (invalid-key-notation-error key))))
   
   (defun ensure-double-float (number)
  
positive.code:       (#\A 6)
        ((#\B #\H) 7))))
  
  (defun ensure-piano-key (key)
    (cond
      ((typep key 'integer) key)
  
negative.code:   (coerce (+ (- (ensure-pitch tuning) 440.0d0)
               (* 440.0d0 (expt 2.0d0 (/ (- (ensure-piano-key key) 49.0d0) 12.0d0))))
            'single-float))
  
  (defun pitch->piano-key (pitch &key (tuning 440.0d0))
    (let ((pitch (ensure-double-float (- pitch (- 440.0d0 tuning)))))
      (let* ((key (round (+ 49.0d0 (/ (* 12.0d0 (log (/ pitch 440.0d0))) (log 2.0d0)))))
             (offset (- pitch (piano-key->pitch key :tuning tuning))))
        (values key (if (< (abs offset) 0.001d0) 0.0 (/ (round (* offset 1000.0)) 1000.0))))))
  
  (defun piano-key->notation (key &key (notation 'english))
    (unless (<= 1 key 88) (error (format NIL "Invalid key: ~a" key)))
    (cond
      ((< key 4)
       (notation (if (= key 3) #\B #\A) 0 :sharp-p (= key 2) :notation notation))
      ((= key 88) (notation #\C 8 :notation notation))
      (T (let ((key-of-octave (mod (- key 3) 12))
               (black-keys '(2 4 7 9 11)))
           (when (= 0 key-of-octave) (setf key-of-octave 12))
           (notation (note-from-order (- key-of-octave (length (loop for black in black-keys
                                                                     until (< key-of-octave black)
                                                                     collecting black))))
                     (floor (+ key 8) 12)
                     :sharp-p (find key-of-octave black-keys)
                     :notation notation)))))
  
  (defun pitch->notation (pitch &key (tuning 440.0d0) (notation 'english))
    (multiple-value-bind (key offset)
        (pitch->piano-key pitch :tuning tuning)
      (values (piano-key->notation key :notation notation) offset)))
  