Skip to content

Instantly share code, notes, and snippets.

@isoraqathedh
Created June 3, 2018 11:29
Show Gist options
  • Save isoraqathedh/5cb162c45eca3ee76e517ae21f5c94e7 to your computer and use it in GitHub Desktop.
Save isoraqathedh/5cb162c45eca3ee76e517ae21f5c94e7 to your computer and use it in GitHub Desktop.
(defun solfege->note-number (solfege octave key mode base-octave)
"Convert a note in the movable-do system into absolute notes."
(let ((note-correspondences
'(#|de = ti|# ("do" . 0) ("di" . 1)
("ra" . 1) ("re" . 2) ("ri" . 3)
("me" . 3) ("mi" . 4)
#|fe = mi|# ("fa" . 5) ("fi" . 6)
("se" . 6) ("so" . 7) ("si" . 8)
("le" . 8) ("la" . 9) ("li" . 10)
("te" . 10) ("ti" . 11)
#|------|# ("do'" . 12)))
(tonic
(case mode
((:major :ionian) "do'")
((:minor :aeolian) "la")
(:dorian "re")
(:phrygian "mi")
(:lydian "fa")
(:mixolydian "so")
(:locrian "ti"))))
(+ (cdr (assoc solfege note-correspondences :test #'string-equal))
(alexandria:eswitch (key :test #'string-equal)
("C" 0) ("C#" 1) ("Db" 1)
("D" 2) ("D#" 3) ("Eb" 3)
("E" 4)
("F" 5) ("F#" 6) ("Gb" 6)
("G" 7) ("G#" 8) ("Ab" 8)
("A" 9) ("A#" 10) ("Bb" 10)
("B" 11))
(ecase mode
((:major :ionian) 0)
((:minor :aeolian) 3)
(:dorian 9)
(:phrygian 8)
(:lydian 7)
(:mixolydian 5)
(:locrian 1))
(* octave 12)
(* base-octave 12)
(if (<= (position tonic note-correspondences
:key #'car
:test #'string-equal)
(position solfege note-correspondences
:key #'car
:test #'string-equal))
0
12))))
(defun note->note-number (note accidental octave)
"Turn a note into a number."
(+ (ecase (normalise-note-letter note)
(#\C 0) (#\D 2) (#\E 4) (#\F 5)
(#\G 7) (#\A 9) (#\B 11))
(ecase (normalise-accidental accidental)
(:sharp 1) (:flat -1) (:natural 0))
(* 12 octave)
12)) ;; offset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment