Skip to content

Commit

Permalink
Merge pull request #2059 from MarcSabatella/63961-parts
Browse files Browse the repository at this point in the history
fix #63961: mid-measure barline span not respected in parts
  • Loading branch information
lasconic committed Jun 23, 2015
2 parents 654c6ad + e653f64 commit 2d32d74
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 4 deletions.
59 changes: 56 additions & 3 deletions libmscore/barline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,6 @@ void BarLine::getY(qreal* y1, qreal* y2) const
int staffIdx1 = staffIdx();
int staffIdx2 = staffIdx1 + _span - 1;
if (staffIdx2 >= score()->nstaves()) {
// this can happen on read
// as we may be laying out a barline that spans multiple staves
// before we have read the staves it spans
qDebug("BarLine: bad _span %d", _span);
staffIdx2 = score()->nstaves() - 1;
}
Expand Down Expand Up @@ -740,6 +737,13 @@ void BarLine::endEdit()
// if bar line belongs to a system (system-initial bar line), edit is local
if (parent() && parent()->type() == Element::Type::SYSTEM)
ctrlDrag = true;
// for mid-measure barlines, edit is local
bool midMeasure = false;
if (parent()->type() == Element::Type::SEGMENT
&& static_cast<Segment*>(parent())->segmentType() == Segment::Type::BarLine) {
ctrlDrag = true;
midMeasure = true;
}

if (ctrlDrag) { // if single bar line edit
ctrlDrag = false;
Expand All @@ -750,6 +754,55 @@ void BarLine::endEdit()
_span = _origSpan; // restore original span values
_spanFrom = _origSpanFrom;
_spanTo = _origSpanTo;
// for mid-measure barline in root score, update parts
if (midMeasure && score()->parentScore() == nullptr && score()->excerpts().size() > 0) {
int currIdx = staffIdx();
Measure* m = static_cast<Segment*>(parent())->measure();
// change linked barlines as necessary
int lastIdx = currIdx + qMax(_span, newSpan);
for (int idx = currIdx; idx < lastIdx; ++idx) {
Staff* staff = score()->staff(idx);
LinkedStaves* ls = staff->linkedStaves();
if (ls) {
for (Staff* lstaff : ls->staves()) {
Score* lscore = lstaff->score();
// don't change barlines in root score
if (lscore == staff->score())
continue;
// change barline only in top staff of part
if (lstaff != lscore->staff(0))
continue;
int spannedStaves = qMax(currIdx + newSpan - idx, 0);
int lNewSpan = qMin(spannedStaves, lscore->nstaves());
Measure* lm = lscore->tick2measure(m->tick());
Segment* lseg = lm->undoGetSegment(Segment::Type::BarLine, tick());
BarLine* lbl = static_cast<BarLine*>(lseg->element(0));
if (lbl) {
// already a barline here
if (lNewSpan > 0) {
// keep barline, but update span if necessary
if (lbl->span() != lNewSpan)
lbl->undoChangeProperty(P_ID::BARLINE_SPAN, lNewSpan);
}
else {
// remove barline
lbl->unlink();
lbl->score()->undoRemoveElement(lbl);
}
}
else {
// new barline needed
lbl = static_cast<BarLine*>(linkedClone());
lbl->setSpan(lNewSpan);
lbl->setTrack(lstaff->idx() * VOICES);
lbl->setScore(lscore);
lbl->setParent(lseg);
lscore->undoAddElement(lbl);
}
}
}
}
}
score()->undoChangeSingleBarLineSpan(this, newSpan, newSpanFrom, newSpanTo);
return;
}
Expand Down
38 changes: 37 additions & 1 deletion libmscore/excerpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "beam.h"
#include "utils.h"
#include "tremolo.h"
#include "barline.h"
#include "undo.h"

namespace Ms {
Expand Down Expand Up @@ -393,6 +394,37 @@ void cloneStaves(Score* oscore, Score* score, const QList<int>& map)
continue;

Element* oe = oseg->element(srcTrack);
int adjustedBarlineSpan = 0;
if (srcTrack % VOICES == 0 && oseg->segmentType() == Segment::Type::BarLine) {
// mid-measure barline segment
// may need to clone barline from a previous staff and/or adjust span
int oIdx = srcTrack / VOICES;
if (!oe) {
// no barline on this staff in original score,
// but check previous staves
for (int i = oIdx - 1; i >= 0; --i) {
oe = oseg->element(i * VOICES);
if (oe)
break;
}
}
if (oe) {
// barline found, now check span
BarLine* bl = static_cast<BarLine*>(oe);
int oSpan1 = bl->staff()->idx();
int oSpan2 = oSpan1 + bl->span();
if (oSpan1 <= oIdx && oIdx < oSpan2) {
// this staff is within span
// calculate adjusted span for excerpt
int oSpan = oSpan2 - oIdx;
adjustedBarlineSpan = qMin(oSpan, score->nstaves());
}
else {
// this staff is not within span
oe = nullptr;
}
}
}
if (oe == 0)
continue;
Element* ne;
Expand All @@ -403,7 +435,11 @@ void cloneStaves(Score* oscore, Score* score, const QList<int>& map)
ne->setTrack(track);
ne->scanElements(score, localSetScore); //necessary?
ne->setScore(score);
if (oe->isChordRest()) {
if (oe->type() == Element::Type::BAR_LINE && adjustedBarlineSpan) {
BarLine* nbl = static_cast<BarLine*>(ne);
nbl->setSpan(adjustedBarlineSpan);
}
else if (oe->isChordRest()) {
ChordRest* ocr = static_cast<ChordRest*>(oe);
ChordRest* ncr = static_cast<ChordRest*>(ne);

Expand Down

0 comments on commit 2d32d74

Please sign in to comment.