@@ -201,13 +201,10 @@ def write_note(parent, event: dict, voice: str, divisions: int, tuplets: list[di
|
||||
for syllable in verse['syllables']:
|
||||
element(lyric, syllable['kind'], syllable['text'], **syllable['attributes'])
|
||||
|
||||
def musicxml_tree(document: dict, *, engine_voices: bool = False) -> ElementTree.ElementTree:
|
||||
def musicxml_tree(document: dict) -> ElementTree.ElementTree:
|
||||
validate_document(document)
|
||||
root = ElementTree.Element('score-partwise', {'version': '4.0'})
|
||||
metadata, staff = document['metadata'], document['staves'][0]
|
||||
voice_ids = list(dict.fromkeys(v['id'] for m in staff['measures'] for v in m['voices'] if v['id'] != 'voice-arranged'))
|
||||
voice_slots = {identifier: str(index + 1) for index, identifier in enumerate(voice_ids)}
|
||||
voice_slots['voice-arranged'] = '1'
|
||||
element(element(root, 'work'), 'work-title', metadata['title'])
|
||||
identification = element(root, 'identification')
|
||||
element(identification, 'creator', metadata.get('composer', ''), type='composer')
|
||||
@@ -300,7 +297,7 @@ def musicxml_tree(document: dict, *, engine_voices: bool = False) -> ElementTree
|
||||
onset = fraction(event['onset'])
|
||||
if onset > cursor:
|
||||
element(element(bar, 'forward'), 'duration', int((onset - cursor) * divisions))
|
||||
write_note(bar, event, voice_slots[voice['id']] if engine_voices else voice['id'], divisions, staff.get('tuplets', []))
|
||||
write_note(bar, event, voice['id'], divisions, staff.get('tuplets', []))
|
||||
cursor = onset + fraction(event['duration'])
|
||||
if cursor < fraction(measure['duration']):
|
||||
element(element(bar, 'forward'), 'duration', int((fraction(measure['duration']) - cursor) * divisions))
|
||||
@@ -310,7 +307,7 @@ def musicxml_tree(document: dict, *, engine_voices: bool = False) -> ElementTree
|
||||
absolute += fraction(measure['duration'])
|
||||
return ElementTree.ElementTree(root)
|
||||
|
||||
def write_musicxml(path: Path, document: dict, *, engine_voices: bool = False) -> None:
|
||||
tree = musicxml_tree(document, engine_voices=engine_voices)
|
||||
def write_musicxml(path: Path, document: dict) -> None:
|
||||
tree = musicxml_tree(document)
|
||||
ElementTree.indent(tree, space=' ')
|
||||
tree.write(path, encoding='utf-8', xml_declaration=True)
|
||||
|
||||
Reference in New Issue
Block a user