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

Function parse_string

mingus/core/progressions.py:215–239  ·  view source on GitHub ↗

Return a tuple (roman numeral, accidentals, chord suffix). Examples: >>> parse_string('I') ('I', 0, '') >>> parse_string('bIM7') ('I', -1, 'M7')

(progression)

Source from the content-addressed store, hash-verified

213
214
215def parse_string(progression):
216 """Return a tuple (roman numeral, accidentals, chord suffix).
217
218 Examples:
219 >>> parse_string('I')
220 ('I', 0, '')
221 >>> parse_string('bIM7')
222 ('I', -1, 'M7')
223 """
224 acc = 0
225 roman_numeral = ""
226 suffix = ""
227 i = 0
228 for c in progression:
229 if c == "#":
230 acc += 1
231 elif c == "b":
232 acc -= 1
233 elif c.upper() == "I" or c.upper() == "V":
234 roman_numeral += c.upper()
235 else:
236 break
237 i += 1
238 suffix = progression[i:]
239 return (roman_numeral, acc, suffix)
240
241
242def tuple_to_string(prog_tuple):

Callers 7

to_chordsFunction · 0.85
substitute_harmonicFunction · 0.85
substituteFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected