From a35b1eff4ab9a4ba42767bf5f7c2ca15bead10a3 Mon Sep 17 00:00:00 2001 From: Niek van den Berg Date: Fri, 1 May 2020 09:05:47 +0200 Subject: [PATCH] Fix #283964 - Linked parts for single voices don't work Corrects recognistion of linked staves with a part and linked staves over excerpts. --- libmscore/edit.cpp | 45 ++++++++++++++++++++++++++++++++++++--------- libmscore/score.cpp | 2 +- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/libmscore/edit.cpp b/libmscore/edit.cpp index 4cbdf6edf0499..35718e7dc3daf 100644 --- a/libmscore/edit.cpp +++ b/libmscore/edit.cpp @@ -4889,17 +4889,44 @@ void Score::undoAddCR(ChordRest* cr, Measure* measure, const Fraction& tick) Tuplet* t = cr->tuplet(); + // For linked staves the length of staffList is always > 1 since the list contains the staff itself too! + const bool linked = ostaff->staffList().length() > 1; + for (const Staff* staff : ostaff->staffList()) { QList tracks; - int staffIdx = staff->idx(); - if ((strack & ~3) != staffIdx) // linked staff ? - tracks.append(staffIdx * VOICES + (strack % VOICES)); - else if (staff->score()->excerpt() && !staff->score()->excerpt()->tracks().isEmpty()) - tracks = staff->score()->excerpt()->tracks().values(strack); - else if (!staff->score()->excerpt()) - tracks.append(staffIdx * VOICES + (strack % VOICES)); - else - tracks.append(staffIdx * VOICES + cr->voice()); + if (!staff->score()->excerpt()) { + // On masterScore. + int track = staff->idx() * VOICES + (strack % VOICES); + tracks.append(track); + } + else { + QMultiMap mapping = staff->score()->excerpt()->tracks(); + if (mapping.isEmpty()) { + // This can happen during reading the score and there is + // no Tracklist tag specified. + // TODO solve this in read301.cpp. + tracks.append(strack); + } + else { + // linkedPart : linked staves within same part/instrument. + // linkedScore: linked staves over different scores via excerpts. + const bool linkedPart = linked && (staff != ostaff) && (staff->score() == ostaff->score()); + const bool linkedScore = linked && (staff != ostaff) && (staff->score() != ostaff->score()); + for (int track : mapping.values(strack)) { + if (linkedPart && !linkedScore) { + tracks.append(staff->idx() * VOICES + mapping.value(track)); + } + else if (!linkedPart && linkedScore) { + if ((track >> 2) != staff->idx()) + track += (staff->idx() - (track >> 2)) * VOICES; + tracks.append(track); + } + else { + tracks.append(track); + } + } + } + } for (int ntrack : tracks) { if (ntrack < staff->part()->startTrack() || ntrack >= staff->part()->endTrack()) diff --git a/libmscore/score.cpp b/libmscore/score.cpp index c4aa5e05a3c8d..a2efc0b247662 100644 --- a/libmscore/score.cpp +++ b/libmscore/score.cpp @@ -1910,7 +1910,7 @@ void MasterScore::addExcerpt(Excerpt* ex) } } } - if (ex->tracks().isEmpty()) { // SHOULDN'T HAPPEN, protected in the UI + if (ex->tracks().isEmpty()) { // SHOULDN'T HAPPEN, protected in the UI, but it happens during read-in!!! QMultiMap tracks; for (Staff* s : score->staves()) { const LinkedElements* ls = s->links();