Skip to content

Commit

Permalink
Merge pull request #6110 from njvdberg/issue-305656-double-parts
Browse files Browse the repository at this point in the history
Fix #305656 Two piano instruments shown for a single piano part after…
  • Loading branch information
anatoly-os committed Jun 6, 2020
2 parents 4174c96 + c5de914 commit 7189a88
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
12 changes: 12 additions & 0 deletions libmscore/excerpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ Excerpt::~Excerpt() {
delete _partScore;
}

//---------------------------------------------------------
// nstaves
//---------------------------------------------------------

int Excerpt::nstaves() const
{
int n { 0 };
for (Part* p : _parts)
n += p->nstaves();
return n;
}

//---------------------------------------------------------
// read
//---------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions libmscore/excerpt.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Excerpt : public QObject {
QList<Part*>& parts() { return _parts; }
void setParts(const QList<Part*>& p) { _parts = p; }

int nstaves() const;

QMultiMap<int, int>& tracks() { return _tracks; }
void setTracks(const QMultiMap<int, int>& t) { _tracks = t; }
Expand Down
12 changes: 10 additions & 2 deletions libmscore/score.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1898,16 +1898,24 @@ void MasterScore::addExcerpt(Excerpt* ex)
{
Score* score = ex->partScore();

int nstaves { 1 }; // Initialise to 1 to force writing of the first part.
for (Staff* s : score->staves()) {
const LinkedElements* ls = s->links();
if (ls == 0)
continue;
for (auto le : *ls) {
if (le->score() != this)
continue;

// For instruments with multiple staves, every staff will point to the
// same part. To prevent adding the same part several times to the excerpt,
// add only the part of the first staff pointing to the part.
Staff* ps = toStaff(le);
if (ps->score() == this) {
if (!(--nstaves)) {
ex->parts().append(ps->part());
break;
nstaves = ps->part()->nstaves();
}
break;
}
}
if (ex->tracks().isEmpty()) { // SHOULDN'T HAPPEN, protected in the UI, but it happens during read-in!!!
Expand Down
2 changes: 1 addition & 1 deletion libmscore/scorefile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void Score::writeMovement(XmlWriter& xml, bool selectionOnly)
Excerpt* e = excerpt();
QMultiMap<int, int> trackList = e->tracks();
QMapIterator<int, int> i(trackList);
if (!(trackList.size() == e->parts().size() * VOICES) && !trackList.isEmpty()) {
if (!(trackList.size() == e->nstaves() * VOICES) && !trackList.isEmpty()) {
while (i.hasNext()) {
i.next();
xml.tagE(QString("Tracklist sTrack=\"%1\" dstTrack=\"%2\"").arg(i.key()).arg(i.value()));
Expand Down

0 comments on commit 7189a88

Please sign in to comment.