Skip to content

Commit e4b3258

Browse files
authored
Merge pull request #97 from FelippeRoza/break-export
\break export to MusicXML
2 parents 1f81db6 + 5cac5cd commit e4b3258

7 files changed

Lines changed: 127 additions & 0 deletions

File tree

ly/musicxml/create_musicxml.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,9 @@ def add_clef(self, sign, line, nr=0, oct_ch=0):
536536
octchnode = etree.SubElement(clefnode, "clef-octave-change")
537537
octchnode.text = str(oct_ch)
538538

539+
def new_system(self, force_break):
540+
etree.SubElement(self.current_bar, "print", {'new-system':force_break})
541+
539542
def add_barline(self, bl_type, repeat=None):
540543
barnode = etree.SubElement(self.current_bar, "barline", location="right")
541544
barstyle = etree.SubElement(barnode, "bar-style")

ly/musicxml/ly2xml_mediator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,10 @@ def check_divs(self):
888888
mult = get_mult(a, b)
889889
self.divisions = divs*mult
890890

891+
def add_break(self):
892+
if self.bar is None:
893+
self.new_bar()
894+
self.current_attr.add_break('yes')
891895

892896

893897
##

ly/musicxml/lymus2musxml.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,8 @@ def Command(self, command):
506506
if self.tupl_span:
507507
self.mediator.unset_tuplspan_dur()
508508
self.tupl_span = False
509+
elif command.token == '\\break':
510+
self.mediator.add_break()
509511
else:
510512
if command.token not in excls:
511513
print("Unknown command:", command.token)

ly/musicxml/xml_objs.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ def new_xml_bar_attr(self, obj):
122122
"""Create bar attribute xml-nodes."""
123123
if obj.has_attr():
124124
self.musxml.new_bar_attr(obj.clef, obj.time, obj.key, obj.mode, obj.divs)
125+
if obj.new_system:
126+
self.musxml.new_system(obj.new_system)
125127
if obj.repeat:
126128
self.musxml.add_barline(obj.barline, obj.repeat)
127129
elif obj.barline:
@@ -731,10 +733,14 @@ def __init__(self):
731733
self.staves = 0
732734
self.multiclef = []
733735
self.tempo = None
736+
self.new_system = None
734737

735738
def __repr__(self):
736739
return '<{0} {1}>'.format(self.__class__.__name__, self.time)
737740

741+
def add_break(self, force_break):
742+
self.new_system = force_break
743+
738744
def set_key(self, muskey, mode):
739745
self.key = muskey
740746
self.mode = mode

tests/test_xml.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ def test_dynamics():
3030
def test_tuplet():
3131
compare_output('tuplet')
3232

33+
def test_break():
34+
compare_output('break')
3335

3436
def test_partial():
3537
compare_output('partial')

tests/test_xml_files/break.ly

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
\relative c'' {
2+
c4 c c c | \break
3+
c4 c c c |
4+
}

tests/test_xml_files/break.xml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 2.0 Partwise//EN"
3+
"http://www.musicxml.org/dtds/partwise.dtd">
4+
<score-partwise version="3.0">
5+
<identification>
6+
<encoding>
7+
<software>python-ly 0.9.5</software>
8+
<encoding-date>2017-05-14</encoding-date>
9+
</encoding>
10+
</identification>
11+
<part-list>
12+
<score-part id="P1">
13+
<part-name />
14+
</score-part>
15+
</part-list>
16+
<part id="P1">
17+
<measure number="1">
18+
<attributes>
19+
<divisions>1</divisions>
20+
<time symbol="common">
21+
<beats>4</beats>
22+
<beat-type>4</beat-type>
23+
</time>
24+
<clef>
25+
<sign>G</sign>
26+
<line>2</line>
27+
</clef>
28+
</attributes>
29+
<note>
30+
<pitch>
31+
<step>C</step>
32+
<octave>5</octave>
33+
</pitch>
34+
<duration>1</duration>
35+
<voice>1</voice>
36+
<type>quarter</type>
37+
</note>
38+
<note>
39+
<pitch>
40+
<step>C</step>
41+
<octave>5</octave>
42+
</pitch>
43+
<duration>1</duration>
44+
<voice>1</voice>
45+
<type>quarter</type>
46+
</note>
47+
<note>
48+
<pitch>
49+
<step>C</step>
50+
<octave>5</octave>
51+
</pitch>
52+
<duration>1</duration>
53+
<voice>1</voice>
54+
<type>quarter</type>
55+
</note>
56+
<note>
57+
<pitch>
58+
<step>C</step>
59+
<octave>5</octave>
60+
</pitch>
61+
<duration>1</duration>
62+
<voice>1</voice>
63+
<type>quarter</type>
64+
</note>
65+
</measure>
66+
<measure number="2">
67+
<note>
68+
<pitch>
69+
<step>C</step>
70+
<octave>5</octave>
71+
</pitch>
72+
<duration>1</duration>
73+
<voice>1</voice>
74+
<type>quarter</type>
75+
</note>
76+
<note>
77+
<pitch>
78+
<step>C</step>
79+
<octave>5</octave>
80+
</pitch>
81+
<duration>1</duration>
82+
<voice>1</voice>
83+
<type>quarter</type>
84+
</note>
85+
<note>
86+
<pitch>
87+
<step>C</step>
88+
<octave>5</octave>
89+
</pitch>
90+
<duration>1</duration>
91+
<voice>1</voice>
92+
<type>quarter</type>
93+
</note>
94+
<note>
95+
<pitch>
96+
<step>C</step>
97+
<octave>5</octave>
98+
</pitch>
99+
<duration>1</duration>
100+
<voice>1</voice>
101+
<type>quarter</type>
102+
</note>
103+
</measure>
104+
<measure number="3" />
105+
</part>
106+
</score-partwise>

0 commit comments

Comments
 (0)