MCPcopy Create free account
hub / github.com/bspaans/python-mingus / note_to_int

Function note_to_int

mingus/core/notes.py:79–96  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

77
78
79def 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
99def reduce_accidentals(note):

Callers 2

is_enharmonicFunction · 0.85
reduce_accidentalsFunction · 0.85

Calls 2

NoteFormatErrorClass · 0.90
is_valid_noteFunction · 0.85

Tested by

no test coverage detected