History

lib/aubio/midiconv.py: improve note2midi

Paul Brossier committed 13 years ago

Commit f552e9e1 parent 33102ab2 files · +14 −8Browse files

Showing the changes to python/lib (1 of 2 files). Show all

Unified · Split

python/lib/aubio/midiconv.py+3−2
@@ -1,11 +1,12 @@
1# -*- encoding: utf8 -*-1# -*- encoding: utf8 -*-
2 2
3def note2midi(note):3def note2midi(note):
4 " convert a note name to a midi note value "4 " convert note name to midi note number, e.g. [C-1, G9] -> [0, 127] "
5 # from C-2 to G8, though we do accept everything in the upper octave
6 _valid_notenames = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}5 _valid_notenames = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
7 _valid_modifiers = {None: 0, u'♮': 0, '#': +1, u'♯': +1, u'\udd2a': +2, 'b': -1, u'♭': -1, u'\ufffd': -2}6 _valid_modifiers = {None: 0, u'♮': 0, '#': +1, u'♯': +1, u'\udd2a': +2, 'b': -1, u'♭': -1, u'\ufffd': -2}
8 _valid_octaves = range(-1, 10) 7 _valid_octaves = range(-1, 10)
8 if type(note) not in (str, unicode):
9 raise TypeError, "a string is required, got %s" % note
9 if not (1 < len(note) < 5):10 if not (1 < len(note) < 5):
10 raise ValueError, "string of 2 to 4 characters expected, got %d (%s)" % (len(note), note)11 raise ValueError, "string of 2 to 4 characters expected, got %d (%s)" % (len(note), note)
11 notename, modifier, octave = [None]*312 notename, modifier, octave = [None]*3

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