Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset offset when placement is changed and Discard relative-y for lyric placement #667

Open
wants to merge 2 commits into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 41 additions & 18 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 @@ -7135,9 +7149,11 @@ void MusicXMLParserLyric::parse()
const QString lyricNumber = _e.attributes().value("number").toString();
const QColor lyricColor { _e.attributes().value("color").toString() };
const bool printLyric = _e.attributes().value("print-object") != "no";
const QString placement = _e.attributes().value("placement").toString();
_placement = _e.attributes().value("placement").toString();
qreal relX = _e.attributes().value("relative-x").toDouble() / 10 * DPMM;
qreal relY = _e.attributes().value("relative-y").toDouble() / 10 * DPMM;
_relativeY = _e.attributes().value("relative-y").toDouble() / 10 * DPMM;
_defaultY = _e.attributes().value("default-y").toDouble() * -0.1 * DPMM;

QString extendType;
QString formattedText;

Expand Down Expand Up @@ -7194,15 +7210,14 @@ void MusicXMLParserLyric::parse()
lyric->setPropertyFlags(Pid::COLOR, PropertyFlags::UNSTYLED);
}
lyric->setVisible(printLyric);
if (!placement.isEmpty()) {
lyric->setPlacement(placement == "above" ? Placement::ABOVE : Placement::BELOW);
lyric->setPropertyFlags(Pid::PLACEMENT, PropertyFlags::UNSTYLED);
}

if (relX != 0 || relY != 0) {
lyric->setPlacement(placement() == "above" ? Placement::ABOVE : Placement::BELOW);
lyric->setPropertyFlags(Pid::PLACEMENT, PropertyFlags::UNSTYLED);
lyric->resetProperty(Pid::OFFSET);

if (!qFuzzyIsNull(relX)) {
QPointF offset = lyric->offset();
offset.setX(relX != 0 ? relX : lyric->offset().x());
offset.setY(relY != 0 ? relY : lyric->offset().y());
offset.setX(relX);
lyric->setOffset(offset);
lyric->setPropertyFlags(Pid::OFFSET, PropertyFlags::UNSTYLED);
}
Expand All @@ -7217,6 +7232,14 @@ void MusicXMLParserLyric::parse()
_extendedLyrics.insert(l);
}

QString MusicXMLParserLyric::placement() const
{
if (_placement == "" && hasTotalY())
return totalY() < 0 ? "above" : "below";
else
return _placement;
}

//---------------------------------------------------------
// slur
//---------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions importexport/musicxml/importmxmlpass2.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ class MusicXMLParserLyric {
MxmlLogger* _logger = nullptr; ///< Error logger
QMap<int, Lyrics*> _numberedLyrics; // lyrics with valid number
QSet<Lyrics*> _extendedLyrics; // lyrics with the extend flag set
qreal _defaultY = 0.0;
qreal _relativeY = 0.0;
QString _placement;
QString placement() const;
qreal totalY() const { return _defaultY + _relativeY; }
bool hasTotalY() const { return !qFuzzyIsNull(_defaultY) || !qFuzzyIsNull(_relativeY); }
};

