From: Paul Brossier Date: Mon, 18 Apr 2016 22:44:46 +0000 (+0200) Subject: lib/aubio/midiconv.py: prepare for python3 X-Git-Tag: 0.4.4~300^2~307^2~7 X-Git-Url: https://git.aubio.org/?a=commitdiff_plain;h=e76842e70dd5d6b326096b53afd24542636a7462;p=aubio.git lib/aubio/midiconv.py: prepare for python3 --- diff --git a/python/lib/aubio/midiconv.py b/python/lib/aubio/midiconv.py index 5937be66..a2bcfb22 100644 --- 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)" %