Last active
December 27, 2015 02:09
-
-
Save zeffii/7249990 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
given valid notes this returns their correct midi integer value | |
given "off" or "---" will return -1 and -2 respectively | |
given any other input will return -3 | |
""" | |
def notetoi(strlong_in): | |
""" note string to midi integer """ | |
def to_note(str_in, oct_in): | |
""" further parsing of note input """ | |
if (oct_in < 0 or oct_in > 10): return -1 | |
str_in = str_in.replace('-', '') | |
notes_list = ["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"] | |
# note must be in this list, else return -1 at the end | |
for i, note in enumerate(notes_list): | |
if str_in == note: | |
return (i + oct_in * 12) | |
if not strlong_in.lower() == "off": | |
if strlong_in == "---": | |
return -2 | |
str_in, oct_in = strlong_in[:2], int(strlong_in[-1]) | |
return to_note(str_in, oct_in) | |
# if reaches here, it's not recognized as a valid note | |
return -3 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment