Skip to content

Commit

Permalink
simplify name_to_note code
Browse files Browse the repository at this point in the history
  • Loading branch information
CedarGroveStudios committed Sep 15, 2023
1 parent 121c84f commit 70aa65f
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions cedargrove_midi_tools.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,10 @@ def name_to_note(name):
:param str name: The note name input in NoteOctave format. No default value.
"""
name = name.upper() # Convert lower to uppercase
if (name[:1] or name[:2]) in NOTE_BASE:
if name[:-1] in NOTE_BASE:
# Note name is valid
if "#" in name:
# Extract octave value for 'sharped' note
note = NOTE_BASE.index(name[:2])
octave = int(name[2:])
else:
# Extract octave value
note = NOTE_BASE.index(name[0])
octave = int(name[1:])
note = NOTE_BASE.index(name[:-1])
octave = int(name[-1])
return note + (12 * (octave + 1)) # Calculated note value
return None # Input string is not in NOTE_BASE

Expand Down

0 comments on commit 70aa65f

Please sign in to comment.