File tree Expand file tree Collapse file tree 1 file changed +14
-7
lines changed Expand file tree Collapse file tree 1 file changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -66,19 +66,26 @@ def note_to_name(note):
6666
6767def name_to_note (name ):
6868 """Translates a note name to a MIDI sequential note value. Note names are
69- character strings expressed in the NoteOctave format such as 'C4' or 'G#7'.
70- Note names range from 'C-1' (note value 0) to 'F#9' (note value 127). Note
71- values are of integer type in the range of 0 to 127 (inclusive). If the
72- input value is outside that range, the value of `None` is returned.
69+ character strings expressed in Scienfic Pitch Notation (NoteOctave) format
70+ such as 'C4' or 'G#7'. Note names range from 'C-1' (note value 0) to
71+ 'F#9' (note value 127). Note values are of integer type in the range of
72+ 0 to 127 (inclusive). If the input value is outside that range, the value
73+ of `None` is returned.
7374
74- :param str name: The note name input in NoteOctave format. No default value.
75+ :param str name: The note name input in SPN format. No default value.
7576 """
7677 name = name .upper () # Convert lower to uppercase
7778 if name [:- 1 ] in NOTE_BASE :
7879 # Note name is valid
7980 note = NOTE_BASE .index (name [:- 1 ])
80- octave = int (name [- 1 ])
81- return note + (12 * (octave + 1 )) # Calculated note value
81+ if "-1" in name :
82+ # Special case for octave -1
83+ note = NOTE_BASE .index (name [:- 2 ])
84+ octave = - 1
85+ else :
86+ note = NOTE_BASE .index (name [:- 1 ])
87+ octave = int (name [- 1 ])
88+ return min (max (0 , note + (12 * (octave + 1 ))), 127 ) # MIDI note value
8289 return None # Input string is not in NOTE_BASE
8390
8491
You can’t perform that action at this time.
0 commit comments