import xml.etree.ElementTree import fractions import generator.model import tests.test_musicxml import tests.test_parts def xml_bars(contents, *, beats=4, divisions=1, implicit=False): root = xml.etree.ElementTree.fromstring(tests.test_musicxml.xml_score(contents[0], f'', divisions=divisions, implicit=implicit)) for index, content in enumerate(contents[1:], 2): root.find('part').append(xml.etree.ElementTree.fromstring(f'{content}')) return xml.etree.ElementTree.tostring(root, encoding='unicode') def melody_measures(count, *, beats=4, dense=False): notes = ''.join(tests.test_musicxml.xml_note(duration=1, kind='eighth' if dense else 'quarter') for _ in range(beats * (2 if dense else 1))) content = tests.test_parts.xml_harmony() + notes return tests.test_musicxml.parse(xml_bars([content] * count, beats=beats, divisions=2 if dense else 1))['staves'][0]['measures'] def timing(events): return [(generator.model.fraction(n['onset']), generator.model.fraction(n['duration']), n['kind']) for n in events]