Skip to content

Commit

Permalink
Clone barlines to part
Browse files Browse the repository at this point in the history
Backport of musescore#24925, also fix some clazy warnings
  • Loading branch information
miiizen authored and Jojo-Schmitz committed Sep 27, 2024
1 parent c251674 commit 4cfc597
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions libmscore/excerpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

#include "barline.h"
#include "beam.h"
#include "bracketItem.h"
#include "box.h"
#include "bracketItem.h"
#include "chord.h"
#include "excerpt.h"
#include "harmony.h"
Expand Down Expand Up @@ -184,7 +184,7 @@ void Excerpt::createExcerpt(Excerpt* excerpt)
// Fill tracklist (map all tracks of a stave)
if (excerpt->tracks().isEmpty()) {
QMultiMap<int, int> tracks;
for (Staff* s : score->staves()) {
for (Staff* s : qAsConst(score->staves())) {
const LinkedElements* ls = s->links();
if (ls == 0)
continue;
Expand Down Expand Up @@ -232,7 +232,7 @@ void Excerpt::createExcerpt(Excerpt* excerpt)

// handle transposing instruments
if (oscore->styleB(Sid::concertPitch) != score->styleB(Sid::concertPitch)) {
for (const Staff* staff : score->staves()) {
for (const Staff* staff : qAsConst(score->staves())) {
if (staff->staffType(Fraction(0,1))->group() == StaffGroup::PERCUSSION)
continue;

Expand Down Expand Up @@ -313,10 +313,10 @@ void MasterScore::deleteExcerpt(Excerpt* excerpt)
}

// unlink the staves in the excerpt
for (Staff* st : partScore->staves()) {
for (Staff* st : qAsConst(partScore->staves())) {
bool hasLinksInMaster = false;
if (st->links()) {
for (auto le : *st->links()) {
for (auto& le : *st->links()) {
if (le->score() == this) {
hasLinksInMaster = true;
break;
Expand Down Expand Up @@ -376,7 +376,7 @@ static void cloneSpanner(Spanner* s, Score* score, int dstTrack, int dstTrack2)
ns->setStartElement(0);
ns->setEndElement(0);
if (cr1 && cr1->links()) {
for (ScoreElement* e : *cr1->links()) {
for (ScoreElement* e : qAsConst(*cr1->links())) {
ChordRest* cr = toChordRest(e);
if (cr == cr1)
continue;
Expand All @@ -387,7 +387,7 @@ static void cloneSpanner(Spanner* s, Score* score, int dstTrack, int dstTrack2)
}
}
if (cr2 && cr2->links()) {
for (ScoreElement* e : *cr2->links()) {
for (ScoreElement* e : qAsConst(*cr2->links())) {
ChordRest* cr = toChordRest(e);
if (cr == cr2)
continue;
Expand Down Expand Up @@ -580,7 +580,7 @@ void Excerpt::cloneStaves(Score* oscore, Score* score, const QList<int>& map, QM
BarLine* bl = toBarLine(oe);
int oSpan1 = bl->staff()->idx();
int oSpan2 = oSpan1 + bl->spanStaff();
if (oSpan1 <= oIdx && oIdx < oSpan2) {
if (oSpan1 <= oIdx && oIdx <= oSpan2) {
// this staff is within span
// calculate adjusted span for excerpt
int oSpan = oSpan2 - oIdx;
Expand Down Expand Up @@ -725,7 +725,8 @@ void Excerpt::cloneStaves(Score* oscore, Score* score, const QList<int>& map, QM
}
}

nmb->linkTo(mb);
if (nmb)
nmb->linkTo(mb);
for (Element* e : mb->el()) {
if (e->isLayoutBreak()) {
LayoutBreak::Type st = toLayoutBreak(e)->layoutBreakType();
Expand Down Expand Up @@ -764,7 +765,8 @@ void Excerpt::cloneStaves(Score* oscore, Score* score, const QList<int>& map, QM
ne = e->clone();
ne->setScore(score);
ne->setTrack(track);
nmb->add(ne);
if (nmb)
nmb->add(ne);
}
nmbl->add(nmb);
}
Expand Down Expand Up @@ -798,7 +800,7 @@ void Excerpt::cloneStaves(Score* oscore, Score* score, const QList<int>& map, QM
span = n - dstStaffIdx - 1;
dstStaff->setBarLineSpan(span);
int idx = 0;
for (BracketItem* bi : srcStaff->brackets()) {
for (BracketItem* bi : qAsConst(srcStaff->brackets())) {
dstStaff->setBracketType(idx, bi->bracketType());
dstStaff->setBracketSpan(idx, bi->bracketSpan());
++idx;
Expand Down Expand Up @@ -1087,7 +1089,7 @@ void Excerpt::cloneStaff2(Staff* srcStaff, Staff* dstStaff, const Fraction& stic
map.insert(i, otracks.key(i));
}
else if (!oex && ex) {
for (int j : tracks.values(i)) {
for (int& j : tracks.values(i)) {
if (dstStaffIdx * VOICES <= j && j < (dstStaffIdx + 1) * VOICES) {
map.insert(i, j);
break;
Expand All @@ -1096,7 +1098,7 @@ void Excerpt::cloneStaff2(Staff* srcStaff, Staff* dstStaff, const Fraction& stic
}
else if (oex && ex) {
if (otracks.key(i, -1) != -1) {
for (int j : tracks.values(otracks.key(i))) {
for (int& j : tracks.values(otracks.key(i))) {
if (dstStaffIdx * VOICES <= j && j < (dstStaffIdx + 1) * VOICES) {
map.insert(i, j);
break;
Expand All @@ -1123,7 +1125,7 @@ void Excerpt::cloneStaff2(Staff* srcStaff, Staff* dstStaff, const Fraction& stic
score->undoAddElement(newEl);
}

for (int srcTrack : map.keys()) {
for (int srcTrack : map) {
TupletMap tupletMap; // tuplets cannot cross measure boundaries
int dstTrack = map.value(srcTrack);
for (Segment* oseg = m->first(); oseg; oseg = oseg->next()) {
Expand Down Expand Up @@ -1242,7 +1244,7 @@ void Excerpt::cloneStaff2(Staff* srcStaff, Staff* dstStaff, const Fraction& stic
QList<Excerpt*> Excerpt::createAllExcerpt(MasterScore *score)
{
QList<Excerpt*> all;
for (Part* part : score->parts()) {
for (Part* part : qAsConst(score->parts())) {
if (part->show()) {
Excerpt* e = new Excerpt(score);
e->parts().append(part);
Expand Down

0 comments on commit 4cfc597

Please sign in to comment.