Skip to content
Open
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
7 changes: 5 additions & 2 deletions ly/musicxml/ly2xml_mediator.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def __init__(self):
self.multiple_rest_bar = None
self.current_mark = 1
self.bar_is_pickup = False
self.obj_bar = None
self.stem_dir = None

def new_header_assignment(self, name, value):
Expand Down Expand Up @@ -335,6 +336,7 @@ def new_bar(self, fill_prev=True):
def add_to_bar(self, obj):
if self.bar is None:
self.new_bar()
self.obj_bar = self.bar
self.bar.add(obj)

def create_barline(self, bl):
Expand Down Expand Up @@ -636,8 +638,9 @@ def note2rest(self):
pos = [self.current_note.base_note, self.current_note.octave]
self.current_note = xml_objs.BarRest(dur, voice, pos=pos)
self.check_duration(rest=True)
self.bar.obj_list.pop()
self.bar.add(self.current_note)
# The note may have completed its bar, leaving self.bar on the next one.
self.obj_bar.obj_list.pop()
self.obj_bar.add(self.current_note)

def set_mult_rest(self):
self.multiple_rest = True
Expand Down
4 changes: 4 additions & 0 deletions tests/test_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def test_chord_duration():
compare_output('chord_duration')


def test_rest_command():
compare_output('rest_command')


def ly_to_xml(filename):
"""Read Lilypond file and return XML string."""
writer = ly.musicxml.writer()
Expand Down
12 changes: 12 additions & 0 deletions tests/test_xml_files/rest_command.ly
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
\version "2.22.2"

% \rest converts the note it follows where that note stands, even when the note
% completed the bar (issue #147)

\score {
\relative b' {
\time 2/4
b4. b8 \rest |
b8 \rest b8 b4
}
}
79 changes: 79 additions & 0 deletions tests/test_xml_files/rest_command.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?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.10</software>
<encoding-date>2026-08-18</encoding-date>
</encoding>
</identification>
<part-list>
<score-part id="P1">
<part-name />
</score-part>
</part-list>
<part id="P1">
<measure number="1">
<attributes>
<divisions>2</divisions>
<time>
<beats>2</beats>
<beat-type>4</beat-type>
</time>
<clef>
<sign>G</sign>
<line>2</line>
</clef>
</attributes>
<note>
<pitch>
<step>B</step>
<octave>4</octave>
</pitch>
<duration>3</duration>
<voice>1</voice>
<type>quarter</type>
<dot />
</note>
<note>
<rest>
<display-step>B</display-step>
<display-octave>4</display-octave>
</rest>
<duration>1</duration>
<voice>1</voice>
<type>eighth</type>
</note>
</measure>
<measure number="2">
<note>
<rest>
<display-step>B</display-step>
<display-octave>4</display-octave>
</rest>
<duration>1</duration>
<voice>1</voice>
<type>eighth</type>
</note>
<note>
<pitch>
<step>B</step>
<octave>4</octave>
</pitch>
<duration>1</duration>
<voice>1</voice>
<type>eighth</type>
</note>
<note>
<pitch>
<step>B</step>
<octave>4</octave>
</pitch>
<duration>2</duration>
<voice>1</voice>
<type>quarter</type>
</note>
</measure>
</part>
</score-partwise>
Loading