Skip to content

Commit 70aa65f

Browse files
simplify name_to_note code
1 parent 121c84f commit 70aa65f

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

cedargrove_midi_tools.py

100644100755
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,10 @@ def name_to_note(name):
7474
:param str name: The note name input in NoteOctave format. No default value.
7575
"""
7676
name = name.upper() # Convert lower to uppercase
77-
if (name[:1] or name[:2]) in NOTE_BASE:
77+
if name[:-1] in NOTE_BASE:
7878
# Note name is valid
79-
if "#" in name:
80-
# Extract octave value for 'sharped' note
81-
note = NOTE_BASE.index(name[:2])
82-
octave = int(name[2:])
83-
else:
84-
# Extract octave value
85-
note = NOTE_BASE.index(name[0])
86-
octave = int(name[1:])
79+
note = NOTE_BASE.index(name[:-1])
80+
octave = int(name[-1])
8781
return note + (12 * (octave + 1)) # Calculated note value
8882
return None # Input string is not in NOTE_BASE
8983

0 commit comments

Comments
 (0)