Skip to content

Commit

Permalink
Fix layout issues, with TODO's
Browse files Browse the repository at this point in the history
Co-authored-by: MarcSabatella <marc@outsideshore.com>
  • Loading branch information
IsaacWeiss and MarcSabatella committed Jul 30, 2020
1 parent 74ff5e8 commit 0828d65
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 53 deletions.
57 changes: 44 additions & 13 deletions libmscore/layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3544,6 +3544,7 @@ System* Score::collectSystem(LayoutContext& lc)
qreal curWidth = lc.curMeasure->width();
bool curHeader = lc.curMeasure->header();
bool curTrailer = lc.curMeasure->trailer();
MeasureBase* breakMeasure = nullptr;

while (lc.curMeasure) { // collect measure for system
System* oldSystem = lc.curMeasure->system();
Expand Down Expand Up @@ -3576,7 +3577,13 @@ System* Score::collectSystem(LayoutContext& lc)
}

m->createEndBarLines(true);
m->addSystemTrailer(m->nextMeasure());
// measures with nobreak cannot end a system
// thus they will not contain a trailer
if (m->noBreak()) {
m->removeSystemTrailer();
} else {
m->addSystemTrailer(m->nextMeasure());
}
m->computeMinWidth();
ww = m->width();
} else if (lc.curMeasure->isHBox()) {
Expand All @@ -3594,22 +3601,34 @@ System* Score::collectSystem(LayoutContext& lc)

bool doBreak = (system->measures().size() > 1) && ((minWidth + ww) > systemWidth);
if (doBreak) {
breakMeasure = lc.curMeasure;
if (lc.prevMeasure->noBreak() && system->measures().size() > 2) {
// TODO: why 2? should this really be the total size of the nobreak group?
// to make sure we don't remove everything?
// TODO: what about the case where nobreak is set, but system size is only 2 (or whatever size of nobreak group is)?
//
// remove however many measures are grouped with nobreak
system->removeLastMeasure();
while (lc.prevMeasure && lc.prevMeasure->noBreak() && system->measures().size() > 1) {
minWidth -= system->lastMeasure()->width();
system->removeLastMeasure();
// TODO: this seems kludgy, seems like it means we set for the same measure
// on two separate iterations of the loop
lc.curMeasure->setSystem(oldSystem);
lc.prevMeasure->setSystem(oldSystem);
lc.tick -= lc.curMeasure->ticks();
--lc.measureNo;
lc.nextMeasure = lc.curMeasure;
lc.curMeasure = lc.prevMeasure;
lc.prevMeasure = lc.curMeasure->prevMeasure();
// lc.curMeasure->setOldWidth(lc.curMeasure->width());
// curHeader = lc.curMeasure->header();
}
break;
} else if (!lc.prevMeasure->noBreak()) {
// TODO: is it really necessary to have a separate clause here?
// it seems we should be able to handle this within the if clause above
//
// remove last measure
system->removeLastMeasure();
lc.curMeasure->setSystem(oldSystem);
Expand Down Expand Up @@ -3668,12 +3687,16 @@ System* Score::collectSystem(LayoutContext& lc)
nmb = nm->mmRest();
}
}
nmb->setOldWidth(nmb->width());
if (!lc.curMeasure->noBreak()) {
curWidth = nmb->width();
// current measure is not a nobreak,
// so next measure could possibly start a system
curHeader = nmb->header();
}
if (!nmb->noBreak()) {
// next measure is not a nobreak
// so it could possibly end a system
curTrailer = nmb->trailer();
} else {
// TODO: measure widths within nobreak group are distorted after edit on previous system
}
}

