ref: e76842e70dd5d6b326096b53afd24542636a7462
parent: 376d5e97103f3715d0ef89df155c14ffe6cbec09
author: Paul Brossier <piem@piem.org>
date: Mon Apr 18 20:44:46 EDT 2016
lib/aubio/midiconv.py: prepare for python3
--- a/python/lib/aubio/midiconv.py
+++ b/python/lib/aubio/midiconv.py
@@ -1,12 +1,19 @@
# -*- coding: utf-8 -*-
+import sys
+PY3 = sys.version_info[0] == 3
+if PY3:
+ string_types = [str]
+else:
+ string_types = [str, unicode]
+
def note2midi(note):
" convert note name to midi note number, e.g. [C-1, G9] -> [0, 127] "
_valid_notenames = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
_valid_modifiers = {None: 0, u'♮': 0, '#': +1, u'♯': +1, u'\udd2a': +2, 'b': -1, u'♭': -1, u'\ufffd': -2}
_valid_octaves = range(-1, 10)
- if type(note) not in (str, unicode):
- raise TypeError("a string is required, got %s" % note)
+ if type(note) not in string_types:
+ raise TypeError("a string is required, got %s (%s)" % (note, str(type(note)) ))
if not (1 < len(note) < 5):
raise ValueError(
"string of 2 to 4 characters expected, got %d (%s)" %