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

Function remove_redundant_accidentals

mingus/core/notes.py:120–142  ·  view source on GitHub ↗

Remove redundant sharps and flats from the given note. Examples: >>> remove_redundant_accidentals('C##b') 'C#' >>> remove_redundant_accidentals('Eb##b') 'E'

(note)

Source from the content-addressed store, hash-verified

118
119
120def remove_redundant_accidentals(note):
121 """Remove redundant sharps and flats from the given note.
122
123 Examples:
124 >>> remove_redundant_accidentals('C##b')
125 'C#'
126 >>> remove_redundant_accidentals('Eb##b')
127 'E'
128 """
129 val = 0
130 for token in note[1:]:
131 if token == "b":
132 val -= 1
133 elif token == "#":
134 val += 1
135 result = note[0]
136 while val > 0:
137 result = augment(result)
138 val -= 1
139 while val < 0:
140 result = diminish(result)
141 val += 1
142 return result
143
144
145def augment(note):

Callers

nothing calls this directly

Calls 2

augmentFunction · 0.85
diminishFunction · 0.85

Tested by

no test coverage detected