Skip to content

Commit

Permalink
Reset offset when placement is changed
Browse files Browse the repository at this point in the history
Backport of musescore#25014 plus 2 more small changes, one apparently an ommision from #444, which backported musescore#22577, the other stems from musescore#22740, which I haven't backported (yet).

Update testPlacementOffsetDefaults_ref.mscx
  • Loading branch information
miiizen authored and Jojo-Schmitz committed Oct 2, 2024
1 parent 0eccb13 commit 801715b
Show file tree
Hide file tree
Showing 4 changed files with 443 additions and 10 deletions.
35 changes: 25 additions & 10 deletions importexport/musicxml/importmxmlpass2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,8 @@ static void addElemOffset(Element* el, int track, const QString& placement, Meas
if (!placement.isEmpty()) {
el->setPlacement(placement == "above" ? Placement::ABOVE : Placement::BELOW);
el->setPropertyFlags(Pid::PLACEMENT, PropertyFlags::UNSTYLED);
if (!el->isSticking())
el->resetProperty(Pid::OFFSET);
}


Expand Down Expand Up @@ -1101,8 +1103,10 @@ static void addFermataToChord(const Notation& notation, ChordRest* cr)
na->setTrack(cr->track());
if (color.isValid()/* && preferences.getBool(PREF_IMPORT_MUSICXML_IMPORTLAYOUT)*/)
na->setColor(color);
if (!direction.isEmpty())
if (!direction.isEmpty()) {
na->setPlacement(direction == "inverted" ? Placement::BELOW : Placement::ABOVE);
na->resetProperty(Pid::OFFSET);
}
else
na->setPlacement(na->propertyDefault(Pid::PLACEMENT).value<Placement>());
setElementPropertyFlags(na, Pid::PLACEMENT, direction);
Expand Down Expand Up @@ -1373,6 +1377,7 @@ static void addTextToNote(int l, int c, QString txt, QString placement, QString
if (!placement.isEmpty()) {
t->setPlacement(placement == "below" ? Placement::BELOW : Placement::ABOVE);
t->setPropertyFlags(Pid::PLACEMENT, PropertyFlags::UNSTYLED);
t->resetProperty(Pid::OFFSET);
}
if (color.isValid()) {
t->setColor(color);
Expand Down Expand Up @@ -1427,6 +1432,7 @@ static void setSLinePlacement(SLine* sli, const QString placement)
if (placement == "above" || placement == "below") {
sli->setPlacement(placement == "above" ? Placement::ABOVE : Placement::BELOW);
sli->setPropertyFlags(Pid::PLACEMENT, PropertyFlags::UNSTYLED);
sli->resetProperty(Pid::OFFSET);
}
}

Expand Down Expand Up @@ -3324,6 +3330,7 @@ void MusicXMLParserDirection::direction(const QString& partId,
if (!_hasDefaultY) {
t->setPlacement(Placement::ABOVE); // crude way to force placement TODO improve ?
t->setPropertyFlags(Pid::PLACEMENT, PropertyFlags::UNSTYLED);
t->resetProperty(Pid::OFFSET);
}
}

Expand Down Expand Up @@ -4263,7 +4270,8 @@ void MusicXMLParserDirection::handleRepeats(Measure* measure, const int track, c
tb->setSize(symSize);
tb->setPropertyFlags(Pid::FONT_SIZE, PropertyFlags::UNSTYLED);
}
else tb->setVisible(false);
else
tb->setVisible(false);

// Sometimes Jumps and Markers are exported on the incorrect side
// of the barline (i.e. end of mm. 29 vs. beginning of mm. 30).
Expand Down Expand Up @@ -4316,6 +4324,8 @@ void MusicXMLParserDirection::handleChordSym(const int track, const Fraction tic
ha->setTrack(track);
ha->setPlacement(placement() == "above" ? Placement::ABOVE : Placement::BELOW);
ha->setPropertyFlags(Pid::PLACEMENT, PropertyFlags::UNSTYLED);
ha->resetProperty(Pid::OFFSET);
ha->setVisible(_visible);
HarmonyDesc newHarmonyDesc(track, ha, nullptr);

const int ticks = tick.ticks();
Expand Down Expand Up @@ -4946,18 +4956,18 @@ void MusicXMLParserPass2::barline(const QString& partId, Measure* measure, const
segment->add(fermata);
if (fermataColor.isValid())
fermata->setColor(fermataColor);
if (fermataType == "inverted")
if (fermataType == "inverted") {
fermata->setPlacement(Placement::BELOW);
else if (fermataType.isEmpty()) {
fermata->setPlacement(fermata->propertyDefault(Pid::PLACEMENT).value<Placement>());
fermata->resetProperty(Pid::OFFSET);
}
else if (fermataType.isEmpty())
fermata->setPlacement(fermata->propertyDefault(Pid::PLACEMENT).value<Placement>());
}
else if (_e.name() == "repeat") {
repeat = _e.attributes().value("direction").toString();
count = _e.attributes().value("times").toString();
if (count.isEmpty()) {
count = "2";
}
if (count.isEmpty())
count = "2";
measure->setRepeatCount(count.toInt());
_e.skipCurrentElement();
}
Expand Down Expand Up @@ -6674,6 +6684,7 @@ FiguredBass* MusicXMLParserPass2::figuredBass()

fb->setPlacement(placement == "above" ? Placement::ABOVE : Placement::BELOW);
fb->setPropertyFlags(Pid::PLACEMENT, PropertyFlags::UNSTYLED);
fb->resetProperty(Pid::OFFSET);

if (normalizedText.isEmpty()) {
delete fb;
Expand Down Expand Up @@ -6850,6 +6861,7 @@ void MusicXMLParserPass2::harmony(const QString& partId, Measure* measure, const
if (!placement.isEmpty()) {
ha->setPlacement(placement == "below" ? Placement::BELOW : Placement::ABOVE);
ha->setPropertyFlags(Pid::PLACEMENT, PropertyFlags::UNSTYLED);
ha->resetProperty(Pid::OFFSET);
}
else if (hasTotalY) {
ha->setPlacement(totalY > 0 ? Placement::BELOW : Placement::ABOVE);
Expand Down Expand Up @@ -6993,8 +7005,10 @@ void MusicXMLParserPass2::harmony(const QString& partId, Measure* measure, const
ha->render();

ha->setVisible(printObject);
if (placement == "below")
if (placement == "below") {
ha->setPlacement(Placement::BELOW);
ha->resetProperty(Pid::OFFSET);
}
if (color.isValid()/* && preferences.getBool(PREF_IMPORT_MUSICXML_IMPORTLAYOUT)*/) {
ha->setColor(color);
ha->setPropertyFlags(Pid::COLOR, PropertyFlags::UNSTYLED);
Expand Down Expand Up @@ -7197,9 +7211,10 @@ void MusicXMLParserLyric::parse()
if (!placement.isEmpty()) {
lyric->setPlacement(placement == "above" ? Placement::ABOVE : Placement::BELOW);
lyric->setPropertyFlags(Pid::PLACEMENT, PropertyFlags::UNSTYLED);
lyric->resetProperty(Pid::OFFSET);
}

if (relX != 0 || relY != 0) {
if (!qFuzzyIsNull(relX) || !qFuzzyIsNull(relY)) {
QPointF offset = lyric->offset();
offset.setX(relX != 0 ? relX : lyric->offset().x());
offset.setY(relY != 0 ? relY : lyric->offset().y());
Expand Down
194 changes: 194 additions & 0 deletions mtest/musicxml/io/testPlacementOffsetDefaults.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 4.0 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise version="4.0">
<work>
<work-title>Untitled score</work-title>
</work>
<identification>
<creator type="composer">Composer / arranger</creator>
<encoding>
<software>MuseScore 4.4.1</software>
<encoding-date>2024-09-08</encoding-date>
<supports element="accidental" type="yes"/>
<supports element="beam" type="yes"/>
<supports element="print" attribute="new-page" type="yes" value="yes"/>
<supports element="print" attribute="new-system" type="yes" value="yes"/>
<supports element="stem" type="yes"/>
</encoding>
</identification>
<defaults>
<scaling>
<millimeters>6.99911</millimeters>
<tenths>40</tenths>
</scaling>
<page-layout>
<page-height>1696.94</page-height>
<page-width>1200.48</page-width>
<page-margins type="even">
<left-margin>85.7252</left-margin>
<right-margin>85.7252</right-margin>
<top-margin>85.7252</top-margin>
<bottom-margin>85.7252</bottom-margin>
</page-margins>
<page-margins type="odd">
<left-margin>85.7252</left-margin>
<right-margin>85.7252</right-margin>
<top-margin>85.7252</top-margin>
<bottom-margin>85.7252</bottom-margin>
</page-margins>
</page-layout>
<appearance>
<line-width type="light barline">1.8</line-width>
<line-width type="heavy barline">5.5</line-width>
<line-width type="beam">5</line-width>
<line-width type="bracket">4.5</line-width>
<line-width type="dashes">1</line-width>
<line-width type="enclosure">1</line-width>
<line-width type="ending">1.1</line-width>
<line-width type="extend">1</line-width>
<line-width type="leger">1.6</line-width>
<line-width type="pedal">1.1</line-width>
<line-width type="octave shift">1.1</line-width>
<line-width type="slur middle">2.1</line-width>
<line-width type="slur tip">0.5</line-width>
<line-width type="staff">1.1</line-width>
<line-width type="stem">1</line-width>
<line-width type="tie middle">2.1</line-width>
<line-width type="tie tip">0.5</line-width>
<line-width type="tuplet bracket">1</line-width>
<line-width type="wedge">1.2</line-width>
<note-size type="cue">70</note-size>
<note-size type="grace">70</note-size>
<note-size type="grace-cue">49</note-size>
</appearance>
<music-font font-family="Leland"/>
<word-font font-family="Edwin" font-size="10"/>
<lyric-font font-family="Edwin" font-size="10"/>
</defaults>
<credit page="1">
<credit-type>title</credit-type>
<credit-words default-x="600.241935" default-y="1611.210312" justify="center" valign="top" font-size="22">Untitled score</credit-words>
</credit>
<credit page="1">
<credit-type>subtitle</credit-type>
<credit-words default-x="600.241935" default-y="1554.060198" justify="center" valign="top" font-size="14">Subtitle</credit-words>
</credit>
<credit page="1">
<credit-type>composer</credit-type>
<credit-words default-x="1114.7587" default-y="1511.210312" justify="right" valign="bottom">Composer / arranger</credit-words>
</credit>
<part-list>
<score-part id="P1">
<part-name>Voice</part-name>
<part-abbreviation>Vo.</part-abbreviation>
<score-instrument id="P1-I1">
<instrument-name>Voice</instrument-name>
<instrument-sound>voice.vocals</instrument-sound>
</score-instrument>
<midi-device id="P1-I1" port="1"></midi-device>
<midi-instrument id="P1-I1">
<midi-channel>1</midi-channel>
<midi-program>53</midi-program>
<volume>78.7402</volume>
<pan>0</pan>
</midi-instrument>
</score-part>
</part-list>
<part id="P1">
<measure number="1" width="519.24">
<print>
<system-layout>
<system-margins>
<left-margin>50</left-margin>
<right-margin>0</right-margin>
</system-margins>
<top-system-distance>170</top-system-distance>
</system-layout>
</print>
<attributes>
<divisions>1</divisions>
<key>
<fifths>0</fifths>
</key>
<time>
<beats>4</beats>
<beat-type>4</beat-type>
</time>
<clef>
<sign>G</sign>
<line>2</line>
</clef>
</attributes>
<note default-x="282.33" default-y="-10">
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
<lyric number="1" default-y="-80" placement="below">
<syllabic>single</syllabic>
<text>Lyrics</text>
</lyric>
</note>
</measure>
<measure number="2" width="459.79">
<note default-x="222.5" default-y="-10">
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
<lyric number="1" default-y="-80" placement="below" relative-x="10">
<syllabic>single</syllabic>
<text>lyrics</text>
</lyric>
</note>
</measure>
<measure number="3" width="533.18">
<print new-system="yes">
<system-layout>
<system-margins>
<left-margin>0</left-margin>
<right-margin>-0</right-margin>
</system-margins>
<system-distance>205</system-distance>
</system-layout>
</print>
<note default-x="275.74" default-y="-10">
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
<lyric number="1" default-y="40" placement="above">
<syllabic>single</syllabic>
<text>lyrics</text>
</lyric>
</note>
</measure>
<measure number="4" width="495.85">
<note default-x="240.53" default-y="-10">
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
<lyric number="1" default-y="40" placement="above" relative-x="10">
<syllabic>single</syllabic>
<text>lyrics</text>
</lyric>
</note>
</measure>
<measure number="5" width="125.59">
<print new-system="yes">
<system-layout>
<system-margins>
<left-margin>0</left-margin>
<right-margin>903.44</right-margin>
</system-margins>
<system-distance>205</system-distance>
</system-layout>
</print>
<note default-x="67.35" default-y="-10">
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
</note>
<barline location="right">
<bar-style>light-heavy</bar-style>
</barline>
</measure>
</part>
</score-partwise>
Loading

0 comments on commit 801715b

Please sign in to comment.