Showing the changes to python (1 of 1 file). Show all
Unified · Split
| @@ -4,11 +4,11 @@ · 3 unmodified lines | |||
| 4 | import sys | 4 | import sys |
| 5 | py3 = sys.version_info[0] == 3 | 5 | py3 = sys.version_info[0] == 3 |
| 6 | if py3: | 6 | if py3: |
| 7 | str_instances = [str] | 7 | str_instances = str |
| 8 | int_instances = [int] | 8 | int_instances = int |
| 9 | else: | 9 | else: |
| 10 | str_instances = [str, unicode] | 10 | str_instances = (str, unicode) |
| 11 | int_instances = [int, long] | 11 | int_instances = (int, long) |
| 12 | 12 | ||
| 13 | def note2midi(note): | 13 | def note2midi(note): |
| 14 | " convert note name to midi note number, e.g. [C-1, G9] -> [0, 127] " | 14 | " convert note name to midi note number, e.g. [C-1, G9] -> [0, 127] " |
| @@ -16,7 +16,7 @@ def note2midi(note): · 1 unmodified line | |||
| 16 | _valid_modifiers = {None: 0, u'♮': 0, '#': +1, u'♯': +1, u'\udd2a': +2, | 16 | _valid_modifiers = {None: 0, u'♮': 0, '#': +1, u'♯': +1, u'\udd2a': +2, |
| 17 | 'b': -1, u'♭': -1, u'\ufffd': -2} | 17 | 'b': -1, u'♭': -1, u'\ufffd': -2} |
| 18 | _valid_octaves = range(-1, 10) | 18 | _valid_octaves = range(-1, 10) |
| 19 | if isinstance(note, str_instances): | 19 | if not isinstance(note, str_instances): |
| 20 | raise TypeError("a string is required, got %s (%s)" % (note, str(type(note)))) | 20 | raise TypeError("a string is required, got %s (%s)" % (note, str(type(note)))) |
| 21 | if len(note) not in range(2, 5): | 21 | if len(note) not in range(2, 5): |
| 22 | raise ValueError("string of 2 to 4 characters expected, got %d (%s)" \ | 22 | raise ValueError("string of 2 to 4 characters expected, got %d (%s)" \ |
| @@ -51,7 +51,7 @@ def note2midi(note): · 28 unmodified lines | |||
| 51 | 51 | ||
| 52 | def midi2note(midi): | 52 | def midi2note(midi): |
| 53 | " convert midi note number to note name, e.g. [0, 127] -> [C-1, G9] " | 53 | " convert midi note number to note name, e.g. [0, 127] -> [C-1, G9] " |
| 54 | if isinstance(midi, int_instances): | 54 | if not isinstance(midi, int_instances): |
| 55 | raise TypeError("an integer is required, got %s" % midi) | 55 | raise TypeError("an integer is required, got %s" % midi) |
| 56 | if midi not in range(0, 128): | 56 | if midi not in range(0, 128): |
| 57 | raise ValueError("an integer between 0 and 127 is excepted, got %d" % midi) | 57 | raise ValueError("an integer between 0 and 127 is excepted, got %d" % midi) |