//---------------------------------------------------------
Expand Down
10 changes: 0 additions & 10 deletions mtest/musicxml/io/testCueNotes3_ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@
<Chord>
<durationType>half</durationType>
<Lyrics>
<offset x="0" y="-1.7145"/>
<text>Whose</text>
</Lyrics>
<StemDirection>up</StemDirection>
Expand All @@ -162,7 +161,6 @@
<Chord>
<durationType>quarter</durationType>
<Lyrics>
<offset x="0" y="-1.7145"/>
<text>broad</text>
</Lyrics>
<StemDirection>up</StemDirection>
Expand All @@ -176,7 +174,6 @@
<Lyrics>
<ticks>480</ticks>
<ticks_f>1/4</ticks_f>
<offset x="0" y="-1.7145"/>
<text>stripes</text>
</Lyrics>
<StemDirection>up</StemDirection>
Expand Down Expand Up @@ -218,7 +215,6 @@
<Chord>
<durationType>quarter</durationType>
<Lyrics>
<offset x="0" y="-1.7145"/>
<text>and</text>
</Lyrics>
<StemDirection>up</StemDirection>
Expand All @@ -232,7 +228,6 @@
<small>1</small>
<durationType>16th</durationType>
<Lyrics>
<offset x="0" y="-1.7145"/>
<text>bright</text>
</Lyrics>
<StemDirection>up</StemDirection>
Expand All @@ -255,7 +250,6 @@
<small>1</small>
<durationType>quarter</durationType>
<Lyrics>
<offset x="0" y="-1.7145"/>
<text>stars</text>
</Lyrics>
<Articulation>
Expand All @@ -281,7 +275,6 @@
<small>1</small>
<durationType>quarter</durationType>
<Lyrics>
<offset x="0" y="-1.7145"/>
<text>through</text>
</Lyrics>
<StemDirection>down</StemDirection>
Expand All @@ -296,7 +289,6 @@
<Chord>
<durationType>half</durationType>
<Lyrics>
<offset x="0" y="-1.7145"/>
<text>the</text>
</Lyrics>
<StemDirection>up</StemDirection>
Expand All @@ -314,7 +306,6 @@
<small>1</small>
<durationType>quarter</durationType>
<Lyrics>
<offset x="0" y="-1.7145"/>
<text>per'l's</text>
</Lyrics>
<StemDirection>down</StemDirection>
Expand Down Expand Up @@ -342,7 +333,6 @@
<dots>1</dots>
<durationType>half</durationType>
<Lyrics>
<offset x="0" y="-1.7145"/>
<text>fight</text>
</Lyrics>
<StemDirection>up</StemDirection>
Expand Down
4 changes: 0 additions & 4 deletions mtest/musicxml/io/testElision_ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@
<Chord>
<durationType>quarter</durationType>
<Lyrics>
<offset x="0" y="-1.7145"/>
<text>ce<sym>lyricsElision</sym>e<sym>lyricsElision</sym>in</text>
</Lyrics>
<StemDirection>down</StemDirection>
Expand All @@ -163,7 +162,6 @@
<Chord>
<durationType>quarter</durationType>
<Lyrics>
<offset x="0" y="-1.7145"/>
<text>ce‿e in</text>
</Lyrics>
<StemDirection>down</StemDirection>
Expand All @@ -175,7 +173,6 @@
<Chord>
<durationType>quarter</durationType>
<Lyrics>
<offset x="0" y="-1.7145"/>
<text>ce<sym>lyricsElision</sym>e<sym>lyricsElision</sym>in</text>
</Lyrics>
<StemDirection>down</StemDirection>
Expand All @@ -187,7 +184,6 @@
<Chord>
<durationType>quarter</durationType>
<Lyrics>
<offset x="0" y="-1.7145"/>
<text>ce<sym>lyricsElision</sym>e‿in</text>
</Lyrics>
<StemDirection>down</StemDirection>
Expand Down
3 changes: 0 additions & 3 deletions mtest/musicxml/io/testInferredCredits1_ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ the video game: a tone poem</text>
<durationType>eighth</durationType>
<Lyrics>
<syllabic>begin</syllabic>
<offset x="0" y="-1.71429"/>
<text>ha</text>
</Lyrics>
<Note>
Expand All @@ -171,7 +170,6 @@ the video game: a tone poem</text>
<durationType>eighth</durationType>
<Lyrics>
<syllabic>end</syllabic>
<offset x="0" y="-1.71429"/>
<text>ha</text>
</Lyrics>
<Note>
Expand All @@ -192,7 +190,6 @@ the video game: a tone poem</text>
<Chord>
<durationType>quarter</durationType>
<Lyrics>
<offset x="0" y="-1.71429"/>
<text>nice.</text>
</Lyrics>
<StemDirection>up</StemDirection>
Expand Down
3 changes: 0 additions & 3 deletions mtest/musicxml/io/testInferredCredits2_ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ Words &amp; Music by also Henry Ives (and ampersands)
<durationType>eighth</durationType>
<Lyrics>
<syllabic>begin</syllabic>
<offset x="0" y="-1.71429"/>
<text>ha</text>
</Lyrics>
<Note>
Expand All @@ -179,7 +178,6 @@ Words &amp; Music by also Henry Ives (and ampersands)
<durationType>eighth</durationType>
<Lyrics>
<syllabic>end</syllabic>
<offset x="0" y="-1.71429"/>
<text>ha</text>
</Lyrics>
<Note>
Expand All @@ -200,7 +198,6 @@ Words &amp; Music by also Henry Ives (and ampersands)
<Chord>
<durationType>quarter</durationType>
<Lyrics>
<offset x="0" y="-1.71429"/>
<text>nice.</text>
</Lyrics>
<StemDirection>up</StemDirection>
Expand Down
Loading
Loading