diff --git a/libmscore/barline.cpp b/libmscore/barline.cpp index 66a929a18a176..bc18f4efac534 100644 --- a/libmscore/barline.cpp +++ b/libmscore/barline.cpp @@ -830,7 +830,7 @@ void BarLine::endEdit() int idx2 = idx1 + _span; // set span 0 to all additional staves for (int idx = idx1 + 1; idx < idx2; ++idx) - // mensurstrich special case: + // Mensurstrich special case: // if line spans to top line of a stave AND current staff is // the last spanned staff BUT NOT the last score staff // keep its bar lines @@ -1286,7 +1286,7 @@ void BarLine::updateCustomType() } } _customSubtype = (_barLineType != refType); - updateGenerated(!_customSubtype); // if _customSubType, _genereated is surely false + updateGenerated(!_customSubtype); // if _customSubType, _generated is surely false } //--------------------------------------------------------- diff --git a/libmscore/measure.cpp b/libmscore/measure.cpp index 885a558a83cb7..d8945be43b0f7 100644 --- a/libmscore/measure.cpp +++ b/libmscore/measure.cpp @@ -2556,7 +2556,7 @@ bool Measure::createEndBarLines() BarLine* bl = 0; int span = 0; // span counter int aspan = 0; // actual span - bool mensur = false; // keep note of mensurstrich case + bool mensur = false; // keep note of Mensurstrich case int spanTot; // to keep track of the target span int spanFrom; int spanTo; @@ -2583,7 +2583,7 @@ bool Measure::createEndBarLines() } else { // otherwise, get from staff span = staff->barLineSpan(); - // if some span OR last staff (span=0) of a mensurstrich case, get From/To from staff + // if some span OR last staff (span=0) of a Mensurstrich case, get From/To from staff if (span || mensur) { spanFrom = staff->barLineFrom(); spanTo = staff->barLineTo(); @@ -2646,14 +2646,14 @@ bool Measure::createEndBarLines() // and the bar line for this staff (cbl) is not needed: // DELETE it if (cbl && cbl != bl) { - // mensurstrich special case: + // Mensurstrich special case: // if span arrives inside the end staff (spanTo>0) OR // span is not multi-staff (spanTot<=1) OR // current staff is not the last spanned staff (span!=1) OR // staff is the last score staff // remove bar line for this staff // If NONE of the above conditions holds, the staff is the last staff of - // a mensurstrich(-like) span: keep its bar line, as it may span to next staff + // a Mensurstrich(-like) span: keep its bar line, as it may span to next staff if (spanTo > 0 || spanTot <= 1 || span != 1 || staffIdx == nstaves-1) { score()->undoRemoveElement(cbl); changed = true; @@ -2690,7 +2690,7 @@ bool Measure::createEndBarLines() --span; } // if just finished (span==0) a multi-staff span (spanTot>1) ending at the top of a staff (spanTo<=0) - // scan this staff again, as it may have its own bar lines (mensurstich(-like) span) + // scan this staff again, as it may have its own bar lines (Mensurstrich(-like) span) if (spanTot > 1 && spanTo <= 0 && span == 0) { mensur = true; staffIdx--; diff --git a/mscore/instrdialog.cpp b/mscore/instrdialog.cpp index 955b9b88d53aa..868a083da37a2 100644 --- a/mscore/instrdialog.cpp +++ b/mscore/instrdialog.cpp @@ -22,6 +22,7 @@ #include "musescore.h" #include "scoreview.h" #include "seq.h" +#include "libmscore/barline.h" #include "libmscore/clef.h" #include "libmscore/excerpt.h" #include "libmscore/instrtemplate.h" @@ -389,7 +390,7 @@ void MuseScore::editInstrList() QList dl; int idx2 = 0; bool sort = false; - for(Staff* staff : dst) { + for (Staff* staff : dst) { int idx = rootScore->staves().indexOf(staff); if (idx == -1) qDebug("staff in dialog(%p) not found in score", staff); @@ -409,10 +410,62 @@ void MuseScore::editInstrList() // int n = rootScore->nstaves(); + int curSpan = 0; for (int i = 0; i < n; ++i) { Staff* staff = rootScore->staff(i); - if (staff->barLineSpan() > (n - i)) - rootScore->undoChangeBarLineSpan(staff, n - i, 0, (rootScore->staff(n-1)->lines()-1) * 2); + int span = staff->barLineSpan(); + int setSpan = -1; + + // determine if we need to update barline span + if (curSpan == 0) { + // no current span; this staff must start a new one + if (span == 0) { + // no span; this staff must have been within a span + // update it to a span of 1 + setSpan = 1; + } + else if (span > (n - i)) { + // span too big; staves must have been removed + // reduce span to last staff + setSpan = n - i; + } + else if (span > 1 && staff->barLineTo() > 0) { + // TODO: check if span is still valid + // (true if the last staff is the same as it was before this edit) + // the code here fixes https://musescore.org/en/node/41786 + // but by forcing an update, + // we lose custom modifications to staff barLineTo + // at least this happens only for span > 1, and not for Mensurstrich (barLineTo<=0) + setSpan = span; // force update to pick up new barLineTo value + } + else { + // this staff starts a span + curSpan = span; + } + } + else if (span && staff->barLineTo() > 0) { + // within a current span; staff must have span of 0 + // except for Mensurstrich (barLineTo<=0) + // for consistency with Barline::endEdit, + // don't special case 1-line staves + rootScore->undoChangeBarLineSpan(staff, 0, 0, (staff->lines() - 1) * 2); + } + + // update barline span if necessary + if (setSpan > 0) { + // this staff starts a span + curSpan = setSpan; + // calculate spanFrom and spanTo values + int spanFrom = staff->lines() == 1 ? BARLINE_SPAN_1LINESTAFF_FROM : 0; + int linesTo = rootScore->staff(i + setSpan - 1)->lines(); + int spanTo = linesTo == 1 ? BARLINE_SPAN_1LINESTAFF_TO : (linesTo - 1) * 2; + rootScore->undoChangeBarLineSpan(staff, setSpan, spanFrom, spanTo); + } + + // count off one from barline span + --curSpan; + + // update brackets QList brackets = staff->brackets(); int nn = brackets.size(); for (int ii = 0; ii < nn; ++ii) { @@ -420,6 +473,7 @@ void MuseScore::editInstrList() rootScore->undoChangeBracketSpan(staff, ii, n - i); } } + // // there should be at least one measure //