Expand All @@ -3696,8 +3719,8 @@ System* Score::collectSystem(LayoutContext& lc)
// this system ends in the same place as the previous layout
// ok to stop
if (lc.curMeasure && lc.curMeasure->isMeasure()) {
// we may have previously processed first measure of next system
// so now we must restore it to its original state
// we may have previously processed first measure(s) of next system
// so now we must restore to original state
Measure* m = toMeasure(lc.curMeasure);
if (m->repeatStart()) {
Segment* s = m->findSegmentR(SegmentType::StartRepeatBarLine, Fraction(0,1));
Expand All @@ -3706,19 +3729,27 @@ System* Score::collectSystem(LayoutContext& lc)
}
}
bool firstSystem = lc.prevMeasure->sectionBreak() && _layoutMode != LayoutMode::FLOAT;
MeasureBase* nm = breakMeasure ? breakMeasure : m;
if (curHeader) {
m->addSystemHeader(firstSystem);
} else {
m->removeSystemHeader();
}
if (curTrailer) {
m->addSystemTrailer(m->nextMeasure());
} else {
m->removeSystemTrailer();
while (true) {
// TODO: what if the nobreak group takes the entire system - is this correct?
if (curTrailer && !m->noBreak()) {
m->addSystemTrailer(m->nextMeasure());
} else {
m->removeSystemTrailer();
}
m->computeMinWidth();
m->stretchMeasure(m->oldWidth());
restoreBeams(m);
if (m == nm || !m->noBreak()) {
break;
}
m = m->nextMeasure();
}
m->computeMinWidth();
m->stretchMeasure(curWidth);
restoreBeams(m);
}
lc.rangeDone = true;
}
Expand Down
4 changes: 4 additions & 0 deletions libmscore/measurebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class MeasureBase : public Element
Fraction _tick { Fraction(0, 1) };
int _no { 0 }; ///< Measure number, counting from zero
int _noOffset { 0 }; ///< Offset to measure number
qreal m_oldWidth { 0 }; ///< Used to restore layout during recalculations in Score::collectSystem()

protected:
Fraction _len { Fraction(0, 1) }; ///< actual length of measure
Expand Down Expand Up @@ -183,6 +184,9 @@ class MeasureBase : public Element

int index() const;
int measureIndex() const;

void setOldWidth(qreal n) { m_oldWidth = n; }
qreal oldWidth() const { return m_oldWidth; }
};
} // namespace Ms
#endif
1 change: 1 addition & 0 deletions mscore/debugger/debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,7 @@ void MeasureView::setElement(Element* e)
mb.repeatCount->setValue(m->repeatCount());
mb.breakMultiMeasureRest->setChecked(m->breakMultiMeasureRest());
mb.mmRestCount->setValue(m->mmRestCount());
mb.oldWidth->setValue(m->oldWidth());
mb.timesig->setText(m->timesig().print());
mb.len->setText(m->ticks().print());
mb.tick->setValue(m->tick().ticks());
Expand Down
55 changes: 15 additions & 40 deletions mscore/debugger/measure.ui
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="2">
Expand All @@ -114,9 +111,6 @@
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="5">
Expand All @@ -130,9 +124,6 @@
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="8">
Expand All @@ -146,9 +137,6 @@
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="2">
Expand All @@ -169,9 +157,6 @@
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="5">
Expand All @@ -185,9 +170,6 @@
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="8">
Expand All @@ -201,9 +183,6 @@
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="2">
Expand All @@ -224,9 +203,6 @@
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="5">
Expand All @@ -237,9 +213,6 @@
<property name="text">
<string notr="true">EndRep:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="8">
Expand All @@ -250,29 +223,20 @@
<property name="text">
<string notr="true">len:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="4" column="3">
<widget class="QLabel" name="label_15">
<property name="text">
<string notr="true">timesig:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string notr="true">tick:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="4" column="5">
Expand All @@ -295,10 +259,7 @@
<string notr="true"/>
</property>
<property name="text">
<string notr="true">mmRestCount</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<string notr="true">mmRestCount:</string>
</property>
</widget>
</item>
Expand All @@ -312,6 +273,20 @@
</property>
</widget>
</item>
<item row="3" column="5">
<widget class="QDoubleSpinBox" name="oldWidth">
<property name="maximum">
<double>10000.000000000000000</double>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="QLabel" name="label_10">
<property name="text">
<string>oldWidth:</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand Down

0 comments on commit 0828d65

Please sign in to comment.