Skip to content

Commit

Permalink
ENG-73: Hide redundant header text once inferred
Browse files Browse the repository at this point in the history
Some scores specify header text both in the <identification> element
and in the incorrectly-exported staff text. The latter tends to have
more information, so this commit hides the former when the latter is
present to avoid redundancy.

Duplicate of musescore#8678, part 4
  • Loading branch information
iveshenry18 authored and Jojo-Schmitz committed Mar 5, 2023
1 parent 546500a commit b7a1e4f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
43 changes: 40 additions & 3 deletions importexport/musicxml/importmxmlpass2.cpp
Expand Up @@ -2877,10 +2877,17 @@ void MusicXMLParserDirection::direction(const QString& partId,
if (isLyricBracket())
return;
else if (isLikelyCredit(tick)) {
addTextToHeader(Tid::COMPOSER);
Text* inferredText = addTextToHeader(Tid::COMPOSER);
if (inferredText)
hideRedundantHeaderText(inferredText, {"lyricist", "composer", "poet"});
}
else if (isLikelySource(tick)) {
addTextToHeader(Tid::SUBTITLE);
Text* inferredText = addTextToHeader(Tid::SUBTITLE);
if (inferredText) {
if (_score->metaTag("source").isEmpty())
_score->setMetaTag("source", inferredText->plainText());
hideRedundantHeaderText(inferredText, {"source"});
}
}
else if (isLikelyLegallyDownloaded(tick)) {
// Ignore (TBD: print to footer?)
Expand Down Expand Up @@ -3401,7 +3408,11 @@ bool MusicXMLParserDirection::isLikelyLegallyDownloaded(const Fraction& tick) co
&& _wordsText.contains(QRegularExpression("This music has been legally downloaded\\.\\sDo not photocopy\\."));
}

Text* MusicXMLParserDirection::addTextToHeader(const Tid tid) const
//---------------------------------------------------------
// addTextToHeader
//---------------------------------------------------------

Text* MusicXMLParserDirection::addTextToHeader(const Tid tid)
{
Text* t = new Text(_score, tid);
t->setXmlText(_wordsText.trimmed());
Expand All @@ -3415,6 +3426,32 @@ Text* MusicXMLParserDirection::addTextToHeader(const Tid tid) const
}

//---------------------------------------------------------
// hideRedundantHeaderText
// After inferring header text, hide redundant text.
// Redundant text is detected by checking all the
// Text elements of the inferred text's VBox against
// the contents of the eligible metaTags
//---------------------------------------------------------

void MusicXMLParserDirection::hideRedundantHeaderText(const Text* inferredText, const std::vector<QString> metaTags)
{
if (!inferredText->parent()->isVBox())
return;

for (auto e : toVBox(inferredText->parent())->el()) {
if (e == inferredText || !e->isText())
continue;

Text* t = toText(e);
for (auto metaTag : metaTags) {
if (t->plainText() == _score->metaTag(metaTag)) {
t->setVisible(false);
continue;
}
}
}
}
//---------------------------------------------------------
// MusicXMLInferredFingering
//---------------------------------------------------------

Expand Down
3 changes: 2 additions & 1 deletion importexport/musicxml/importmxmlpass2.h
Expand Up @@ -412,7 +412,8 @@ class MusicXMLParserDirection {
bool isLyricBracket() const;
bool isLikelySource(const Fraction& tick) const;
bool isLikelyLegallyDownloaded(const Fraction& tick) const;
Text* addTextToHeader(const Tid tid) const;
Text* addTextToHeader(const Tid tid);
void hideRedundantHeaderText(const Text* inferredText, const std::vector<QString> metaTags);
void textToDynamic(QString& text) const;
bool directionToDynamic();
bool isLikelyTempoText();
Expand Down
1 change: 1 addition & 0 deletions mtest/musicxml/io/testInferredCredits.xml
Expand Up @@ -6,6 +6,7 @@
</work>
<identification>
<creator type="composer">Henry Ives</creator>
<creator type='lyricist'>Henry Ives</creator>
<encoding>
<software>MuseScore 0.7.0</software>
<encoding-date>2007-09-10</encoding-date>
Expand Down
5 changes: 3 additions & 2 deletions mtest/musicxml/io/testInferredCredits_ref.mscx
Expand Up @@ -43,11 +43,12 @@
<metaTag name="arranger"></metaTag>
<metaTag name="composer">Henry Ives</metaTag>
<metaTag name="copyright"></metaTag>
<metaTag name="lyricist"></metaTag>
<metaTag name="lyricist">Henry Ives</metaTag>
<metaTag name="movementNumber"></metaTag>
<metaTag name="movementTitle"></metaTag>
<metaTag name="poet"></metaTag>
<metaTag name="source"></metaTag>
<metaTag name="source">from MUSESCORE: the musical: the graphic novel:
the video game: a tone poem</metaTag>
<metaTag name="translator"></metaTag>
<metaTag name="workNumber"></metaTag>
<metaTag name="workTitle">Inferred Credits</metaTag>
Expand Down

0 comments on commit b7a1e4f

Please sign in to comment.