History

lib/aubio/midiconv.py: prepare for python3

Paul Brossier committed 10 years ago

Commit e76842e1 parent 376d5e91 file · +9 −2Browse files

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

Unified · Split

python/lib/aubio/midiconv.py+9−2
@@ -1,12 +1,19 @@
1# -*- coding: utf-8 -*-1# -*- coding: utf-8 -*-
2 2
3import sys
4PY3 = sys.version_info[0] == 3
5if PY3:
6 string_types = [str]
7else:
8 string_types = [str, unicode]
9
3def note2midi(note):10def note2midi(note):
4 " convert note name to midi note number, e.g. [C-1, G9] -> [0, 127] "11 " convert note name to midi note number, e.g. [C-1, G9] -> [0, 127] "
5 _valid_notenames = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}12 _valid_notenames = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
6 _valid_modifiers = {None: 0, u'♮': 0, '#': +1, u'♯': +1, u'\udd2a': +2, 'b': -1, u'♭': -1, u'\ufffd': -2}13 _valid_modifiers = {None: 0, u'♮': 0, '#': +1, u'♯': +1, u'\udd2a': +2, 'b': -1, u'♭': -1, u'\ufffd': -2}
7 _valid_octaves = range(-1, 10)14 _valid_octaves = range(-1, 10)
8 if type(note) not in (str, unicode):15 if type(note) not in string_types:
9 raise TypeError("a string is required, got %s" % note)16 raise TypeError("a string is required, got %s (%s)" % (note, str(type(note)) ))
10 if not (1 < len(note) < 5):17 if not (1 < len(note) < 5):
11 raise ValueError(18 raise ValueError(
12 "string of 2 to 4 characters expected, got %d (%s)" %19 "string of 2 to 4 characters expected, got %d (%s)" %

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