Skip to content

Commit

Permalink
Manually merged musescore#6339 to master
Browse files Browse the repository at this point in the history
  • Loading branch information
anatoly-os committed Aug 26, 2020
1 parent 60a786c commit 63696c5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
3 changes: 3 additions & 0 deletions libmscore/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3131,6 +3131,9 @@ void Score::insertMeasure(ElementType type, MeasureBase* measure, bool createEmp
MeasureBase* mb = toMeasureBase(Element::create(type, score));
mb->setTick(tick);

if (im) {
im = im->top(); // don't try to insert in front of nested frame
}
mb->setNext(im);
mb->setPrev(im ? im->prev() : score->last());
if (mb->isMeasure()) {
Expand Down
34 changes: 32 additions & 2 deletions libmscore/measurebase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,44 @@ void MeasureBase::layout()
}
}

//---------------------------------------------------------
// top
//---------------------------------------------------------

MeasureBase* MeasureBase::top() const
{
const MeasureBase* mb = this;
while (mb->parent()) {
if (mb->parent()->isMeasureBase()) {
mb = toMeasureBase(mb->parent());
} else {
break;
}
}
return const_cast<MeasureBase*>(mb);
}

//---------------------------------------------------------
// tick
//---------------------------------------------------------

Fraction MeasureBase::tick() const
{
const MeasureBase* mb = top();
return mb ? mb->_tick : Fraction(-1, 1);
}

//---------------------------------------------------------
// triggerLayout
//---------------------------------------------------------

void MeasureBase::triggerLayout() const
{
if (prev() || next()) { // avoid triggering layout before getting added to a score
score()->setLayout(tick(), -1, this);
// for measurebases within other measurebases (e.g., hbox within vbox), use top level
const MeasureBase* mb = top();
// avoid triggering layout before getting added to a score
if (mb->prev() || mb->next()) {
score()->setLayout(mb->tick(), -1, this);
}
}

Expand Down
3 changes: 2 additions & 1 deletion libmscore/measurebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class MeasureBase : public Element
MeasureBase* prev() const { return _prev; }
MeasureBase* prevMM() const;
void setPrev(MeasureBase* e) { _prev = e; }
MeasureBase* top() const;

Ms::Measure* nextMeasure() const;
Ms::Measure* prevMeasure() const;
Expand Down Expand Up @@ -127,7 +128,7 @@ class MeasureBase : public Element
virtual void writeProperties(XmlWriter&) const override;
virtual bool readProperties(XmlReader&) override;

Fraction tick() const { return _tick; }
Fraction tick() const override;
void setTick(const Fraction& f) { _tick = f; }

Fraction ticks() const { return _len; }
Expand Down

0 comments on commit 63696c5

Please sign in to comment.