;;;; The pitch module is responsible for converting intervals in "pitch
;;;; notation" to intervals in relative "numeric notation".
;;;;
;;;; This project does not handle MIDI, and while this module was moved from
;;;; the midiserver project, it is easily adapted to MIDI.
(defmodule uth.pitch
  (export all))

(defun template-note->
  ((1) 0)
  (('|#1|) 1)
  (('|##1|) 2)
  (('bb2) 0)
  (('b2) 1)
  ((2) 2)
  (('|#2|) 3)
  (('|##2|) 4)
  (('bb3) 2)
  (('b3) 3)
  ((3) 4)
  (('|#3|) 5)
  (('|##3|) 6)
  (('bb4) 3)
  (('b4) 4)
  ((4) 5)
  (('|#4|) 6)
  (('|##4|) 7)
  (('bb5) 5)
  (('b5) 6)
  ((5) 7)
  (('|#5|) 8)
  (('|##5|) 9)
  (('bb6) 7)
  (('b6) 8)
  ((6) 9)
  (('|#6|) 10)
  (('|##6|) 11)
  (('bb7) 9)
  (('b7) 10)
  ((7) 11)
  (('|#7|) 12)
  (('|##7|) 13)
  (('bb8) 10)
  (('b8) 11)
  ((8) 12)
  (('|#8|) 13)
  (('|##8|) 14)
  (('bb9) 12)
  (('b9) 13)
  ((9) 14)
  (('|#9|) 15)
  (('|##9|) 16)
  (('bb10) 14)
  (('b10) 15)
  ((10) 16)
  (('|#10|) 17)
  (('|##10|) 18)
  (('bb11) 16)
  (('b11) 17)
  ((11) 18)
  (('|#11|) 19)
  (('|##11|) 20)
  (('bb12) 18)
  (('b12) 19)
  ((12) 20)
  (('|#12|) 21)
  (('|##12|) 22)
  (('bb13) 20)
  (('b13) 21)
  ((13) 22)
  (('|#13|) 23)
  (('|##13|) 24)
  ((x)
   (template-note-> (- x 8))))

(defun template-> (template)
  (list-comp
    ((<- note template))
    (template-note-> note)))
