Skip to content

Commit

Permalink
fix #41786: barline span issues after edit / instrument
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcSabatella committed Jul 15, 2015
1 parent 2ab95b0 commit 0362ea0
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 10 deletions.
4 changes: 2 additions & 2 deletions libmscore/barline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

//---------------------------------------------------------
Expand Down
10 changes: 5 additions & 5 deletions libmscore/measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2554,7 +2554,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;
Expand All @@ -2581,7 +2581,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();
Expand Down Expand Up @@ -2644,14 +2644,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;
Expand Down Expand Up @@ -2688,7 +2688,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--;
Expand Down
60 changes: 57 additions & 3 deletions mscore/instrdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -389,7 +390,7 @@ void MuseScore::editInstrList()
QList<int> 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);
Expand All @@ -409,17 +410,70 @@ 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<BracketItem> brackets = staff->brackets();
int nn = brackets.size();
for (int ii = 0; ii < nn; ++ii) {
if ((brackets[ii]._bracket != BracketType::NO_BRACKET) && (brackets[ii]._bracketSpan > (n - i)))
rootScore->undoChangeBracketSpan(staff, ii, n - i);
}
}

//
// there should be at least one measure
//
Expand Down

0 comments on commit 0362ea0

Please sign in to comment.