Skip to content

Commit 0fac9b5

Browse files
committed
MusicXML: Recognize \break
Recognize the \break command by adding a <print new-system="yes" /> to the beginning of a bar. See http://usermanuals.musicxml.com/MusicXML/MusicXML.htm#EL-MusicXML-print.htm
1 parent 1cd3260 commit 0fac9b5

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

ly/musicxml/create_musicxml.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def create_part(self, name="unnamed", abbr=False, midi=False):
115115
def create_measure(self, **bar_attrs):
116116
"""Create new measure """
117117
self.current_bar = etree.SubElement(self.current_part, "measure", number=str(self.bar_nr))
118+
self.current_print = None
118119
self.bar_nr +=1
119120
if bar_attrs:
120121
self.new_bar_attr(**bar_attrs)
@@ -626,6 +627,13 @@ def add_lyric(self, txt, syll, nr, ext=False):
626627
if ext:
627628
etree.SubElement(lyricnode, "extend")
628629

630+
def new_system(self):
631+
if not self.current_print:
632+
self.create_print()
633+
self.current_print.attrib["new-system"] = "yes"
634+
635+
def create_print(self):
636+
self.current_print = etree.SubElement(self.current_bar, "print")
629637

630638
##
631639
# Create the XML document

ly/musicxml/ly2xml_mediator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,10 @@ def new_lyrics_item(self, item):
829829
elif item == '\\skip':
830830
self.insert_into.barlist.append("skip")
831831

832+
def line_break(self):
833+
if self.bar:
834+
self.bar.line_break = True
835+
832836
def duration_from_tokens(self, tokens):
833837
"""Calculate dots and multibar rests from tokens."""
834838
dots = 0

ly/musicxml/lymus2musxml.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,8 @@ def Command(self, command):
497497
if self.tupl_span:
498498
self.mediator.unset_tuplspan_dur()
499499
self.tupl_span = False
500+
elif command.token == '\\break':
501+
self.mediator.line_break()
500502
else:
501503
if command.token not in excls:
502504
print("Unknown command:", command.token)

ly/musicxml/xml_objs.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ def iterate_part(self, part):
103103
def iterate_bar(self, bar):
104104
"""The objects in the bar are output to the xml-file."""
105105
self.musxml.create_measure()
106+
107+
if bar.line_break:
108+
self.musxml.new_system()
109+
106110
for obj in bar.obj_list:
107111
if isinstance(obj, BarAttr):
108112
self.new_xml_bar_attr(obj)
@@ -433,6 +437,7 @@ class Bar():
433437
def __init__(self):
434438
self.obj_list = []
435439
self.list_full = False
440+
self.line_break = False
436441

437442
def __repr__(self):
438443
return '<{0} {1}>'.format(self.__class__.__name__, self.obj_list)
@@ -478,6 +483,10 @@ def inject_voice(self, new_voice, override=False):
478483
""" Adding new voice to bar.
479484
Omitting double or conflicting bar attributes as long as override is false.
480485
Omitting also bars with only skips."""
486+
487+
if new_voice.line_break:
488+
self.line_break = True
489+
481490
if new_voice.obj_list[0].has_attr():
482491
if self.obj_list[0].has_attr():
483492
self.obj_list[0].merge_attr(new_voice.obj_list[0], override)

0 commit comments

Comments
 (0)