Showing the changes to python (1 of 1 file). Show all
Unified · Split
| @@ -24,10 +24,11 @@ def note2midi(note): · 23 unmodified lines | ||
| 24 | 24 | } |
| 25 | 25 | _valid_octaves = range(-1, 10) |
| 26 | 26 | if not isinstance(note, str_instances): |
| 27 | − raise TypeError("a string is required, got %s (%s)" % (note, str(type(note)))) | |
| 27 | + msg = "a string is required, got {:s} ({:s})" | |
| 28 | + raise TypeError(msg.format(str(type(note)), repr(note))) | |
| 28 | 29 | if len(note) not in range(2, 5): |
| 29 | − raise ValueError("string of 2 to 4 characters expected, got %d (%s)" \ | |
| 30 | − % (len(note), note)) | |
| 30 | + msg = "string of 2 to 4 characters expected, got {:d} ({:s})" | |
| 31 | + raise ValueError(msg.format(len(note), note)) | |
| 31 | 32 | notename, modifier, octave = [None]*3 |
| 32 | 33 | |
| 33 | 34 | if len(note) == 4: |
| @@ -51,7 +52,8 @@ def note2midi(note): · 17 unmodified lines | ||
| 51 | 52 | if octave not in _valid_octaves: |
| 52 | 53 | raise ValueError("%s is not a valid octave" % octave) |
| 53 | 54 | |
| 54 | − midi = 12 + octave * 12 + _valid_notenames[notename] + _valid_modifiers[modifier] | |
| 55 | + midi = 12 + octave * 12 + _valid_notenames[notename] \ | |
| 56 | + + _valid_modifiers[modifier] | |
| 55 | 57 | if midi > 127: |
| 56 | 58 | raise ValueError("%s is outside of the range C-2 to G8" % note) |
| 57 | 59 | return midi |
| @@ -61,8 +63,10 @@ def midi2note(midi): · 3 unmodified lines | ||
| 61 | 63 | if not isinstance(midi, int_instances): |
| 62 | 64 | raise TypeError("an integer is required, got %s" % midi) |
| 63 | 65 | if midi not in range(0, 128): |
| 64 | − raise ValueError("an integer between 0 and 127 is excepted, got %d" % midi) | |
| 65 | − _valid_notenames = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B'] | |
| 66 | + msg = "an integer between 0 and 127 is excepted, got {:d}" | |
| 67 | + raise ValueError(msg.format(midi)) | |
| 68 | + _valid_notenames = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', | |
| 69 | + 'A', 'A#', 'B'] | |
| 66 | 70 | return _valid_notenames[midi % 12] + str(int(midi / 12) - 1) |
| 67 | 71 | |
| 68 | 72 | def freq2note(freq): |