;; quantize pc
;; Always slelects a higher value before a lower value where distance is equal.
;;
;; arg 1: pitch to quantize to pc
;; arg 2: pc to quantize pitch against
;;
;; returns quantized pitch or #f if non available
;;
(define pc:quantize
(lambda (pitch-in pc)
(let loop ((offset 0)
(pitch (real->integer (round pitch-in))))
(cond ((pc:? (+ pitch offset) pc) (+ pitch offset))
((pc:? (- pitch offset) pc) (- pitch offset))
((< offset 7) (loop (+ offset 1) pitch))
(else (log-info "no pc value to quantize to" pitch pc)
#f)))))