Skip to content

Instantly share code, notes, and snippets.

@alexpw
Last active January 3, 2016 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexpw/8476780 to your computer and use it in GitHub Desktop.
Save alexpw/8476780 to your computer and use it in GitHub Desktop.
(def notes {:C 0
:C# 1
:D 2
:D# 3
:E 4
:F 5
:F# 6
:G 7
:G# 8
:A 9
:A# 10
:B 11})
(defn note->num
[note]
(when-let [[_ b n] (re-find #"([\w]+#?)([\d]+)" (str note))]
(+ (notes (keyword b))
(* 12 (dec (Integer/parseInt n))))))
=> (note->num :C2)
12
=> (note->num :C#2)
13
=> (note->num :B1)
11
=> (note->num :B2)
23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment