feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change
on this file since 33102ab was
33102ab,
checked in by Paul Brossier <piem@piem.org>, 11 years ago
|
lib/aubio/midiconv.py: add note2midi
|
-
Property mode set to
100755
|
File size:
1.5 KB
|
Line | |
---|
1 | # -*- encoding: utf8 -*- |
---|
2 | |
---|
3 | from aubio import note2midi |
---|
4 | import unittest |
---|
5 | |
---|
6 | list_of_known_notes = ( |
---|
7 | ( 'C-1', 0 ), |
---|
8 | ( 'C#-1', 1 ), |
---|
9 | ( 'd2', 38 ), |
---|
10 | ( 'C3', 48 ), |
---|
11 | ( 'B3', 59 ), |
---|
12 | ( 'B#3', 60 ), |
---|
13 | ( 'A4', 69 ), |
---|
14 | ( 'A#4', 70 ), |
---|
15 | ( 'G8', 115 ), |
---|
16 | ( u'G♯8', 116 ), |
---|
17 | ( u'G♭9', 126 ), |
---|
18 | ( 'G9', 127 ), |
---|
19 | ( u'G\udd2a2', 45 ), |
---|
20 | ( u'B\ufffd2', 45 ), |
---|
21 | ( u'A♮2', 45 ), |
---|
22 | ) |
---|
23 | |
---|
24 | class TestNote2MidiGoodValues(unittest.TestCase): |
---|
25 | |
---|
26 | def test_note2midi_known_values(self): |
---|
27 | " known values are correctly converted " |
---|
28 | for note, midi in list_of_known_notes: |
---|
29 | self.assertEqual ( note2midi(note), midi ) |
---|
30 | |
---|
31 | class TestNote2MidiWrongValues(unittest.TestCase): |
---|
32 | |
---|
33 | def test_note2midi_missing_octave(self): |
---|
34 | " fails when passed only one character" |
---|
35 | self.assertRaises(ValueError, note2midi, 'C') |
---|
36 | |
---|
37 | def test_note2midi_wrong_modifier(self): |
---|
38 | " fails when passed an invalid note name" |
---|
39 | self.assertRaises(ValueError, note2midi, 'C.1') |
---|
40 | |
---|
41 | def test_note2midi_wronge_midifier_again(self): |
---|
42 | " fails when passed a wrong modifier" |
---|
43 | self.assertRaises(ValueError, note2midi, 'CB-3') |
---|
44 | |
---|
45 | def test_note2midi_wrong_octave(self): |
---|
46 | " fails when passed a wrong octave" |
---|
47 | self.assertRaises(ValueError, note2midi, 'CBc') |
---|
48 | |
---|
49 | def test_note2midi_out_of_range(self): |
---|
50 | " fails when passed a non-existing note" |
---|
51 | self.assertRaises(ValueError, note2midi, 'A9') |
---|
52 | |
---|
53 | if __name__ == '__main__': |
---|
54 | unittest.main() |
---|
Note: See
TracBrowser
for help on using the repository browser.