Convert notes in the form of C, C#, Cb, C##, etc. to an integer in the range of 0-11. Throw a NoteFormatError exception if the note format is not recognised.
(note)
| 77 | |
| 78 | |
| 79 | def note_to_int(note): |
| 80 | """Convert notes in the form of C, C#, Cb, C##, etc. to an integer in the |
| 81 | range of 0-11. |
| 82 | |
| 83 | Throw a NoteFormatError exception if the note format is not recognised. |
| 84 | """ |
| 85 | if is_valid_note(note): |
| 86 | val = _note_dict[note[0]] |
| 87 | else: |
| 88 | raise NoteFormatError("Unknown note format '%s'" % note) |
| 89 | |
| 90 | # Check for '#' and 'b' postfixes |
| 91 | for post in note[1:]: |
| 92 | if post == "b": |
| 93 | val -= 1 |
| 94 | elif post == "#": |
| 95 | val += 1 |
| 96 | return val % 12 |
| 97 | |
| 98 | |
| 99 | def reduce_accidentals(note): |
no test coverage detected