Skip to content
Permalink
Browse files

fix some regressions for mm rests

  • Loading branch information...
wschweer committed Sep 27, 2013
1 parent eee9f5f commit 7d919a97e9d84e76bf6dc786b1a97b828af02808
@@ -2360,7 +2360,14 @@ void Score::cmd(const QAction* a)
Element* e = selection().element();
if (e && e->type() == Element::BAR_LINE && e->parent()->type() == Element::SEGMENT) {
Measure* measure = static_cast<Measure*>(e->parent()->parent());
measure->undoSetBreak(!measure->lineBreak(), type);
if (measure->isMMRest()) {
// if measure is mm rest, then propagate to last original measure
measure = measure->nextMeasure();
if (measure)
measure = measure->prevMeasure();
}
if (measure)
measure->undoSetBreak(!measure->lineBreak(), type);
}
}
else if (cmd == "reset-stretch")
@@ -1261,6 +1261,23 @@ void Score::deleteItem(Element* el)
undoRemoveBracket(static_cast<Bracket*>(el));
break;

case Element::LAYOUT_BREAK:
{
undoRemoveElement(el);
LayoutBreak* lb = static_cast<LayoutBreak*>(el);
Measure* m = lb->measure();
if (m->isMMRest()) {
m = static_cast<Measure*>(m->next()->prev());
foreach(Element* e, *m->el()) {
if (e->type() == Element::LAYOUT_BREAK) {
undoRemoveElement(e);
break;
}
}
}
}
break;

