Skip to content

Commit

Permalink
factorize hide empty staff code
Browse files Browse the repository at this point in the history
  • Loading branch information
lasconic committed Mar 29, 2013
1 parent 143dbea commit 15c1263
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 69 deletions.
79 changes: 10 additions & 69 deletions libmscore/layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,15 @@ bool Score::layoutSystem(qreal& minWidth, qreal w, bool isFirstSystem, bool long
if (!undoRedo() && firstMeasure && lastMeasure && firstMeasure != lastMeasure)
removeGeneratedElements(firstMeasure, lastMeasure);

//
hideEmptyStaves(system, isFirstSystem);

return continueFlag && curMeasure;
}


void Score::hideEmptyStaves(System* system, bool isFirstSystem)
{
//
// hide empty staves
//
int staves = _staves.size();
Expand Down Expand Up @@ -1138,7 +1146,6 @@ bool Score::layoutSystem(qreal& minWidth, qreal w, bool isFirstSystem, bool long
}
++staffIdx;
}
return continueFlag && curMeasure;
}

//---------------------------------------------------------
Expand Down Expand Up @@ -1245,74 +1252,8 @@ bool Score::layoutSystem1(qreal& minWidth, bool isFirstSystem, bool longName)
curMeasure = nextMeasure;
}

//
// hide empty staves
//
int staves = _staves.size();
int staffIdx = 0;
foreach (Staff* staff, _staves) {
SysStaff* s = system->staff(staffIdx);
bool oldShow = s->show();
if (styleB(ST_hideEmptyStaves)
&& (staves > 1)
&& !(isFirstSystem && styleB(ST_dontHideStavesInFirstSystem))
) {
bool hideStaff = true;
foreach(MeasureBase* m, system->measures()) {
if (m->type() != Element::MEASURE)
continue;
Measure* measure = static_cast<Measure*>(m);
if (!measure->isMeasureRest(staffIdx)) {
hideStaff = false;
break;
}
}
// check if notes moved into this staff
Part* part = staff->part();
int n = part->nstaves();
if (hideStaff && (n > 1)) {
int idx = part->staves()->front()->idx();
for (int i = 0; i < part->nstaves(); ++i) {
int st = idx + i;
hideEmptyStaves(system,isFirstSystem);

foreach(MeasureBase* mb, system->measures()) {
if (mb->type() != Element::MEASURE)
continue;
Measure* m = static_cast<Measure*>(mb);
for (Segment* s = m->first(Segment::SegChordRest); s; s = s->next(Segment::SegChordRest)) {
for (int voice = 0; voice < VOICES; ++voice) {
ChordRest* cr = static_cast<ChordRest*>(s->element(st * VOICES + voice));
if (cr == 0 || cr->type() == Element::REST)
continue;
int staffMove = cr->staffMove();
if (staffIdx == st + staffMove) {
hideStaff = false;
break;
}
}
}
if (!hideStaff)
break;
}
if (!hideStaff)
break;
}
}
s->setShow(hideStaff ? false : staff->show());
}
else {
s->setShow(true);
}

if (oldShow != s->show()) {
foreach (MeasureBase* mb, system->measures()) {
if (mb->type() != Element::MEASURE)
continue;
static_cast<Measure*>(mb)->createEndBarLines();
}
}
++staffIdx;
}
return continueFlag && curMeasure;
}

Expand Down
2 changes: 2 additions & 0 deletions libmscore/score.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,8 @@ class Score : public QObject {
void transposeKeys(int staffStart, int staffEnd, int tickStart, int tickEnd, const Interval&);
void reLayout(Measure*);

void hideEmptyStaves(System* system, bool isFirstSystem);

void checkSlurs();
void checkScore();
bool rewriteMeasures(Measure* fm, Measure* lm, const Fraction&);
Expand Down

0 comments on commit 15c1263

Please sign in to comment.