Skip to content

Commit

Permalink
Don't add credit frames past page 1 on XML import
Browse files Browse the repository at this point in the history
Backport of musescore#24069
  • Loading branch information
miiizen authored and Jojo-Schmitz committed Aug 28, 2024
1 parent 783b05f commit 8a09536
Show file tree
Hide file tree
Showing 40 changed files with 62 additions and 126 deletions.
56 changes: 22 additions & 34 deletions importexport/musicxml/importmxmlpass1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,17 +672,9 @@ static Tid tidForCreditWords(const CreditWords* const word, std::vector<const Cr
// createAndAddVBoxForCreditWords
//---------------------------------------------------------

VBox* MusicXMLParserPass1::createAndAddVBoxForCreditWords(Score* const score, const int miny, const int maxy)
VBox* MusicXMLParserPass1::createAndAddVBoxForCreditWords(Score* const score)
{
VBox* vbox = new VBox(score);
qreal vboxHeight = 10; // default height in tenths
double diff = maxy - miny; // calculate height in tenths
if (diff > vboxHeight) // and size is reasonable
vboxHeight = diff;
vboxHeight /= 10; // height in spatium
vboxHeight += 2.5; // guesstimated correction for last line

vbox->setBoxHeight(Spatium(vboxHeight));
score->measures()->add(vbox);
return vbox;
}
Expand Down Expand Up @@ -764,16 +756,15 @@ static void inferFromTitle(QString& title, QString& inferredSubtitle, QString& i
// addCreditWords
//---------------------------------------------------------

static VBox* addCreditWords(Score* const score, const CreditWordsList& crWords,
const int pageNr, const QSize pageSize,
static VBox* addCreditWords(Score* const score, const CreditWordsList& crWords, const QSize pageSize,
const bool top, const bool isSibeliusScore)
{
VBox* vbox = nullptr;

std::vector<const CreditWords*> headerWords;
std::vector<const CreditWords*> footerWords;
for (const CreditWords* w : crWords) {
if (w->page == pageNr) {
if (w->page == 1) {
if (w->defaultY > (pageSize.height() / 2))
headerWords.push_back(w);
else
Expand All @@ -782,35 +773,28 @@ static VBox* addCreditWords(Score* const score, const CreditWordsList& crWords,
}

std::vector<const CreditWords*> words;
if (pageNr == 1) {
// if there are more credit words in the footer than in header,
// swap heaer and footer, assuming this will result in a vertical
// frame with the title on top of the page.
// Sibelius (direct export) typically exports no header
// and puts the title etc. in the footer
const bool doSwap = footerWords.size() > headerWords.size() && isSibeliusScore;
if (top) {
words = doSwap ? footerWords : headerWords;
}
else {
words = doSwap ? headerWords : footerWords;
}
}
else {
words = top ? headerWords : footerWords;
}
// if there are more credit words in the footer than in header,
// swap heaer and footer, assuming this will result in a vertical
// frame with the title on top of the page.
// Sibelius (direct export) typically exports no header
// and puts the title etc. in the footer
const bool doSwap = footerWords.size() > headerWords.size() && isSibeliusScore;
if (top)
words = doSwap ? footerWords : headerWords;
else
words = doSwap ? headerWords : footerWords;

int miny = 0;
int maxy = 0;
findYMinYMaxInWords(words, miny, maxy);

for (const CreditWords* w : words) {
if (mustAddWordToVbox(w->type)) {
const Tid tid = (pageNr == 1 && top) ? tidForCreditWords(w, words, pageSize.width()) : Tid::DEFAULT;
const Tid tid = top ? tidForCreditWords(w, words, pageSize.width()) : Tid::DEFAULT;
const Align align = alignForCreditWords(w, pageSize.width(), tid);
double yoffs = tid == Tid::COMPOSER ? 0.0 : (maxy - w->defaultY) * score->spatium() / 10;
if (!vbox)
vbox = MusicXMLParserPass1::createAndAddVBoxForCreditWords(score, miny, maxy);
vbox = MusicXMLParserPass1::createAndAddVBoxForCreditWords(score);
addText2(vbox, score, w->words, tid, align, yoffs);
}
else if (w->type == "rights" && score->metaTag("copyright").isEmpty()) {
Expand Down Expand Up @@ -900,7 +884,11 @@ void MusicXMLParserPass1::createMeasuresAndVboxes(Score* const score,
// add a header vbox if the this measure is the first in the score or the first on a new page
if (pageStartMeasureNrs.count(i) || i == 0) {
++pageNr;
vbox = addCreditWords(score, crWords, pageNr, pageSize, true, _exporterString.contains("sibelius"));
if (pageNr == 1) {
vbox = addCreditWords(score, crWords, pageSize, true, _exporterString.contains("sibelius"));
//if (i == 0 && vbox)
// vbox->setExcludeFromOtherParts(false);
}
}

// create and add the measure
Expand All @@ -919,8 +907,8 @@ void MusicXMLParserPass1::createMeasuresAndVboxes(Score* const score,
addBreakToPreviousMeasureBase(score, mb, LayoutBreak::Type::LINE);

// add a footer vbox if the next measure is on a new page or end of score has been reached
if (pageStartMeasureNrs.count(i+1) || i == (ml.size() - 1))
addCreditWords(score, crWords, pageNr, pageSize, false, _exporterString.contains("sibelius"));
if ((pageStartMeasureNrs.count(i + 1) || i == (ml.size() - 1)) && pageNr == 1)
addCreditWords(score, crWords, pageSize, false, _exporterString.contains("sibelius"));
}
}

Expand Down
2 changes: 1 addition & 1 deletion importexport/musicxml/importmxmlpass1.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class MusicXMLParserPass1 {
const CreditWordsList& credits() const { return _credits; }
bool hasBeamingInfo() const { return _hasBeamingInfo; }
bool isVocalStaff(const QString& id) const { return _parts[id].isVocalStaff(); }
static VBox* createAndAddVBoxForCreditWords(Score* const score, const int miny = 0, const int maxy = 75);
static VBox* createAndAddVBoxForCreditWords(Score* const score);
int maxDiff() const { return _maxDiff; }
void insertAdjustedDuration(Fraction key, Fraction value) { _adjustedDurations.insert(key, value); }
QMap<Fraction, Fraction>& adjustedDurations() { return _adjustedDurations; }
Expand Down
52 changes: 0 additions & 52 deletions importexport/musicxml/importmxmlpass2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1625,53 +1625,6 @@ 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 lineSpacingMultiplier = 1.2;

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 += t->lineHeight() * lineSpacingMultiplier;
t->setOffset(t->offset().x(), offsetHeight);
t->setPropertyFlags(Pid::OFFSET, PropertyFlags::UNSTYLED);
offsetHeight += t->height();
offsetHeight += t->lineHeight() * lineSpacingMultiplier;
}
}

// 1mm of
static const double VBOX_BOTTOM_PADDING = 1;
totalHeight += VBOX_BOTTOM_PADDING;
headerVBox->setBottomMargin(VBOX_BOTTOM_PADDING);
headerVBox->setPropertyFlags(Pid::BOTTOM_MARGIN, PropertyFlags::UNSTYLED);

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

//---------------------------------------------------------
// initPartState
//---------------------------------------------------------
Expand Down Expand Up @@ -2171,11 +2124,6 @@ void MusicXMLParserPass2::scorePartwise()
cleanUpLayoutBreaks(_score, _logger);

addError(checkAtEndElement(_e, "score-partwise"));

// This method relies heavily on text metrics which differ from system to system and can be very volatile
// To avoid having to update the majority of musicxml tests on every change to engraving, don't run this during testing
if (!MScore::testMode)
reformatHeaderVBox(_score->measures()->first());
}

//---------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion mtest/musicxml/io/testAdditionalFermatas_ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
</Part>
<Staff id="1">
<VBox>
<height>12.5</height>
<height>10</height>
<Text>
<style>Title</style>
<offset x="0" y="-0.07525"/>
Expand Down
2 changes: 1 addition & 1 deletion mtest/musicxml/io/testBarlineLoc_ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
</Part>
<Staff id="1">
<VBox>
<height>12.5</height>
<height>10</height>
<Text>
<style>Title</style>
<offset x="0" y="-0.0367999"/>
Expand Down
2 changes: 1 addition & 1 deletion mtest/musicxml/io/testBeamModes_ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
</Part>
<Staff id="1">
<VBox>
<height>12.5</height>
<height>10</height>
<Text>
<style>Title</style>
<offset x="0" y="-0.07525"/>
Expand Down
2 changes: 1 addition & 1 deletion mtest/musicxml/io/testBracketTypes_ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
</Part>
<Staff id="1">
<VBox>
<height>12.5</height>
<height>10</height>
<Text>
<style>Title</style>
<offset x="0" y="-0.07525"/>
Expand Down
2 changes: 1 addition & 1 deletion mtest/musicxml/io/testConnectedArpeggios_ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
</Part>
<Staff id="1">
<VBox>
<height>12.5</height>
<height>10</height>
<Text>
<style>Title</style>
<offset x="0" y="-0.07525"/>
Expand Down
2 changes: 1 addition & 1 deletion mtest/musicxml/io/testCueGraceNotes_ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
</Part>
<Staff id="1">
<VBox>
<height>12.5</height>
<height>10</height>
<Text>
<style>Title</style>
<offset x="0" y="-0.07525"/>
Expand Down
2 changes: 1 addition & 1 deletion mtest/musicxml/io/testCueNotes3_ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
</Part>
<Staff id="1">
<VBox>
<height>12.5</height>
<height>10</height>
<Text>
<style>Title</style>
<offset x="0" y="-0.110236"/>
Expand Down
2 changes: 1 addition & 1 deletion mtest/musicxml/io/testDSalCodaMisplaced_ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
</Part>
<Staff id="1">
<VBox>
<height>12.5</height>
<height>10</height>
<Text>
<style>Title</style>
<offset x="0" y="-0.07525"/>
Expand Down
2 changes: 1 addition & 1 deletion mtest/musicxml/io/testDSalCoda_ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
</Part>
<Staff id="1">
<VBox>
<height>12.5</height>
<height>10</height>
<Text>
<style>Title</style>
<offset x="0" y="-0.07525"/>
Expand Down
2 changes: 1 addition & 1 deletion mtest/musicxml/io/testExcessHiddenStaves_ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
</Part>
<Staff id="1">
<VBox>
<height>12.5</height>
<height>10</height>
<Text>
<style>Title</style>
<offset x="0" y="-0.07525"/>
Expand Down
2 changes: 1 addition & 1 deletion mtest/musicxml/io/testExcessiveFretDiagrams1_ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
</Part>
<Staff id="1">
<VBox>
<height>12.5</height>
<height>10</height>
<Text>
<style>Title</style>
<offset x="0" y="-0.07525"/>
Expand Down
2 changes: 1 addition & 1 deletion mtest/musicxml/io/testExcessiveFretDiagrams2_ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
</Part>
<Staff id="1">
<VBox>
<height>12.5</height>
<height>10</height>
<Text>
<style>Title</style>
<offset x="0" y="-0.07525"/>
Expand Down
2 changes: 1 addition & 1 deletion mtest/musicxml/io/testFretDiagramLayoutOrder_ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
</Part>
<Staff id="1">
<VBox>
<height>12.5</height>
<height>10</height>
<Text>
<style>Title</style>
<offset x="0" y="-0.07525"/>
Expand Down
2 changes: 1 addition & 1 deletion mtest/musicxml/io/testFretboardDiagrams_ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
</Part>
<Staff id="1">
<VBox>
<height>12.5</height>
<height>10</height>
<Text>
<style>Title</style>
<offset x="0" y="-0.0454943"/>
Expand Down
2 changes: 1 addition & 1 deletion mtest/musicxml/io/testInferredCredits1_ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ the video game: a tone poem</metaTag>
</Part>
<Staff id="1">
<VBox>
<height>12.3698</height>
<height>18.8698</height>
<Text>
<style>Title</style>
<offset x="0" y="-0.1505"/>
Expand Down
2 changes: 1 addition & 1 deletion mtest/musicxml/io/testInferredDynamics_ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
</Part>
<Staff id="1">
<VBox>
<height>12.5</height>
<height>10</height>
<Text>
<style>Title</style>
<offset x="0" y="-0.07525"/>
Expand Down
2 changes: 1 addition & 1 deletion mtest/musicxml/io/testInferredFingerings_ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
</Part>
<Staff id="1">
<VBox>
<height>12.5</height>
<height>10</height>
<Text>
<style>Title</style>
<offset x="0" y="-0.07525"/>
Expand Down
2 changes: 1 addition & 1 deletion mtest/musicxml/io/testLayoutCleanup1_ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
</Part>
<Staff id="1">
<VBox>
<height>12.5</height>
<height>10</height>
<Text>
<style>Title</style>
<offset x="0" y="-0.07525"/>
Expand Down
2 changes: 1 addition & 1 deletion mtest/musicxml/io/testLayoutCleanup2_ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
</Part>
<Staff id="1">
<VBox>
<height>12.5</height>
<height>10</height>
<Text>
<style>Title</style>
<offset x="0" y="-0.07525"/>
Expand Down
2 changes: 1 addition & 1 deletion mtest/musicxml/io/testLyricBracket_ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
</Part>
<Staff id="1">
<VBox>
<height>12.5</height>
<height>10</height>
<Text>
<style>Title</style>
<offset x="0" y="-0.07525"/>
Expand Down
2 changes: 1 addition & 1 deletion mtest/musicxml/io/testMeasureStyleSlash_ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
</Part>
<Staff id="1">
<VBox>
<height>3.5</height>
<height>10</height>
<Text>
<style>Title</style>
<offset x="0" y="-0.0564445"/>
Expand Down
2 changes: 1 addition & 1 deletion mtest/musicxml/io/testNegativeOffset_ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
</Part>
<Staff id="1">
<VBox>
<height>12.5</height>
<height>10</height>
<Text>
<style>Title</style>
<offset x="0" y="-0.07525"/>
Expand Down
2 changes: 1 addition & 1 deletion mtest/musicxml/io/testPartNames_ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@
</Part>
<Staff id="1">
<VBox>
<height>12.5</height>
<height>10</height>
<Text>
<style>Title</style>
<offset x="0" y="-0.0174978"/>
Expand Down
Loading

0 comments on commit 8a09536

Please sign in to comment.