Skip to content

Commit

Permalink
Fix GH#26494: MusicXML Import - Beams don't have their colour imported
Browse files Browse the repository at this point in the history
'Backport' of musescore#26495, 1st commit

Current restriction: doesn't work for grace note beams
Further restriction: if in the MusicXML different colors are set for different strokes of a beam, like for 16ths' beams' upper and lower stroke, the last color wins, MuseScore does not allow for this, it colors the entire beam, not single strokes of it.
  • Loading branch information
Jojo-Schmitz committed Feb 14, 2025
1 parent ff83653 commit f1db51b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 13 deletions.
11 changes: 8 additions & 3 deletions importexport/musicxml/importmxmlpass2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2486,7 +2486,7 @@ static void removeBeam(Beam*& beam)
// handleBeamAndStemDir
//---------------------------------------------------------

static void handleBeamAndStemDir(ChordRest* cr, const Beam::Mode bm, const Direction sd, Beam*& beam, bool hasBeamingInfo)
static void handleBeamAndStemDir(ChordRest* cr, const Beam::Mode bm, const Direction sd, Beam*& beam, bool hasBeamingInfo, QColor beamColor)
{
if (!cr) return;
// create a new beam
Expand All @@ -2500,6 +2500,8 @@ static void handleBeamAndStemDir(ChordRest* cr, const Beam::Mode bm, const Direc
beam = new Beam(cr->score());
beam->setTrack(cr->track());
beam->setBeamDirection(sd);
if (beamColor.isValid()/* && preferences.getBool(PREF_IMPORT_MUSICXML_IMPORTLAYOUT)*/)
beam->setColor(beamColor);
}
// add ChordRest to beam
if (beam) {
Expand Down Expand Up @@ -6169,6 +6171,7 @@ Note* MusicXMLParserPass2::note(const QString& partId,
const QColor noteColor = _e.attributes().value("color").toString();
QColor noteheadColor = QColor::Invalid;
QColor stemColor = QColor::Invalid;
QColor beamColor = QColor::Invalid;
bool noteheadParentheses = false;
QString noteheadFilled;
int velocity = round(_e.attributes().value("dynamics").toDouble() * 0.9);
Expand All @@ -6191,8 +6194,10 @@ Note* MusicXMLParserPass2::note(const QString& partId,
else if (mnd.readProperties(_e)) {
// element handled
}
else if (_e.name() == "beam")
else if (_e.name() == "beam") {
beamColor.setNamedColor(_e.attributes().value("color").toString());
beam(beamTypes);
}
else if (_e.name() == "chord") {
chord = true;
_e.skipCurrentElement(); // skip but don't log
Expand Down Expand Up @@ -6449,7 +6454,7 @@ Note* MusicXMLParserPass2::note(const QString& partId,
// regular note
// handle beam
if (!chord)
handleBeamAndStemDir(c, bm, stemDir, currBeam, _pass1.hasBeamingInfo());
handleBeamAndStemDir(c, bm, stemDir, currBeam, _pass1.hasBeamingInfo(), beamColor);

// append any grace chord after chord to the previous chord
Chord*const prevChord = measure->findChord(prevSTime, msTrack + msVoice);
Expand Down
60 changes: 50 additions & 10 deletions mtest/musicxml/io/testColors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<part id="P1">
<measure number="1">
<attributes>
<divisions>1</divisions>
<divisions>4</divisions>
<key color="#00FDFF">
<fifths>-1</fifths>
</key>
Expand All @@ -53,7 +53,7 @@
<step>D</step>
<octave>4</octave>
</pitch>
<duration>1</duration>
<duration>4</duration>
<voice>1</voice>
<type>quarter</type>
<stem>down</stem>
Expand All @@ -66,7 +66,7 @@
<step>G</step>
<octave>4</octave>
</pitch>
<duration>1</duration>
<duration>4</duration>
<voice>1</voice>
<type>quarter</type>
<stem>down</stem>
Expand All @@ -83,7 +83,7 @@
<step>E</step>
<octave>4</octave>
</pitch>
<duration>1</duration>
<duration>4</duration>
<voice>1</voice>
<type>quarter</type>
<stem>down</stem>
Expand All @@ -96,7 +96,7 @@
<step>A</step>
<octave>4</octave>
</pitch>
<duration>1</duration>
<duration>4</duration>
<voice>1</voice>
<type>quarter</type>
<stem>down</stem>
Expand All @@ -118,7 +118,7 @@
<step>G</step>
<octave>4</octave>
</pitch>
<duration>1</duration>
<duration>4</duration>
<voice>1</voice>
<type>quarter</type>
<stem color="#2468AC">down</stem>
Expand All @@ -131,7 +131,7 @@
<step>A</step>
<octave>4</octave>
</pitch>
<duration>1</duration>
<duration>4</duration>
<voice>1</voice>
<type>quarter</type>
<stem>down</stem>
Expand All @@ -141,7 +141,7 @@
<step>B</step>
<octave>4</octave>
</pitch>
<duration>1</duration>
<duration>4</duration>
<voice>1</voice>
<type>quarter</type>
<accidental color="#0F12A7">natural</accidental>
Expand All @@ -158,7 +158,7 @@
<alter>1</alter>
<octave>5</octave>
</pitch>
<duration>1</duration>
<duration>4</duration>
<voice>1</voice>
<type>quarter</type>
<accidental color="#A632F0">sharp</accidental>
Expand All @@ -176,7 +176,7 @@
<step>D</step>
<octave>5</octave>
</pitch>
<duration>4</duration>
<duration>16</duration>
<voice>1</voice>
<type>whole</type>
<notehead color="#9437FF">normal</notehead>
Expand All @@ -185,5 +185,45 @@
</notations>
</note>
</measure>
<measure number="4">
<note>
<pitch>
<step>D</step>
<octave>5</octave>
</pitch>
<duration>2</duration>
<voice>1</voice>
<type>eighth</type>
<stem>down</stem>
<notehead color="#9437FF">normal</notehead>
<beam number="1" color="#FF0000">begin</beam>
</note>
<note>
<pitch>
<step>D</step>
<octave>5</octave>
</pitch>
<duration>1</duration>
<voice>1</voice>
<type>16th</type>
<stem>down</stem>
<notehead color="#9437FF">normal</notehead>
<beam number="1">continue</beam>
<beam number="2" color="#FF0000">begin</beam>
</note>
<note>
<pitch>
<step>D</step>
<octave>5</octave>
</pitch>
<duration>1</duration>
<voice>1</voice>
<type>16th</type>
<stem>down</stem>
<notehead color="#9437FF">normal</notehead>
<beam number="1">end</beam>
<beam number="2">end</beam>
</note>
</measure>
</part>
</score-partwise>

0 comments on commit f1db51b

Please sign in to comment.