From 70aa65fde63a3c1e7fefe3fc327d0c4cf91abaac Mon Sep 17 00:00:00 2001 From: Cedar Grove Maker Studios Date: Fri, 15 Sep 2023 16:25:21 -0700 Subject: [PATCH] simplify name_to_note code --- cedargrove_midi_tools.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) mode change 100644 => 100755 cedargrove_midi_tools.py diff --git a/cedargrove_midi_tools.py b/cedargrove_midi_tools.py old mode 100644 new mode 100755 index ca5eca5..5807692 --- a/cedargrove_midi_tools.py +++ b/cedargrove_midi_tools.py @@ -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