MusicXML export moves lower-staff text to staff 1 when no note or rest starts at its tick

Open Beginner friendly
#35,683 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp
Domain
backend

Research direction

Start in src/importexport/musicxml/internal/export/exportmusicxml.cpp, especially annotationsWithoutNote() and its call to commonAnnotations() when no note or rest starts at the annotation tick. The report identifies the fallback staff number as the source; trace how the annotation track maps to a part-relative staff. Done when the reproduction exports <staff>2</staff> for the lower-staff text and it remains on staff 2 after reimport.

Written by the indexing model from the issue text.

Description

needs review
Issue type

Import/export issue

Description with steps to reproduce
  1. Save the complete MusicXML below as lower-staff-text.musicxml and open it in MuseScore Studio. The text Lower staff only belongs to the lower staff, at beat 2 (where neither staff has a new note or rest).
  2. Export the score as uncompressed MusicXML and inspect the <direction> for that text.
  3. Open the exported MusicXML in MuseScore Studio.

Expected: The exported direction contains <staff>2</staff>, and the text remains on the lower staff at beat 2 after reimport.

Actual: The exported direction contains <staff>1</staff>. On reimport the text belongs to the upper staff. I checked the native score model before export and after reimport: the text changes from staff 2 to staff 1; the notes stay where they were.

Supporting files, videos and screenshots

Complete, schema-validated, one-measure reproduction (no other files needed):

<?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>4</divisions>
        <time><beats>4</beats><beat-type>4</beat-type></time>
        <staves>2</staves>
        <clef number="1"><sign>G</sign><line>2</line></clef>
        <clef number="2"><sign>F</sign><line>4</line></clef>
      </attributes>
      <note>
        <pitch><step>C</step><octave>5</octave></pitch>
        <duration>16</duration><voice>1</voice><type>whole</type><staff>1</staff>
      </note>
      <backup><duration>16</duration></backup>
      <direction placement="above">
        <direction-type><words>Lower staff only</words></direction-type>
        <offset sound="no">4</offset>
        <staff>2</staff>
      </direction>
      <note>
        <pitch><step>C</step><octave>3</octave></pitch>
        <duration>16</duration><voice>5</voice><type>whole</type><staff>2</staff>
      </note>
    </measure>
  </part>
</score-partwise>
In which versions of MuseScore Studio is this issue present?

Reproduced in 4.7.7 (revision b750c43). The same fallback is present in main at 6da159d; no nightly build was run.

Regression

I was unable to check.

Operating system

Windows 11

Additional context

In annotationsWithoutNote(), if there is no note or rest track for the annotation at that tick, commonAnnotations() is called with staves > 1 ? 1 : 0. In a multi-staff part that fallback writes staff 1 rather than deriving the part-relative staff from the annotation's own track. This concerns ordinary <direction><direction-type><words> staff text, not the chord symbols in #23240 or the voice-number issue #25663.

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.