Skip to content

Instantly share code, notes, and snippets.

@josephernest
Created May 22, 2015 07:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save josephernest/8f52e50b6810c6bb4575 to your computer and use it in GitHub Desktop.
Save josephernest/8f52e50b6810c6bb4575 to your computer and use it in GitHub Desktop.
# note name (example: C3, C#3) into midi note number (example: 60, 61, etc.)
import re
note = "F3"
pattern = r"([A-Ga-g]#?[0-9])"
m = re.match(pattern, note)
notes = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
if m:
x = m.groups()[0]
print notes.index(x[:-1]) + (int(x[-1])+2) * 12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment