Skip to content

Commit

Permalink
Fix corruption on section break in parts
Browse files Browse the repository at this point in the history
Backport of musescore#26308 plus fixing most clazy warnings
  • Loading branch information
mike-spa authored and Jojo-Schmitz committed Feb 3, 2025
1 parent 116925b commit d0ca470
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 37 deletions.
37 changes: 18 additions & 19 deletions importexport/capella/capella.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,10 @@ static void processBasicDrawObj(QList<BasicDrawObj*> objects, Segment* s, int tr
{
TransposableObj* to = static_cast<TransposableObj*>(oo);
QString str = "";
for (BasicDrawObj* bdo : to->variants) {
for (BasicDrawObj*& bdo : to->variants) {
SimpleTextObj* st = static_cast<SimpleTextObj*>(bdo);
if (st->font().family() == "capella3") {
for (const QChar& ch : st->text()) {
for (QChar& ch : st->text()) {
if (ch == 'Q')
str += "b";
else if (ch == 'S')
Expand Down Expand Up @@ -498,7 +498,7 @@ static bool findChordRests(BasicDrawObj const* const o, Score* score, const int
if (cr) {
if ((graceNumber1 > 0) && cr->isChord()) { // the spanner is starting from a grace note
Chord* chord = toChord(cr);
for (Chord* cc : chord->graceNotes()) {
for (Chord*& cc : chord->graceNotes()) {
--graceNumber1;
if ((graceNumber1 == 0) && (!cr1))
cr1 = toChordRest(cc); // found first ChordRest
Expand All @@ -515,7 +515,7 @@ static bool findChordRests(BasicDrawObj const* const o, Score* score, const int
if (cr) {
if ((graceNumber > 0) && cr->isChord()) { // the spanner is ending on a grace note
Chord* chord = toChord(cr);
for (Chord* cc : chord->graceNotes()) {
for (Chord*& cc : chord->graceNotes()) {
--graceNumber;
if ((graceNumber == 0) && (!cr2))
cr2 = toChordRest(cc); // found 2nd ChordRest
Expand Down Expand Up @@ -574,7 +574,7 @@ static Fraction readCapVoice(Score* score, CapVoice* cvoice, int staffIdx, const
ClefType pclef = score->staff(staffIdx)->defaultClefType()._concertClef;

QList<Chord*> graceNotes;
for (NoteObj* no : cvoice->objects) {
for (NoteObj*& no : cvoice->objects) {
switch (no->type()) {
case CapellaNoteObjectType::REST:
{
Expand Down Expand Up @@ -766,7 +766,7 @@ static Fraction readCapVoice(Score* score, CapVoice* cvoice, int staffIdx, const
};
off += keyOffsets[int(key) + 7];

for (const CNote& n : o->notes) {
for (const CNote& n : qAsConst(o->notes)) {
Note* note = new Note(score);
int pitch = 0;
// .cap import: pitch contains the diatonic note number relative to clef and key
Expand Down Expand Up @@ -802,7 +802,7 @@ static Fraction readCapVoice(Score* score, CapVoice* cvoice, int staffIdx, const
note->setTieFor(tie);
}
}
for (Verse v : o->verse) {
for (Verse& v : o->verse) {
Lyrics* l = new Lyrics(score);
l->setTrack(track);
l->setPlainText(v.text);
Expand Down Expand Up @@ -972,15 +972,15 @@ static Fraction readCapVoice(Score* score, CapVoice* cvoice, int staffIdx, const
// pass II
//
tick = startTick;
for (NoteObj* no : cvoice->objects) {
for (NoteObj*& no : cvoice->objects) {
BasicDurationalObj* d = 0;
if (no->type() == CapellaNoteObjectType::REST)
d = static_cast<BasicDurationalObj*>(static_cast<RestObj*>(no));
else if (no->type() == CapellaNoteObjectType::CHORD)
d = static_cast<BasicDurationalObj*>(static_cast<ChordObj*>(no));
if (!d)
continue;
for (BasicDrawObj* o : d->objects) {
for (BasicDrawObj*& o : d->objects) {
switch (o->type) {
case CapellaType::SIMPLE_TEXT:
// qDebug("simple text at %d", tick);
Expand Down Expand Up @@ -1175,9 +1175,9 @@ void convertCapella(Score* score, Capella* cap, bool capxMode)
// score->style().set(Sid::hideEmptyStaves, true);

#if 1
for (CapSystem* csys : cap->systems) {
for (CapSystem*& csys : cap->systems) {
qDebug("System:");
for (CapStaff* cstaff : csys->staves) {
for (CapStaff*& cstaff : csys->staves) {
CapStaffLayout* cl = cap->staffLayout(cstaff->iLayout);
qDebug(" Staff layout <%s><%s><%s><%s><%s> %d barline %d-%d mode %d",
qPrintable(cl->descr), qPrintable(cl->name), qPrintable(cl->abbrev),
Expand All @@ -1191,7 +1191,7 @@ void convertCapella(Score* score, Capella* cap, bool capxMode)
// find out the maximum number of staves
//
int staves = 0;
for (CapSystem* csys : cap->systems) {
for (CapSystem*& csys : cap->systems) {
staves = qMax(staves, csys->staves.size());
}
//
Expand Down Expand Up @@ -1263,7 +1263,7 @@ void convertCapella(Score* score, Capella* cap, bool capxMode)
if (bstaff)
bstaff->setBarLineSpan(span != 0);

for (CapBracket cb : cap->brackets) {
for (CapBracket& cb : cap->brackets) {
qDebug("Bracket %d-%d curly %d", cb.from, cb.to, cb.curly);
Staff* staff = score->staves().value(cb.from);
if (staff == 0) {
Expand All @@ -1274,7 +1274,7 @@ void convertCapella(Score* score, Capella* cap, bool capxMode)
staff->setBracketSpan(0, cb.to - cb.from + 1);
}
MeasureBase* measure = nullptr;
for (BasicDrawObj* o : cap->backgroundChord->objects) {
for (BasicDrawObj*& o : cap->backgroundChord->objects) {
switch (o->type) {
case CapellaType::SIMPLE_TEXT:
{
Expand Down Expand Up @@ -1325,7 +1325,7 @@ void convertCapella(Score* score, Capella* cap, bool capxMode)
}

Fraction systemTick = Fraction(0,1);
for (CapSystem* csys : cap->systems) {
for (CapSystem*& csys : cap->systems) {
qDebug("readCapSystem");
/*
if (csys->explLeftIndent > 0) {
Expand All @@ -1336,15 +1336,15 @@ void convertCapella(Score* score, Capella* cap, bool capxMode)
}
*/
Fraction mtick = Fraction(0,1);
for (CapStaff* cstaff : csys->staves) {
for (CapStaff*& cstaff : csys->staves) {
//
// assumption: layout index is mscore staffIdx
// which means that there is a 1:1 relation between layout/staff
//

qDebug(" ReadCapStaff %d/%d", cstaff->numerator, 1 << cstaff->log2Denom);
int staffIdx = cstaff->iLayout;
for (CapVoice* cvoice : cstaff->voices) {
for (CapVoice*& cvoice : cstaff->voices) {
Fraction tick = readCapVoice(score, cvoice, staffIdx, systemTick, capxMode);
if (tick > mtick)
mtick = tick;
Expand All @@ -1354,7 +1354,7 @@ void convertCapella(Score* score, Capella* cap, bool capxMode)
if (m && !m->lineBreak()) {
LayoutBreak* lb = new LayoutBreak(score);
lb->setLayoutBreakType(LayoutBreak::Type::LINE);
lb->setTrack(-1); // this are system elements
lb->setTrack(0); // these are system elements
m->add(lb);
}
systemTick = mtick;
Expand Down Expand Up @@ -2750,7 +2750,6 @@ void Capella::read(QFile* fp)
barNumberFrame = readByte(); // 0=kein, 1=Rechteck, 2=Ellipse
nBarDistX = readByte();
nBarDistY = readByte();
QFont barNumFont = readFont();
nFirstPage = readUnsigned(); // Versatz fuer Seitenzaehlung
leftPageMargins = readUnsigned(); // Seitenraender
topPageMargins = readUnsigned();
Expand Down
2 changes: 1 addition & 1 deletion libmscore/box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ Element* Box::drop(EditData& data)
}
break;
}
lb->setTrack(-1); // these are system elements
lb->setTrack(0); // these are system elements
lb->setParent(this);
score()->undoAddElement(lb);
return lb;
Expand Down
26 changes: 13 additions & 13 deletions libmscore/measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ AccidentalVal Measure::findAccidental(Note* note) const
if (!e || !e->isChord())
continue;
Chord* crd = toChord(e);
for (Chord* chord1 : crd->graceNotes()) {
for (Chord*& chord1 : crd->graceNotes()) {
for (Note* note1 : chord1->notes()) {
if (note1->tieBack() && note1->accidental() == 0)
continue;
Expand Down Expand Up @@ -425,7 +425,7 @@ AccidentalVal Measure::findAccidental(Segment* s, int staffIdx, int line, bool &
if (!e || !e->isChord())
continue;
Chord* chord = toChord(e);
for (Chord* chord1 : chord->graceNotes()) {
for (Chord*& chord1 : chord->graceNotes()) {
for (Note* note : chord1->notes()) {
if (note->tieBack() && note->accidental() == 0)
continue;
Expand Down Expand Up @@ -1503,8 +1503,8 @@ Element* Measure::drop(EditData& data)
Bracket* b = toBracket(e);
int level = 0;
int firstStaff = 0;
for (Staff* s : score()->staves()) {
for (const BracketItem* bi : s->brackets()) {
for (Staff*& s : score()->staves()) {
for (BracketItem*& bi : s->brackets()) {
int lastStaff = firstStaff + bi->bracketSpan() - 1;
if (staffIdx >= firstStaff && staffIdx <= lastStaff)
++level;
Expand Down Expand Up @@ -1536,7 +1536,7 @@ Element* Measure::drop(EditData& data)
}
else {
// apply to all staves:
for (Staff* s : score()->staves())
for (Staff*& s : score()->staves())
score()->undoChangeKeySig(s, tick(), k);
}

Expand Down Expand Up @@ -1587,7 +1587,7 @@ Element* Measure::drop(EditData& data)
break;
}
if (b) {
b->setTrack(-1); // these are system elements
b->setTrack(0); // these are system elements
b->setParent(measure);
score()->undoAddElement(b);
}
Expand All @@ -1607,7 +1607,7 @@ Element* Measure::drop(EditData& data)
const bool systemEnd = (nextVisStaffIdx == score()->nstaves());
if (systemEnd) {
System* ns = 0;
for (System* ts : score()->systems()) {
for (System*& ts : score()->systems()) {
if (ns) {
ns = ts;
break;
Expand Down Expand Up @@ -1652,23 +1652,23 @@ Element* Measure::drop(EditData& data)
}
else if (bl->barLineType() == BarLineType::START_REPEAT) {
Measure* m2 = isMMRest() ? mmRestFirst() : this;
for (Score* lscore : score()->scoreList()) {
for (Score*& lscore : score()->scoreList()) {
Measure* lmeasure = lscore->tick2measure(m2->tick());
if (lmeasure)
lmeasure->undoChangeProperty(Pid::REPEAT_START, true);
}
}
else if (bl->barLineType() == BarLineType::END_REPEAT) {
Measure* m2 = isMMRest() ? mmRestLast() : this;
for (Score* lscore : score()->scoreList()) {
for (Score*& lscore : score()->scoreList()) {
Measure* lmeasure = lscore->tick2measure(m2->tick());
if (lmeasure)
lmeasure->undoChangeProperty(Pid::REPEAT_END, true);
}
}
else if (bl->barLineType() == BarLineType::END_START_REPEAT) {
Measure* m2 = isMMRest() ? mmRestLast() : this;
for (Score* lscore : score()->scoreList()) {
for (Score*& lscore : score()->scoreList()) {
Measure* lmeasure = lscore->tick2measure(m2->tick());
if (lmeasure) {
lmeasure->undoChangeProperty(Pid::REPEAT_END, true);
Expand Down Expand Up @@ -1808,7 +1808,7 @@ void Measure::adjustToLen(Fraction nf, bool appendRestsIfNecessary)
score()->undoInsertTime(startTick, diff);
score()->undo(new InsertTime(score(), startTick, diff));

for (Score* s : score()->scoreList()) {
for (Score*& s : score()->scoreList()) {
Measure* m = s->tick2measure(tick());
s->undo(new ChangeMeasureLen(m, nf));
if (nl > ol) {
Expand Down Expand Up @@ -3950,7 +3950,7 @@ void Measure::setEndBarLineType(BarLineType val, int track, bool visible, QColor
void Measure::barLinesSetSpan(Segment* seg)
{
int track = 0;
for (Staff* staff : score()->staves()) {
for (Staff*& staff : score()->staves()) {
BarLine* bl = toBarLine(seg->element(track)); // get existing bar line for this staff, if any
if (bl) {
if (bl->generated()) {
Expand Down Expand Up @@ -4236,7 +4236,7 @@ void Measure::addSystemHeader(bool isFirstSystem)
Segment* kSegment = findFirstR(SegmentType::KeySig, Fraction(0,1));
Segment* cSegment = findFirstR(SegmentType::HeaderClef, Fraction(0,1));

for (const Staff* staff : score()->staves()) {
for (Staff*& staff : score()->staves()) {
const int track = staffIdx * VOICES;

if (isFirstSystem || score()->styleB(Sid::genClef)) {
Expand Down
2 changes: 1 addition & 1 deletion libmscore/measurebase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ void MeasureBase::undoSetBreak(bool v, LayoutBreak::Type type)
if (v) {
LayoutBreak* lb = new LayoutBreak(score());
lb->setLayoutBreakType(type);
lb->setTrack(-1); // this are system elements
lb->setTrack(0); // these are system elements
MeasureBase* mb = (isMeasure() && toMeasure(this)->isMMRest()) ? toMeasure(this)->mmRestLast() : this;
lb->setParent(mb);
score()->undoAddElement(lb);
Expand Down
2 changes: 1 addition & 1 deletion libmscore/scoreElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ static const ElementName elementNames[] = {
{ ElementType::SCORE, "Score", QT_TRANSLATE_NOOP("elementName", "Score") },
{ ElementType::SYMBOL, "Symbol", QT_TRANSLATE_NOOP("elementName", "Symbol") },
{ ElementType::TEXT, "Text", QT_TRANSLATE_NOOP("elementName", "Text") },
{ ElementType::LAYOUT_BREAK, "LayoutBreak", QT_TRANSLATE_NOOP("elementName", "Layout Break") },
{ ElementType::MEASURE_NUMBER, "MeasureNumber", QT_TRANSLATE_NOOP("elementName", "Measure Number") },
{ ElementType::MMREST_RANGE, "MMRestRange", QT_TRANSLATE_NOOP("elementName", "Multimeasure Rest Range") },
{ ElementType::INSTRUMENT_NAME, "InstrumentName", QT_TRANSLATE_NOOP("elementName", "Instrument Name") },
Expand Down Expand Up @@ -90,7 +91,6 @@ static const ElementName elementNames[] = {
{ ElementType::PEDAL_SEGMENT, "PedalSegment", QT_TRANSLATE_NOOP("elementName", "Pedal Segment") },
{ ElementType::LYRICSLINE_SEGMENT, "LyricsLineSegment", QT_TRANSLATE_NOOP("elementName", "Melisma Line Segment") },
{ ElementType::GLISSANDO_SEGMENT, "GlissandoSegment", QT_TRANSLATE_NOOP("elementName", "Glissando Segment") },
{ ElementType::LAYOUT_BREAK, "LayoutBreak", QT_TRANSLATE_NOOP("elementName", "Layout Break") },
{ ElementType::SPACER, "Spacer", QT_TRANSLATE_NOOP("elementName", "Spacer") },
{ ElementType::STAFF_STATE, "StaffState", QT_TRANSLATE_NOOP("elementName", "Staff State") },
{ ElementType::NOTEHEAD, "NoteHead", QT_TRANSLATE_NOOP("elementName", "Notehead") },
Expand Down
2 changes: 1 addition & 1 deletion libmscore/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ enum class ElementType {
SCORE,
SYMBOL,
TEXT,
LAYOUT_BREAK,
MEASURE_NUMBER,
MMREST_RANGE,
INSTRUMENT_NAME,
Expand Down Expand Up @@ -96,7 +97,6 @@ enum class ElementType {
PEDAL_SEGMENT,
LYRICSLINE_SEGMENT,
GLISSANDO_SEGMENT,
LAYOUT_BREAK,
SPACER,
STAFF_STATE,
NOTEHEAD,
Expand Down
2 changes: 1 addition & 1 deletion mtest/libmscore/barline/tst_barline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ void TestBarline::barline05()
// create and add a LineBreak element
LayoutBreak* lb = new LayoutBreak(score);
lb->setLayoutBreakType(LayoutBreak::Type::LINE);
lb->setTrack(-1); // system-level element
lb->setTrack(0); // system-level element
lb->setParent(msr);
score->undoAddElement(lb);
score->doLayout();
Expand Down

0 comments on commit d0ca470

Please sign in to comment.