History

python/lib/aubio/midiconv.py: fix instance checks

Paul Brossier committed 10 years ago

Commit 016813e1 parent ddfa6be1 file · +6 −6Browse files

Showing the changes to python (1 of 1 file). Show all

Unified · Split

python/lib/aubio/midiconv.py+6−6
@@ -4,11 +4,11 @@ · 3 unmodified lines
4import sys4import sys
5py3 = sys.version_info[0] == 35py3 = sys.version_info[0] == 3
6if py3:6if py3:
7 str_instances = [str]7 str_instances = str
8 int_instances = [int]8 int_instances = int
9else:9else:
10 str_instances = [str, unicode]10 str_instances = (str, unicode)
11 int_instances = [int, long]11 int_instances = (int, long)
12 12
13def note2midi(note):13def 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
52def midi2note(midi):52def 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)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t