default:
undoRemoveElement(el);
break;
@@ -910,6 +910,7 @@ void Score::createMMRests()
int n = 0;
Fraction len;
while (nm->isEmpty()) {
m->setMMRestCount(0);
MeasureBase* mb = _showVBox ? nm->next() : nm->nextMeasure();
if (nm->breakMultiMeasureRest() && n)
break;
@@ -926,6 +927,11 @@ void Score::createMMRests()
// create a multi measure rest from m to lm (inclusive)
// attach the measure to m
//
for (Measure* mm = m->nextMeasure(); mm; mm = mm->nextMeasure()) {
mm->setMMRestCount(-1);
if (mm == lm)
break;
}
Measure* mmr;
if (m->mmRest()) {
mmr = m->mmRest();
@@ -944,7 +950,15 @@ void Score::createMMRests()
mmr->setMMRestCount(n);
mmr->setTick(m->tick());
mmr->setNo(m->no());
mmr->setPageBreak(lm->pageBreak());
mmr->setLineBreak(lm->lineBreak());
mmr->setSectionBreak(lm->sectionBreak());
mmr->setEndBarLineType(lm->endBarLineType(), false, lm->endBarLineVisible(), lm->endBarLineColor());
qDeleteAll(*mmr->el());
mmr->el()->clear();
for (Element* e : *lm->el())
mmr->add(e->clone());

Segment* s = mmr->getSegment(Segment::SegChordRest, m->tick());
for (int staffIdx = 0; staffIdx < _staves.size(); ++staffIdx) {
int track = staffIdx * VOICES;
@@ -131,6 +131,8 @@ class Measure : public MeasureBase {

Measure* _mmRest; // multi measure rest which replaces a measure range
int _mmRestCount; // > 0 if this is a multi measure rest
// 0 if this is the start of a mm rest (_mmRest != 0)
// < 0 if this measure is covered by a mm rest

void push_back(Segment* e);
void push_front(Segment* e);
@@ -288,7 +290,7 @@ class Measure : public MeasureBase {
virtual QVariant propertyDefault(P_ID) const override;

bool hasMMRest() const { return _mmRest != 0; }
bool isMMRest() const { return _mmRestCount != 0; }
bool isMMRest() const { return _mmRestCount > 0; }
Measure* mmRest() const { return _mmRest; }
void setMMRest(Measure* m) { _mmRest = m; }
int mmRestCount() const { return _mmRestCount; } // number of measures _mmRest spans
@@ -215,6 +215,31 @@ Measure* MeasureBase::prevMeasure() const
return 0;
}

//---------------------------------------------------------
// prevMeasure
//---------------------------------------------------------

Measure* MeasureBase::prevMeasureMM() const
{
MeasureBase* m = prev();
while (m) {
if (m->type() == MEASURE) {
Measure* mm = static_cast<Measure*>(m);
if (score()->styleB(ST_createMultiMeasureRests)) {
if (mm->mmRestCount() >= 0) {
if (mm->hasMMRest())
return mm->mmRest();
return mm;
}
}
else
return mm;
}
m = m->prev();
}
return 0;
}

//---------------------------------------------------------
// pause
//---------------------------------------------------------
@@ -70,6 +70,7 @@ class MeasureBase : public Element {
Q_INVOKABLE Ms::Measure* nextMeasure() const;
Q_INVOKABLE Ms::Measure* prevMeasure() const;
Ms::Measure* nextMeasureMM() const;
Ms::Measure* prevMeasureMM() const;

virtual int ticks() const { return 0; }
virtual void write(Xml&, int, bool) const = 0;
@@ -2857,7 +2857,8 @@ void Score::select(Element* e, SelectType type, int staffIdx)
int etick = tick + m->ticks();
if (_selection.state() == SEL_NONE) {
_selection.setStartSegment(m->tick2segment(tick));
_selection.setEndSegment(m == lastMeasure() ? 0 : tick2segment(etick));
// _selection.setEndSegment(m == lastMeasure() ? 0 : tick2segment(etick));
_selection.setEndSegment(m == lastMeasure() ? 0 : m->last());
}
else {
select(0, SELECT_SINGLE, 0);
@@ -2897,7 +2898,8 @@ void Score::select(Element* e, SelectType type, int staffIdx)
_selection.setStaffStart(staffIdx);
_selection.setStaffEnd(staffIdx + 1);
_selection.setStartSegment(m->tick2segment(tick));
_selection.setEndSegment(m == lastMeasure() ? 0 : tick2segment(etick));
// _selection.setEndSegment(m == lastMeasure() ? 0 : tick2segment(etick));
_selection.setEndSegment(m == lastMeasure() ? 0 : m->last());
}
else if (_selection.state() == SEL_RANGE) {
if (staffIdx < _selection.staffStart())
@@ -2909,14 +2911,16 @@ void Score::select(Element* e, SelectType type, int staffIdx)
activeIsFirst = true;
}
else if (etick >= _selection.tickEnd())
_selection.setEndSegment(m == lastMeasure() ? 0 : tick2segment(etick));
//_selection.setEndSegment(m == lastMeasure() ? 0 : tick2segment(etick));
_selection.setEndSegment(m == lastMeasure() ? 0 : m->last());
else {
if (_selection.activeSegment() == _selection.startSegment()) {
_selection.setStartSegment(m->tick2segment(tick));
activeIsFirst = true;
}
else
_selection.setEndSegment(m == lastMeasure() ? 0 : tick2segment(etick));
//_selection.setEndSegment(m == lastMeasure() ? 0 : tick2segment(etick));
_selection.setEndSegment(m == lastMeasure() ? 0 : m->last());
}
}
else if (_selection.isSingle()) {
@@ -2943,9 +2947,9 @@ void Score::select(Element* e, SelectType type, int staffIdx)
if (el && el->isChordRest())
break;
if (reverse)
seg = seg->prev1();
seg = seg->prev1MM();
else
seg = seg->next1();
seg = seg->next1MM();
if (!seg)
break;
}
@@ -247,6 +247,15 @@ Segment* Segment::next1(SegmentTypes types) const
return 0;
}

Segment* Segment::next1MM(SegmentTypes types) const
{
for (Segment* s = next1MM(); s; s = s->next1MM()) {
if (s->segmentType() & types)
return s;
}
return 0;
}

//---------------------------------------------------------
// next
// got to next segment which has subtype in types
@@ -291,6 +300,16 @@ Segment* Segment::prev1() const
return m->last();
}

Segment* Segment::prev1MM() const
{
if (prev())
return prev();
Measure* m = measure()->prevMeasureMM();
if (m == 0)
return 0;
return m->last();
}

Segment* Segment::prev1(SegmentTypes types) const
{
for (Segment* s = prev1(); s; s = s->prev1()) {
@@ -300,6 +319,15 @@ Segment* Segment::prev1(SegmentTypes types) const
return 0;
}

Segment* Segment::prev1MM(SegmentTypes types) const
{
for (Segment* s = prev1MM(); s; s = s->prev1MM()) {
if (s->segmentType() & types)
return s;
}
return 0;
}

//---------------------------------------------------------
// nextCR
// get next ChordRest Segment
@@ -113,8 +113,11 @@ class Segment : public Element {
Q_INVOKABLE Ms::Segment* next1() const;
Ms::Segment* next1MM() const;
Segment* next1(SegmentTypes) const;
Segment* next1MM(SegmentTypes) const;
Q_INVOKABLE Ms::Segment* prev1() const;
Ms::Segment* prev1MM() const;
Segment* prev1(SegmentTypes) const;
Segment* prev1MM(SegmentTypes) const;

Segment* nextCR(int track = -1) const;

@@ -275,7 +275,7 @@ void Selection::updateSelectedElements()
int endTrack = _staffEnd * VOICES;

for (int st = startTrack; st < endTrack; ++st) {
for (Segment* s = _startSegment; s && (s != _endSegment); s = s->next1()) {
for (Segment* s = _startSegment; s && (s != _endSegment); s = s->next1MM()) {
if (s->segmentType() == Segment::SegEndBarLine) // do not select end bar line
continue;
Element* e = s->element(st);

0 comments on commit 7d919a9

Please sign in to comment.
You can’t perform that action at this time.