Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ly/musicxml/create_musicxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ def create_part(self, name="unnamed", abbr=False, midi=False):
self.part_count += 1
self.bar_nr = 1

def create_measure(self, **bar_attrs):
def create_measure(self, pickup = False, **bar_attrs):
"""Create new measure """
if pickup and self.bar_nr == 1:
self.bar_nr = 0
self.current_bar = etree.SubElement(self.current_part, "measure", number=str(self.bar_nr))
self.bar_nr +=1
if bar_attrs:
Expand Down
7 changes: 7 additions & 0 deletions ly/musicxml/ly2xml_mediator.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def __init__(self):
self.prev_tremolo = 8
self.tupl_dur = 0
self.tupl_sum = 0
self.bar_is_pickup = False

def new_header_assignment(self, name, value):
"""Distributing header information."""
Expand Down Expand Up @@ -309,11 +310,17 @@ def get_first_var(self):
if self.sections:
return self.sections[0].barlist

def set_pickup(self):
self.bar_is_pickup = True

def new_bar(self, fill_prev=True):
if self.bar and fill_prev:
self.bar.list_full = True
self.current_attr = xml_objs.BarAttr()
self.bar = xml_objs.Bar()
if self.bar_is_pickup:
self.bar.pickup = True
self.bar_is_pickup = False
self.bar.obj_list = [self.current_attr]
self.insert_into.barlist.append(self.bar)

Expand Down
7 changes: 7 additions & 0 deletions ly/musicxml/lymus2musxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def __init__(self):
self.slurcount = 0
self.slurnr = 0
self.phrslurnr = 0
self.pickup = False

def parse_text(self, ly_text, filename=None):
"""Parse the LilyPond source specified as text.
Expand Down Expand Up @@ -266,6 +267,9 @@ def Relative(self, relative):
r"""A \relative music expression."""
self.relative = True

def Partial(self, partial):
self.pickup = True

def Note(self, note):
""" notename, e.g. c, cis, a bes ... """
#print(note.token)
Expand Down Expand Up @@ -340,6 +344,9 @@ def Duration(self, duration):
elif self.tupl_span:
self.mediator.set_tuplspan_dur(duration.token, duration.tokens)
self.tupl_span = False
elif self.pickup:
self.mediator.set_pickup()
self.pickup = False
else:
self.mediator.new_duration_token(duration.token, duration.tokens)
if self.trem_rep:
Expand Down
3 changes: 2 additions & 1 deletion ly/musicxml/xml_objs.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def iterate_part(self, part):

def iterate_bar(self, bar):
"""The objects in the bar are output to the xml-file."""
self.musxml.create_measure()
self.musxml.create_measure(pickup = bar.pickup)
for obj in bar.obj_list:
if isinstance(obj, BarAttr):
self.new_xml_bar_attr(obj)
Expand Down Expand Up @@ -432,6 +432,7 @@ class Bar():
Contains also information about how complete it is."""
def __init__(self):
self.obj_list = []
self.pickup = False
self.list_full = False

def __repr__(self):
Expand Down
4 changes: 4 additions & 0 deletions tests/test_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def test_tuplet():
compare_output('tuplet')


def test_partial():
compare_output('partial')


def ly_to_xml(filename):
"""Read Lilypond file and return XML string."""
writer = ly.musicxml.writer()
Expand Down
5 changes: 5 additions & 0 deletions tests/test_xml_files/partial.ly
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
score{
\partial 8 f8 |
c2 d2 |
\partial 8 f8
}
71 changes: 71 additions & 0 deletions tests/test_xml_files/partial.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 2.0 Partwise//EN"
"http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise version="3.0">
<identification>
<encoding>
<software>python-ly 0.9.5</software>
<encoding-date>2017-05-28</encoding-date>
</encoding>
</identification>
<part-list>
<score-part id="P1">
<part-name />
</score-part>
</part-list>
<part id="P1">
<measure number="0">
<attributes>
<divisions>2</divisions>
<time symbol="common">
<beats>4</beats>
<beat-type>4</beat-type>
</time>
<clef>
<sign>G</sign>
<line>2</line>
</clef>
</attributes>
<note>
<pitch>
<step>F</step>
<octave>3</octave>
</pitch>
<duration>1</duration>
<voice>1</voice>
<type>eighth</type>
</note>
</measure>
<measure number="1">
<note>
<pitch>
<step>C</step>
<octave>3</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>half</type>
</note>
<note>
<pitch>
<step>D</step>
<octave>3</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>half</type>
</note>
</measure>
<measure number="2">
<note>
<pitch>
<step>F</step>
<octave>3</octave>
</pitch>
<duration>1</duration>
<voice>1</voice>
<type>eighth</type>
</note>
</measure>
</part>
</score-partwise>