Skip to content

Commit

Permalink
Merge pull request #25014 from miiizen/24551-xml-offset
Browse files Browse the repository at this point in the history
Reset offset when placement is changed
  • Loading branch information
mike-spa authored Oct 18, 2024
2 parents f90a0a9 + 9cccd71 commit 218bf19
Show file tree
Hide file tree
Showing 4 changed files with 422 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,9 @@ static void addElemOffset(EngravingItem* el, track_idx_t track, const String& pl
} else {
el->setPlacement(placement == u"above" ? PlacementV::ABOVE : PlacementV::BELOW);
el->setPropertyFlags(Pid::PLACEMENT, PropertyFlags::UNSTYLED);
if (!el->isSticking()) {
el->resetProperty(Pid::OFFSET);
}
}
}
const Fraction& endTick = measure->score()->endTick();
Expand Down Expand Up @@ -1203,6 +1206,7 @@ static void addFermataToChord(const Notation& notation, ChordRest* cr)
}
if (!direction.empty()) {
na->setPlacement(direction == "inverted" ? PlacementV::BELOW : PlacementV::ABOVE);
na->resetProperty(Pid::OFFSET);
} else {
na->setPlacement(na->propertyDefault(Pid::PLACEMENT).value<PlacementV>());
}
Expand Down Expand Up @@ -1465,6 +1469,7 @@ static void addTextToNote(int l, int c, String txt, String placement, String fon
if (!placement.empty()) {
t->setPlacement(placement == u"below" ? PlacementV::BELOW : PlacementV::ABOVE);
t->setPropertyFlags(Pid::PLACEMENT, PropertyFlags::UNSTYLED);
t->resetProperty(Pid::OFFSET);
}
if (color.isValid()) {
t->setColor(color);
Expand Down Expand Up @@ -1496,6 +1501,7 @@ static void setSLinePlacement(SLine* sli, const String& placement)
} else {
sli->setPlacement(placement == u"above" ? PlacementV::ABOVE : PlacementV::BELOW);
sli->setPropertyFlags(Pid::PLACEMENT, PropertyFlags::UNSTYLED);
sli->resetProperty(Pid::OFFSET);
}
}
}
Expand Down Expand Up @@ -3442,6 +3448,7 @@ void MusicXmlParserDirection::direction(const String& partId,
if (!m_hasDefaultY) {
t->setPlacement(PlacementV::ABOVE); // crude way to force placement TODO improve ?
t->setPropertyFlags(Pid::PLACEMENT, PropertyFlags::UNSTYLED);
t->resetProperty(Pid::OFFSET);
}
}
}
Expand Down Expand Up @@ -4540,6 +4547,7 @@ void MusicXmlParserDirection::handleChordSym(const Fraction& tick, HarmonyMap& h
ha->setTrack(m_track);
ha->setPlacement(placement() == u"above" ? PlacementV::ABOVE : PlacementV::BELOW);
ha->setPropertyFlags(Pid::PLACEMENT, PropertyFlags::UNSTYLED);
ha->resetProperty(Pid::OFFSET);
ha->setVisible(m_visible);
HarmonyDesc newHarmonyDesc(m_track, ha, nullptr);

Expand Down Expand Up @@ -5385,7 +5393,8 @@ void MusicXmlParserPass2::barline(const String& partId, Measure* measure, const
}
if (fermataType == u"inverted") {
fermata->setPlacement(PlacementV::BELOW);
} else if (fermataType == u"") {
fermata->resetProperty(Pid::OFFSET);
} else if (fermataType.empty()) {
fermata->setPlacement(fermata->propertyDefault(Pid::PLACEMENT).value<PlacementV>());
}

Expand Down Expand Up @@ -7237,6 +7246,7 @@ FiguredBass* MusicXmlParserPass2::figuredBass()

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

if (normalizedText.empty()) {
delete fb;
Expand Down Expand Up @@ -7383,6 +7393,7 @@ void MusicXmlParserPass2::harmony(const String& partId, Measure* measure, const
if (!placement.isEmpty()) {
ha->setPlacement(placement == "below" ? PlacementV::BELOW : PlacementV::ABOVE);
ha->setPropertyFlags(Pid::PLACEMENT, PropertyFlags::UNSTYLED);
ha->resetProperty(Pid::OFFSET);
}
while (m_e.readNextStartElement()) {
if (m_e.name() == "root") {
Expand Down Expand Up @@ -7516,6 +7527,7 @@ void MusicXmlParserPass2::harmony(const String& partId, Measure* measure, const
ha->setVisible(printObject);
if (placement == u"below") {
ha->setPlacement(PlacementV::BELOW);
ha->resetProperty(Pid::OFFSET);
}
if (color.isValid()) {
ha->setColor(color);
Expand Down Expand Up @@ -7730,6 +7742,7 @@ void MusicXmlParserLyric::parse()

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

if (!RealIsNull(relX)) {
PointF offset = item->offset();
Expand Down
194 changes: 194 additions & 0 deletions src/importexport/musicxml/tests/data/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 218bf19

Please sign in to comment.