MusicXML import attaches after-graces at the end of a voice to the first note of the next voice/staff after <backup>

Open
#35,730 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp, xml
Domain
data, desktop

Research direction

Start by reproducing the provided MusicXML with MuseScore4.exe -o out.mscz grace-after-backup.musicxml, then read the grace-note handling in importmusicxmlpass2.cpp around gcl/gac, addGraceChordsAfter(), addGraceChordsBefore(), and the <backup> branch. Check how pending after-graces are flushed at voice/track changes rather than only at measure end. Done means the D5 grace imports as <grace16after/> on the voice 1 C5 while the listed controls and normal before-graces still behave.

Written by the indexing model from the issue text.

Description

community MusicXML
Issue type

Import/export issue

Description with steps to reproduce

When a voice ends with grace notes after its last principal note and the measure continues with a <backup> into another voice (or another staff of the same part), the MusicXML importer attaches those grace notes as before-graces to the first note of the following voice/staff instead of as after-graces to the preceding chord in their own voice.

This also breaks MuseScore's own roundtrip: MuseScore Studio exports after-graces as bare <grace/> at the end of their voice, immediately before <backup>. Re-importing such an export of a piano score moves the after-graces from voice 1 / staff 1 onto the first note of staff 2 as <grace16/> before-graces.

Steps:

  1. Save the MusicXML below as grace-after-backup.musicxml.
  2. Open it in MuseScore Studio 4.7.7 (or MuseScore4.exe -o out.mscz grace-after-backup.musicxml) and inspect the result.
<?xml version="1.0" encoding="UTF-8"?>
<score-partwise version="4.0">
  <part-list><score-part id="P1"><part-name>Piano</part-name></score-part></part-list>
  <part id="P1">
    <measure number="1">
      <attributes><divisions>1</divisions><time><beats>4</beats><beat-type>4</beat-type></time><staves>1</staves>
        <clef number="1"><sign>G</sign><line>2</line></clef></attributes>
      <note><pitch><step>C</step><octave>5</octave></pitch><duration>4</duration><voice>1</voice><type>whole</type><staff>1</staff></note>
      <note><grace/><pitch><step>D</step><octave>5</octave></pitch><voice>1</voice><type>16th</type><staff>1</staff></note>
      <backup><duration>4</duration></backup>
      <note><pitch><step>A</step><octave>4</octave></pitch><duration>4</duration><voice>2</voice><type>whole</type><staff>1</staff></note>
    </measure>
  </part>
</score-partwise>

Expected: D5 is a grace-note-after (<grace16after/>) of the voice 1 C5.

Actual: D5 is imported as a before-grace (<grace16/>) of the voice 2 A4.

Controls (all with MuseScore Studio 4.7.7):

  • Removing the <backup> and the voice 2 note: D5 is correctly imported as <grace16after/> of C5 (the end-of-measure conversion applies).
  • Changing <grace/> to <grace steal-time-previous="25"/>: still imported as a before-grace of the voice 2 A4.
  • Same as the example, but with two staves and the second note in voice 5 / staff 2: D5 ends up as a before-grace on staff 2.

Possible cause (based on reading importmusicxmlpass2.cpp at 08d70c1): the pending grace chord list gcl/gac is shared across voices within the measure. When the next regular note arrives in another track, measure->findChord(prevSTime, msTrack + msVoice) finds no previous chord in that track, so addGraceChordsAfter() is skipped and addGraceChordsBefore(c, gcl) attaches the pending graces to the new note. Pending after-graces are only flushed at the end of the measure, not on <backup>/voice change.

Supporting files, videos and screenshots

The minimal example is included inline above.

What is the latest version of MuseScore Studio where this issue is present?

4.7.7 (revision b750c43)

Regression

I don't know

Operating system

Windows 11 (10.0.26300)

Additional context

Related but different: #34140 (closed; slur-based after-grace detection) and #35700 (mid-measure grace group with an intra-grace slur).

Checklist
  • This report follows the guidelines for reporting bugs and issues
  • I have verified that this issue has not been logged before, by searching the issue tracker for similar issues
  • I have attached all requested files and information to this report
  • I have attempted to identify the root problem as concisely as possible, and have used minimal reproducible examples where possible
Dominant language
C++
Stars
15.5k
Forks
3.5k
Avg merge
2d 19h
Merged PRs (30d)
124

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from musescore/MuseScore

All issues in musescore/MuseScore

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.