Skip to content

Commit

Permalink
fix regressions for new mm rest implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed Sep 20, 2013
1 parent 7c7c601 commit 528d297
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 87 deletions.
40 changes: 16 additions & 24 deletions libmscore/layout.cpp
Expand Up @@ -565,25 +565,21 @@ void Score::doLayout()
createPlayEvents();

int measureNo = 0;
for (MeasureBase* m = first(); m; m = m->next()) {
if (m->type() == Element::MEASURE) {
Measure* measure = static_cast<Measure*>(m);
measureNo += measure->noOffset();
measure->setNo(measureNo);
if (measure->sectionBreak() && measure->sectionBreak()->startWithMeasureOne())
measureNo = 0;
else if (measure->irregular()) // dont count measure
;
else
++measureNo;
}
for (Measure* m = firstMeasure(); m; m = m->nextMeasure()) {
Measure* measure = static_cast<Measure*>(m);
measureNo += measure->noOffset();
measure->setNo(measureNo);
if (measure->sectionBreak() && measure->sectionBreak()->startWithMeasureOne())
measureNo = 0;
else if (measure->irregular()) // dont count measure
;
else
++measureNo;
measure->setBreakMMRest(false);
}

for (MeasureBase* m = first(); m; m = m->next()) {
for (MeasureBase* m = first(); m; m = m->next())
m->layout0();
if (m->type() == Element::MEASURE)
static_cast<Measure*>(m)->setBreakMMRest(false);
}

layoutFlags = 0;

Expand Down Expand Up @@ -928,6 +924,7 @@ void Score::createMMRests()
// create a multi measure rest from m to lm (inclusive)
// attach the measure to m
//
printf("create mm rest %d %d\n", n, _showVBox);
Measure* mmr = m->mmRest() ? m->mmRest() : new Measure(this);
mmr->setMMRestCount(n);
mmr->setTick(m->tick());
Expand Down Expand Up @@ -1417,7 +1414,7 @@ bool Score::layoutSystem1(qreal& minWidth, bool isFirstSystem, bool longName)

void Score::removeGeneratedElements(Measure* sm, Measure* em)
{
for (Measure* m = sm; m; m = m->nextMeasure()) {
for (Measure* m = sm; m; m = m->nextMeasureMM()) {
//
// remove generated elements from all measures in [sm;em]
// assume: generated elements are only living in voice 0
Expand Down Expand Up @@ -2033,12 +2030,7 @@ QList<System*> Score::layoutSystemRow(qreal rowWidth, bool isFirstSystem, bool u

void Score::layoutSystems()
{
curMeasure = _showVBox ? first() : firstMeasure();
if (curMeasure->type() == Element::MEASURE
&& styleB(ST_createMultiMeasureRests)
&& static_cast<Measure*>(curMeasure)->hasMMRest()) {
curMeasure = static_cast<Measure*>(curMeasure)->mmRest();
}
curMeasure = _showVBox ? firstMM() : firstMeasureMM();
curSystem = 0;
bool firstSystem = true;
bool startWithLongNames = true;
Expand All @@ -2061,7 +2053,7 @@ void Score::layoutSystems()
system->rxpos() = 0.0;
system->setPageBreak(vbox->pageBreak());
system->measures().push_back(vbox);
curMeasure = curMeasure->next();
curMeasure = curMeasure->nextMM();
++curSystem;
}
else {
Expand Down
36 changes: 13 additions & 23 deletions libmscore/measure.cpp
Expand Up @@ -544,12 +544,14 @@ void Measure::layout2()
if (parent() == 0)
return;

Q_ASSERT(score()->nstaves() == staves.size());

int tracks = score()->nstaves() * VOICES;
qreal _spatium = spatium();
int tracks = staves.size() * VOICES;
static const Segment::SegmentTypes st = Segment::SegChordRest;
for (int track = 0; track < tracks; ++track) {
for (Segment* s = first(st); s; s = s->next(st)) {
ChordRest* cr = static_cast<ChordRest*>(s->element(track));
ChordRest* cr = s->cr(track);
if (!cr)
continue;
int n = cr->lyricsList().size();
Expand All @@ -575,10 +577,8 @@ void Measure::layout2()
}
}
}
int n = staves.size();
for (int i = 0; i < n; ++i)
staves.at(i)->lines->setWidth(width());

for (MStaff* ms : staves)
ms->lines->setWidth(width());

MeasureBase::layout(); // layout LAYOUT_BREAK elements

Expand Down Expand Up @@ -610,7 +610,7 @@ void Measure::layout2()
int nn = 1;
if (!score()->styleB(ST_measureNumberAllStaffs)) {
//find first non invisible staff
for (int staffIdx = 0; staffIdx < n; ++staffIdx) {
for (int staffIdx = 0; staffIdx < staves.size(); ++staffIdx) {
MStaff* ms = staves.at(staffIdx);
SysStaff* s = system()->staff(staffIdx);
Staff* staff = score()->staff(staffIdx);
Expand All @@ -620,7 +620,7 @@ void Measure::layout2()
}
}
}
for (int staffIdx = 0; staffIdx < n; ++staffIdx) {
for (int staffIdx = 0; staffIdx < staves.size(); ++staffIdx) {
MStaff* ms = staves.at(staffIdx);
Text* t = ms->noText();
if (smn) {
Expand Down Expand Up @@ -1001,7 +1001,7 @@ void Measure::removeStaves(int sStaff, int eStaff)
s->removeStaff(staff);
}
}
foreach(Element* e, _el) {
foreach (Element* e, _el) {
if (e->track() == -1)
continue;
int voice = e->voice();
Expand All @@ -1011,8 +1011,6 @@ void Measure::removeStaves(int sStaff, int eStaff)
e->setTrack(staffIdx * VOICES + voice);
}
}
for (int i = 0; i < staves.size(); ++i)
staves[i]->setTrack(i * VOICES);
}

//---------------------------------------------------------
Expand All @@ -1021,7 +1019,7 @@ void Measure::removeStaves(int sStaff, int eStaff)

void Measure::insertStaves(int sStaff, int eStaff)
{
foreach(Element* e, _el) {
foreach (Element* e, _el) {
if (e->track() == -1)
continue;
int staffIdx = e->staffIdx();
Expand All @@ -1036,8 +1034,6 @@ void Measure::insertStaves(int sStaff, int eStaff)
s->insertStaff(staff);
}
}
for (int i = 0; i < staves.size(); ++i)
staves[i]->setTrack(i * VOICES);
}

//---------------------------------------------------------
Expand Down Expand Up @@ -1080,9 +1076,6 @@ qDebug("cmdRemoveStaves %d-%d", sStaff, eStaff);
for (int i = eStaff - 1; i >= sStaff; --i)
_score->undo(new RemoveMStaff(this, *(staves.begin()+i), i));

for (int i = 0; i < staves.size(); ++i)
staves[i]->lines->setTrack(i * VOICES);

// barLine
// TODO
}
Expand Down Expand Up @@ -1156,11 +1149,10 @@ void MStaff::setTrack(int track)

void Measure::insertMStaff(MStaff* staff, int idx)
{
printf("insertMStaff %d\n", idx);
staves.insert(idx, staff);
for (int staffIdx = 0; staffIdx < staves.size(); ++staffIdx)
staves[staffIdx]->setTrack(staffIdx * VOICES);
if (MScore::debugMode)
qDebug(" Measure::insertMStaff %d -> n:%d", idx, staves.size());
}

//---------------------------------------------------------
Expand All @@ -1169,9 +1161,7 @@ void Measure::insertMStaff(MStaff* staff, int idx)

void Measure::removeMStaff(MStaff* /*staff*/, int idx)
{
if (MScore::debugMode)
qDebug(" Measure::removeMStaff %d", idx);

printf("removeMStaff %d\n", idx);
staves.removeAt(idx);
for (int staffIdx = 0; staffIdx < staves.size(); ++staffIdx)
staves[staffIdx]->setTrack(staffIdx * VOICES);
Expand Down Expand Up @@ -2518,7 +2508,7 @@ void Measure::setEndBarLineType(BarLineType val, bool g, bool visible, QColor co
void Measure::sortStaves(QList<int>& dst)
{
QList<MStaff*> ms;
foreach(int idx, dst)
foreach (int idx, dst)
ms.push_back(staves[idx]);
staves = ms;

Expand Down
10 changes: 3 additions & 7 deletions libmscore/measurebase.cpp
Expand Up @@ -195,13 +195,9 @@ Measure* MeasureBase::nextMeasureMM() const
m = m->_next;
}
Measure* mm = static_cast<Measure*>(m);
if (mm
&& mm->type() == MEASURE
&& score()->styleB(ST_createMultiMeasureRests)
&& static_cast<Measure*>(mm)->hasMMRest()) {
return static_cast<Measure*>(mm)->mmRest();
}
return static_cast<Measure*>(mm);
if (mm && score()->styleB(ST_createMultiMeasureRests) && mm->hasMMRest())
return mm->mmRest();
return mm;
}

//---------------------------------------------------------
Expand Down
60 changes: 29 additions & 31 deletions libmscore/score.cpp
Expand Up @@ -1596,13 +1596,10 @@ Measure* Score::firstMeasureMM() const
MeasureBase* mb = _measures.first();
while (mb && mb->type() != Element::MEASURE)
mb = mb->next();
if (mb
&& mb->type() == Element::MEASURE
&& styleB(ST_createMultiMeasureRests)
&& static_cast<Measure*>(mb)->hasMMRest()) {
return static_cast<Measure*>(mb)->mmRest();
}
return static_cast<Measure*>(mb);
Measure* m = static_cast<Measure*>(mb);
if (m && styleB(ST_createMultiMeasureRests) && m->hasMMRest())
return m->mmRest();
return m;
}

//---------------------------------------------------------
Expand Down Expand Up @@ -2038,7 +2035,7 @@ void Score::removeExcerpt(Score* score)

void Score::updateNotes()
{
for (Measure* m = firstMeasure(); m; m = m->nextMeasure()) {
for (Measure* m = firstMeasureMM(); m; m = m->nextMeasureMM()) {
for (int staffIdx = 0; staffIdx < nstaves(); ++staffIdx) {
AccidentalState tversatz; // state of already set accidentals for this measure
tversatz.init(staff(staffIdx)->keymap()->key(m->tick()));
Expand All @@ -2059,7 +2056,7 @@ void Score::updateNotes()

void Score::cmdUpdateNotes()
{
for (Measure* m = firstMeasure(); m; m = m->nextMeasure()) {
for (Measure* m = firstMeasureMM(); m; m = m->nextMeasureMM()) {
for (int staffIdx = 0; staffIdx < nstaves(); ++staffIdx)
updateAccidentals(m, staffIdx);
}
Expand All @@ -2075,7 +2072,7 @@ void Score::cmdUpdateAccidentals(Measure* beginMeasure, int staffIdx)
// qDebug("cmdUpdateAccidentals m=%d for staff=%d",
// beginMeasure->no(), staffIdx);
Staff* st = staff(staffIdx);
for (Measure* m = beginMeasure; m; m = m->nextMeasure()) {
for (Measure* m = beginMeasure; m; m = m->nextMeasureMM()) {
AccidentalState as;
as.init(st->keymap()->key(m->tick()));

Expand Down Expand Up @@ -2257,8 +2254,11 @@ void Score::splitStaff(int staffIdx, int splitPoint)

undoInsertStaff(ns, staffIdx+1);

for (Measure* m = firstMeasure(); m; m = m->nextMeasure())
for (Measure* m = firstMeasure(); m; m = m->nextMeasure()) {
m->cmdAddStaves(staffIdx+1, staffIdx+2, false);
if (m->hasMMRest())
m->mmRest()->cmdAddStaves(staffIdx+1, staffIdx+2, false);
}

Clef* clef = new Clef(this);
clef->setClefType(ClefType::F);
Expand All @@ -2269,16 +2269,6 @@ void Score::splitStaff(int staffIdx, int splitPoint)

undoChangeKeySig(ns, 0, s->key(0));

#if 0 // created on layout
Bracket* b = new Bracket(this);
b->setSubtype(BRACKET_AKKOLADE);
b->setTrack(staffIdx * VOICES);
b->setParent(firstMeasure()->system());
b->setLevel(-1); // add bracket
b->setSpan(2);
undoAddElement(b);
#endif

rebuildMidiMapping();
_instrumentsChanged = true;
doLayout();
Expand Down Expand Up @@ -2392,8 +2382,12 @@ void Score::cmdInsertPart(Part* part, int staffIdx)

int sidx = this->staffIdx(part);
int eidx = sidx + part->nstaves();
for (Measure* m = firstMeasure(); m; m = m->nextMeasure())
for (Measure* m = firstMeasure(); m; m = m->nextMeasure()) {
m->cmdAddStaves(sidx, eidx, true);
if (m->hasMMRest())
m->mmRest()->cmdAddStaves(sidx, eidx, true);
}

adjustBracketsIns(sidx, eidx);
}

Expand All @@ -2407,16 +2401,18 @@ void Score::cmdRemovePart(Part* part)
int n = part->nstaves();
int eidx = sidx + n;

// qDebug("cmdRemovePart %d-%d", sidx, eidx);

//
// adjust measures
//
for (Measure* m = firstMeasure(); m; m = m->nextMeasure())
for (Measure* m = firstMeasure(); m; m = m->nextMeasure()) {
m->cmdRemoveStaves(sidx, eidx);
if (m->hasMMRest())
m->mmRest()->cmdRemoveStaves(sidx, eidx);
}

for (int i = 0; i < n; ++i)
cmdRemoveStaff(sidx);

undoRemovePart(part, sidx);
}

Expand Down Expand Up @@ -2559,8 +2555,11 @@ void Score::cmdRemoveStaff(int staffIdx)
int lstaffIdx = lscore->staffIdx(staff);
int pIndex = lscore->staffIdx(staff->part());
//adjustBracketsDel(lstaffIdx, lstaffIdx+1);
for (Measure* m = lscore->firstMeasure(); m; m = m->nextMeasure())
for (Measure* m = lscore->firstMeasure(); m; m = m->nextMeasure()) {
m->cmdRemoveStaves(lstaffIdx, lstaffIdx + 1);
if (m->hasMMRest())
m->mmRest()->cmdRemoveStaves(lstaffIdx, lstaffIdx + 1);
}
undoRemoveStaff(staff, lstaffIdx);
if (staff->part()->nstaves() == 0)
undoRemovePart(staff->part(), pIndex);
Expand Down Expand Up @@ -2589,7 +2588,7 @@ void Score::sortStaves(QList<int>& dst)
_parts.clear();
Part* curPart = 0;
QList<Staff*> dl;
foreach(int idx, dst) {
foreach (int idx, dst) {
Staff* staff = _staves[idx];
if (staff->part() != curPart) {
curPart = staff->part();
Expand All @@ -2601,11 +2600,10 @@ void Score::sortStaves(QList<int>& dst)
}
_staves = dl;

for (MeasureBase* mb = _measures.first(); mb; mb = mb->next()) {
if (mb->type() != Element::MEASURE)
continue;
Measure* m = static_cast<Measure*>(mb);
for (Measure* m = firstMeasure(); m; m = m->nextMeasure()) {
m->sortStaves(dst);
if (m->hasMMRest())
m->mmRest()->sortStaves(dst);
}
}

Expand Down
6 changes: 5 additions & 1 deletion libmscore/segment.h
Expand Up @@ -119,7 +119,11 @@ class Segment : public Element {

ChordRest* nextChordRest(int track, bool backwards = false) const;

Q_INVOKABLE Ms::Element* element(int track) const { return _elist.value(track); }
Q_INVOKABLE Ms::Element* element(int track) const { return _elist.value(track); }
ChordRest* cr(int track) const {
Q_ASSERT(_segmentType == SegChordRest);
return (ChordRest*)(_elist.value(track));
};
const QList<Element*>& elist() const { return _elist; }

void removeElement(int track);
Expand Down
2 changes: 1 addition & 1 deletion vtest/gen
Expand Up @@ -3,7 +3,7 @@
#
# "compare" - image magick compare program
#
SRC="mmrest-1 mmrest-2 mmrest-4\
SRC="mmrest-1 mmrest-2 mmrest-4 mmrest-5 mmrest-6\
fmrest-1 fmrest-2 fmrest-3 fmrest-4 fmrest-5 measure-repeat-1"

MSCORE=../build.debug/mscore/mscore
Expand Down
Binary file modified vtest/mmrest-1-ref.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified vtest/mmrest-2-ref.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vtest/mmrest-5-ref.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vtest/mmrest-5.mscz
Binary file not shown.
Binary file added vtest/mmrest-6-ref.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vtest/mmrest-6.mscz
Binary file not shown.

0 comments on commit 528d297

Please sign in to comment.