}
_valid_octaves = range(-1, 10)
if not isinstance(note, str_instances):
- raise TypeError("a string is required, got %s (%s)" % (note, str(type(note))))
+ msg = "a string is required, got {:s} ({:s})"
+ raise TypeError(msg.format(str(type(note)), repr(note)))
if len(note) not in range(2, 5):
- raise ValueError("string of 2 to 4 characters expected, got %d (%s)" \
- % (len(note), note))
+ msg = "string of 2 to 4 characters expected, got {:d} ({:s})"
+ raise ValueError(msg.format(len(note), note))
notename, modifier, octave = [None]*3
if len(note) == 4:
if octave not in _valid_octaves:
raise ValueError("%s is not a valid octave" % octave)
- midi = 12 + octave * 12 + _valid_notenames[notename] + _valid_modifiers[modifier]
+ midi = 12 + octave * 12 + _valid_notenames[notename] \
+ + _valid_modifiers[modifier]
if midi > 127:
raise ValueError("%s is outside of the range C-2 to G8" % note)
return midi
if not isinstance(midi, int_instances):
raise TypeError("an integer is required, got %s" % midi)
if midi not in range(0, 128):
- raise ValueError("an integer between 0 and 127 is excepted, got %d" % midi)
- _valid_notenames = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
+ msg = "an integer between 0 and 127 is excepted, got {:d}"
+ raise ValueError(msg.format(midi))
+ _valid_notenames = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#',
+ 'A', 'A#', 'B']
return _valid_notenames[midi % 12] + str(int(midi / 12) - 1)
def freq2note(freq):