Skip to content

Extra rest inserted when parsing MusicXML with backup/forward tags #1715

@werneta

Description

@werneta

music21 version

9.1.0

Problem summary
I'm working in MuseScore 4 and have a 4/4 measure with a double-dotted half note, followed by a clef change, followed by an eighth note:
image

When I convert this to MusicXML and import it with music21, there is an extra rest inserted after the clef change. It looks like it's related to <backup> and <forward> tags that are MuseScore adds around the clef change.

Steps to reproduce
Use this file (remove the .txt) from the file name:
clef_change_backup.musicxml.txt

import music21
fname = 'clef_change_backup.musicxml'
x = music21.converter.parseFile(fname)
list(x[1][1])

Expected vs. actual behavior

[<music21.clef.TrebleClef>,
 <music21.key.KeySignature of no sharps or flats>,
 <music21.meter.TimeSignature 4/4>,
 <music21.note.Note C>,
 <music21.clef.BassClef>,
 <music21.note.Rest dotted-quarter>, # Not expected
 <music21.note.Note C>,
 <music21.bar.Barline type=final>]

More information

I tried removing the <backup> and <forward> tags in the XML:

      <note>
        <pitch>
          <step>C</step>
          <octave>5</octave>
          </pitch>
        <duration>7</duration>
        <voice>1</voice>
        <type>half</type>
        <dot/>
        <dot/>
        <stem>down</stem>
        </note>
      <backup> <!-- Removed this element -->
        <duration>3</duration>
        </backup>
      <attributes>
        <clef>
          <sign>F</sign>
          <line>4</line>
          </clef>
        </attributes>
      <forward> <!-- Removed this element -->
        <duration>3</duration>
        </forward>
      <note>
        <pitch>
          <step>C</step>
          <octave>3</octave>
          </pitch>
        <duration>1</duration>
        <voice>1</voice>
        <type>eighth</type>
        <stem>up</stem>
        </note>

and saved it as this file: clef_change_nobackup.musicxml.txt

Rerunning the previous steps generates the expected output:

[<music21.clef.TrebleClef>,
 <music21.key.KeySignature of no sharps or flats>,
 <music21.meter.TimeSignature 4/4>,
 <music21.note.Note C>,
 <music21.clef.BassClef>,
 <music21.note.Note C>,
 <music21.bar.Barline type=final>]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions