INNER CODE UNIT · Python
unparse_grammar
jisungk/deepjazz · grammar.py:212
def unparse_grammar(m1_grammar, m1_chords):
m1_elements = stream.Voice()
currOffset = 0.0 # for recalculate last chord.
prevElement = None
for ix, grammarElement in enumerate(m1_grammar.split(' ')):
terms = grammarElement.split(',')
currOffset += float(terms[1]) # works just fine
# Case 1: it's a rest. Just append
if terms[0] == 'R':
rNote = note.Rest(quarterLength = float(terms[1]))
m1_elements.insert(currOffset, rNote)
continue
# Get the last chord first so you can find chord note, scale note, etc.
try:
lastChord = [n for n in m1_chords if n.offset <= currOffset][-1]
except IndexError: