Skip to content

Commit cde467b

Browse files
iveshenry18Jojo-Schmitz
authored andcommitted
ENG-83: Prevent collisions with inferred credits
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
1 parent e130ab1 commit cde467b

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

importexport/musicxml/importmxmlpass2.cpp

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ static void handleSpannerStop(SLine* cur_sp, int track2, const Fraction& tick, M
13171317
//---------------------------------------------------------
13181318

13191319
MusicXMLParserPass2::MusicXMLParserPass2(Score* score, MusicXMLParserPass1& pass1, MxmlLogger* logger)
1320-
: _divs(0), _score(score), _pass1(pass1), _logger(logger)
1320+
: _divs(0), _score(score), _pass1(pass1), _logger(logger), _hasInferredHeaderText(false)
13211321
{
13221322
// nothing
13231323
}
@@ -1460,6 +1460,48 @@ static void cleanFretDiagrams(Measure* measure)
14601460
}
14611461
}
14621462
}
1463+
1464+
//---------------------------------------------------------
1465+
// reformatHeaderVBox
1466+
//---------------------------------------------------------
1467+
/**
1468+
Due to inconsistencies with spacing and inferred text,
1469+
the header VBox frequently has collisions. This cleans
1470+
those (as a temporary fix for a more robust collision-prevention
1471+
system in Boxes).
1472+
*/
1473+
1474+
static void reformatHeaderVBox(MeasureBase* mb)
1475+
{
1476+
if (!mb->isVBox())
1477+
return;
1478+
1479+
VBox* headerVBox = toVBox(mb);
1480+
Score* score = mb->score();
1481+
qreal totalHeight = 0;
1482+
qreal offsetHeight = 0;
1483+
qreal verticalPadding = score->styleS(Sid::minVerticalDistance).val() * score->spatium();
1484+
1485+
for (auto e : headerVBox->el()) {
1486+
if (!e->isText())
1487+
continue;
1488+
Text* t = toText(e);
1489+
t->layout();
1490+
1491+
totalHeight += t->height();
1492+
if (Align(t->align() & Align::VMASK) == Align::TOP) {
1493+
totalHeight += verticalPadding;
1494+
t->setOffset(t->offset().x(), offsetHeight);
1495+
t->setPropertyFlags(Pid::OFFSET, PropertyFlags::UNSTYLED);
1496+
offsetHeight += t->height();
1497+
offsetHeight += verticalPadding;
1498+
}
1499+
}
1500+
1501+
headerVBox->setBoxHeight(Spatium(totalHeight / score->spatium()));
1502+
headerVBox->setPropertyFlags(Pid::BOX_HEIGHT, PropertyFlags::UNSTYLED);
1503+
}
1504+
14631505
//---------------------------------------------------------
14641506
// initPartState
14651507
//---------------------------------------------------------
@@ -1856,6 +1898,8 @@ void MusicXMLParserPass2::scorePartwise()
18561898
_score->connectArpeggios();
18571899
_score->fixupLaissezVibrer();
18581900
cleanFretDiagrams(_score->firstMeasure());
1901+
if (_hasInferredHeaderText)
1902+
reformatHeaderVBox(_score->measures()->first());
18591903
cleanUpLayoutBreaks(_score, _logger);
18601904
}
18611905

@@ -2878,12 +2922,15 @@ void MusicXMLParserDirection::direction(const QString& partId,
28782922
return;
28792923
else if (isLikelyCredit(tick)) {
28802924
Text* inferredText = addTextToHeader(Tid::COMPOSER);
2881-
if (inferredText)
2925+
if (inferredText) {
2926+
_pass2.setHasInferredHeaderText(true);
28822927
hideRedundantHeaderText(inferredText, {"lyricist", "composer", "poet"});
2928+
}
28832929
}
28842930
else if (isLikelySource(tick)) {
28852931
Text* inferredText = addTextToHeader(Tid::SUBTITLE);
28862932
if (inferredText) {
2933+
_pass2.setHasInferredHeaderText(true);
28872934
if (_score->metaTag("source").isEmpty())
28882935
_score->setMetaTag("source", inferredText->plainText());
28892936
hideRedundantHeaderText(inferredText, {"source"});

importexport/musicxml/importmxmlpass2.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ class MusicXMLParserPass2 {
267267
MusicXmlExtendedSpannerDesc& getSpanner(const MusicXmlSpannerDesc& desc);
268268
void clearSpanner(const MusicXmlSpannerDesc& desc);
269269
void deleteHandledSpanner(SLine* const& spanner);
270+
void setHasInferredHeaderText(bool b) { _hasInferredHeaderText = b; }
270271

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

342344
MusicXmlSpannerMap _spanners;
343345

mtest/musicxml/io/testInferredCredits_ref.mscx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,9 @@ the video game: a tone poem</metaTag>
118118
</Part>
119119
<Staff id="1">
120120
<VBox>
121-
<height>12.9746</height>
121+
<height>13.821</height>
122122
<Text>
123123
<style>Title</style>
124-
<offset x="0" y="-0.1505"/>
125124
<text><font size="22"/>Inferred Credits</text>
126125
</Text>
127126
<Text>
@@ -130,6 +129,7 @@ the video game: a tone poem</metaTag>
130129
</Text>
131130
<Text>
132131
<style>Subtitle</style>
132+
<offset x="0" y="6.73111"/>
133133
<text>from MUSESCORE: the musical: the graphic novel:
134134
the video game: a tone poem</text>
135135
</Text>

0 commit comments

Comments
 (0)