Skip to content

Commit

Permalink
ENG-83: Prevent collisions with inferred credits
Browse files Browse the repository at this point in the history
Due to inferred (mis-exported) credits not having valid positioning
information, there were occasionally collisions with the title text.
This commit adds a reformatting function that runs at the end of the
import (if any inferred header text is present) that prevents these
vertical collisions.

Duplicate of musescore#8678, part 5
  • Loading branch information
iveshenry18 authored and Jojo-Schmitz committed Sep 29, 2021
1 parent cfcc42d commit cf9d71b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
51 changes: 49 additions & 2 deletions importexport/musicxml/importmxmlpass2.cpp
Expand Up @@ -1317,7 +1317,7 @@ static void handleSpannerStop(SLine* cur_sp, int track2, const Fraction& tick, M
//---------------------------------------------------------

MusicXMLParserPass2::MusicXMLParserPass2(Score* score, MusicXMLParserPass1& pass1, MxmlLogger* logger)
: _divs(0), _score(score), _pass1(pass1), _logger(logger)
: _divs(0), _score(score), _pass1(pass1), _logger(logger), _hasInferredHeaderText(false)
{
// nothing
}
Expand Down Expand Up @@ -1460,6 +1460,48 @@ static void cleanFretDiagrams(Measure* measure)
}
}
}

//---------------------------------------------------------
// reformatHeaderVBox
//---------------------------------------------------------
/**
Due to inconsistencies with spacing and inferred text,
the header VBox frequently has collisions. This cleans
those (as a temporary fix for a more robust collision-prevention
system in Boxes).
*/

static void reformatHeaderVBox(MeasureBase* mb)
{
if (!mb->isVBox())
return;

VBox* headerVBox = toVBox(mb);
Score* score = mb->score();
qreal totalHeight = 0;
qreal offsetHeight = 0;
qreal verticalPadding = score->styleS(Sid::minVerticalDistance).val() * score->spatium();

for (auto e : headerVBox->el()) {
if (!e->isText())
continue;
Text* t = toText(e);
t->layout();

totalHeight += t->height();
if (Align(t->align() & Align::VMASK) == Align::TOP) {
totalHeight += verticalPadding;
t->setOffset(t->offset().x(), offsetHeight);
t->setPropertyFlags(Pid::OFFSET, PropertyFlags::UNSTYLED);
offsetHeight += t->height();
offsetHeight += verticalPadding;
}
}

headerVBox->setBoxHeight(Spatium(totalHeight / score->spatium()));
headerVBox->setPropertyFlags(Pid::BOX_HEIGHT, PropertyFlags::UNSTYLED);
}

//---------------------------------------------------------
// initPartState
//---------------------------------------------------------
Expand Down Expand Up @@ -1856,6 +1898,8 @@ void MusicXMLParserPass2::scorePartwise()
_score->connectArpeggios();
_score->fixupLaissezVibrer();
cleanFretDiagrams(_score->firstMeasure());
if (_hasInferredHeaderText)
reformatHeaderVBox(_score->measures()->first());
cleanUpLayoutBreaks(_score, _logger);
}

Expand Down Expand Up @@ -2878,12 +2922,15 @@ void MusicXMLParserDirection::direction(const QString& partId,
return;
else if (isLikelyCredit(tick)) {
Text* inferredText = addTextToHeader(Tid::COMPOSER);
if (inferredText)
if (inferredText) {
_pass2.setHasInferredHeaderText(true);
hideRedundantHeaderText(inferredText, {"lyricist", "composer", "poet"});
}
}
else if (isLikelySource(tick)) {
Text* inferredText = addTextToHeader(Tid::SUBTITLE);
if (inferredText) {
_pass2.setHasInferredHeaderText(true);
if (_score->metaTag("source").isEmpty())
_score->setMetaTag("source", inferredText->plainText());
hideRedundantHeaderText(inferredText, {"source"});
Expand Down
2 changes: 2 additions & 0 deletions importexport/musicxml/importmxmlpass2.h
Expand Up @@ -267,6 +267,7 @@ class MusicXMLParserPass2 {
MusicXmlExtendedSpannerDesc& getSpanner(const MusicXmlSpannerDesc& desc);
void clearSpanner(const MusicXmlSpannerDesc& desc);
void deleteHandledSpanner(SLine* const& spanner);
void setHasInferredHeaderText(bool b) { _hasInferredHeaderText = b; }

private:
void initPartState(const QString& partId);
Expand Down Expand Up @@ -338,6 +339,7 @@ class MusicXMLParserPass2 {
std::map<int, Tie*> _ties;
Volta* _lastVolta;
bool _hasDrumset; ///< drumset defined TODO: move to pass 1
bool _hasInferredHeaderText;

MusicXmlSpannerMap _spanners;

Expand Down
4 changes: 2 additions & 2 deletions mtest/musicxml/io/testInferredCredits_ref.mscx
Expand Up @@ -118,10 +118,9 @@ the video game: a tone poem</metaTag>
</Part>
<Staff id="1">
<VBox>
<height>12.9746</height>
<height>13.821</height>
<Text>
<style>Title</style>
<offset x="0" y="-0.1505"/>
<text><font size="22"/>Inferred Credits</text>
</Text>
<Text>
Expand All @@ -130,6 +129,7 @@ the video game: a tone poem</metaTag>
</Text>
<Text>
<style>Subtitle</style>
<offset x="0" y="6.73111"/>
<text>from MUSESCORE: the musical: the graphic novel:
the video game: a tone poem</text>
</Text>
Expand Down

0 comments on commit cf9d71b

Please sign in to comment.