Skip to content

Commit

Permalink
fix #283828: add end-start repeat
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcSabatella committed Apr 11, 2019
1 parent 41630ad commit 48d02c7
Show file tree
Hide file tree
Showing 17 changed files with 143 additions and 35 deletions.
81 changes: 74 additions & 7 deletions libmscore/barline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ static void undoChangeBarLineType(BarLine* bl, BarLineType barType, bool allStav
Measure* m = bl->measure();

if (barType == BarLineType::START_REPEAT) {
m->undoChangeProperty(Pid::REPEAT_END, false);
m = m->nextMeasure();
if (!m)
return;
}
else if (bl->barLineType() == BarLineType::START_REPEAT) {
m->undoChangeProperty(Pid::REPEAT_START, false);
if (barType != BarLineType::END_REPEAT)
m->undoChangeProperty(Pid::REPEAT_START, false);
m = m->prevMeasure();
if (!m)
return;
Expand Down Expand Up @@ -135,6 +135,17 @@ static void undoChangeBarLineType(BarLine* bl, BarLineType barType, bool allStav
}
}
break;
case BarLineType::END_START_REPEAT: {
Measure* m2 = m->isMMRest() ? m->mmRestLast() : m;
for (Score* lscore : m2->score()->scoreList()) {
Measure* lmeasure = lscore->tick2measure(m2->tick());
lmeasure->undoChangeProperty(Pid::REPEAT_END, true);
lmeasure = lmeasure->nextMeasure();
if (lmeasure)
lmeasure->undoChangeProperty(Pid::REPEAT_START, true);
}
}
break;
}
}

Expand All @@ -159,6 +170,7 @@ const std::vector<BarLineTableItem> BarLine::barLineTable {
{ BarLineType::END_REPEAT, QT_TRANSLATE_NOOP("Palette", "End repeat"), "end-repeat" },
{ BarLineType::BROKEN, QT_TRANSLATE_NOOP("Palette", "Dashed barline"), "dashed" },
{ BarLineType::END, QT_TRANSLATE_NOOP("Palette", "Final barline"), "end" },
{ BarLineType::END_START_REPEAT, QT_TRANSLATE_NOOP("Palette", "End-start repeat"), "end-start-repeat" },
{ BarLineType::DOTTED, QT_TRANSLATE_NOOP("Palette", "Dotted barline"), "dotted" },
};

Expand Down Expand Up @@ -525,6 +537,38 @@ void BarLine::draw(QPainter* painter) const
drawTips(painter, true, x + lw2 * .5);
}
break;
case BarLineType::END_START_REPEAT: {
qreal lw = score()->styleP(Sid::barWidth) * mag();
painter->setPen(QPen(curColor(), lw, Qt::SolidLine, Qt::FlatCap));

qreal x = 0.0; // symBbox(SymId::repeatDot).width() * .5;
drawDots(painter, x);

x += score()->styleP(Sid::repeatBarlineDotSeparation) * mag();
x += symBbox(SymId::repeatDot).width() * .5;
painter->drawLine(QLineF(x, y1, x, y2));

x += score()->styleP(Sid::endBarDistance) * mag();

qreal lw2 = score()->styleP(Sid::endBarWidth) * mag();
painter->setPen(QPen(curColor(), lw2, Qt::SolidLine, Qt::FlatCap));
painter->drawLine(QLineF(x, y1, x, y2));

if (score()->styleB(Sid::repeatBarTips))
drawTips(painter, true, x + lw2 * .5);

painter->setPen(QPen(curColor(), lw, Qt::SolidLine, Qt::FlatCap));
x += score()->styleP(Sid::endBarDistance) * mag();
painter->drawLine(QLineF(x, y1, x, y2));

x += score()->styleP(Sid::repeatBarlineDotSeparation) * mag();
x -= symBbox(SymId::repeatDot).width() * .5;
drawDots(painter, x);

if (score()->styleB(Sid::repeatBarTips))
drawTips(painter, false, 0.0);
}
break;
}
Segment* s = segment();
if (s && s->isEndBarLineType() && !score()->printing() && score()->showUnprintable()) {
Expand Down Expand Up @@ -647,7 +691,7 @@ Element* BarLine::drop(EditData& data)
}

// check if the new property can apply to this single bar line
BarLineType bt = BarLineType::START_REPEAT | BarLineType::END_REPEAT;
BarLineType bt = BarLineType::START_REPEAT | BarLineType::END_REPEAT | BarLineType::END_START_REPEAT;
bool oldRepeat = barLineType() & bt;
bool newRepeat = bl->barLineType() & bt;

Expand All @@ -668,11 +712,13 @@ Element* BarLine::drop(EditData& data)
undoChangeProperty(Pid::BARLINE_SPAN_TO, spanTo);
}
// if drop refers to subtype, update this bar line subtype
else
else {
undoChangeBarLineType(this, st, false);
}
}
else
else {
undoChangeBarLineType(this, st, true);
}
delete e;
}
else if (e->isArticulation()) {
Expand Down Expand Up @@ -1024,6 +1070,11 @@ qreal BarLine::layoutWidth(Score* score, BarLineType type)
case BarLineType::DOUBLE:
w = score->styleP(Sid::doubleBarWidth) + score->styleP(Sid::doubleBarDistance);
break;
case BarLineType::END_START_REPEAT:
w = score->styleP(Sid::endBarDistance) * 2
+ score->styleP(Sid::repeatBarlineDotSeparation) * 2
+ dotwidth;
break;
case BarLineType::START_REPEAT:
case BarLineType::END_REPEAT:
w = score->styleP(Sid::endBarWidth) * .5
Expand Down Expand Up @@ -1075,11 +1126,18 @@ void BarLine::layout()
// r |= symBbox(SymId::bracketBottom).translated(0, y2);
break;
case BarLineType::END_REPEAT: {
qreal w1 = symBbox(SymId::reversedBracketTop).width();
qreal w1 = 0.0; //symBbox(SymId::reversedBracketTop).width();
r |= symBbox(SymId::reversedBracketTop).translated(-w1, y1);
// r |= symBbox(SymId::reversedBracketBottom).translated(0, y2);
}
break;
case BarLineType::END_START_REPEAT: {
qreal w1 = 0.0; //symBbox(SymId::reversedBracketTop).width();
r |= symBbox(SymId::reversedBracketTop).translated(-w1, y1);
r |= symBbox(SymId::bracketTop).translated(0, y1);
// r |= symBbox(SymId::reversedBracketBottom).translated(0, y2);
}
break;
default:
break;
}
Expand Down Expand Up @@ -1133,11 +1191,20 @@ void BarLine::layout2()
break;
case BarLineType::END_REPEAT:
{
qreal w1 = symBbox(SymId::reversedBracketTop).width();
qreal w1 = 0.0; //symBbox(SymId::reversedBracketTop).width();
bbox() |= symBbox(SymId::reversedBracketTop).translated(-w1, y1);
bbox() |= symBbox(SymId::reversedBracketBottom).translated(-w1, y2);
break;
}
case BarLineType::END_START_REPEAT:
{
qreal w1 = 0.0; //symBbox(SymId::reversedBracketTop).width();
bbox() |= symBbox(SymId::reversedBracketTop).translated(-w1, y1);
bbox() |= symBbox(SymId::reversedBracketBottom).translated(-w1, y2);
bbox() |= symBbox(SymId::bracketTop).translated(0, y1);
bbox() |= symBbox(SymId::bracketBottom).translated(0, y2);
break;
}
default:
break;
}
Expand Down
2 changes: 1 addition & 1 deletion libmscore/barline.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct BarLineTableItem {
//---------------------------------------------------------
// @@ BarLine
//
// @P barLineType enum (BarLineType.NORMAL, .DOUBLE, .START_REPEAT, .END_REPEAT, .BROKEN, .END, .DOTTED)
// @P barLineType enum (BarLineType.NORMAL, .DOUBLE, .START_REPEAT, .END_REPEAT, .BROKEN, .END, .END_START_REPEAT, .DOTTED)
//---------------------------------------------------------

class BarLine final : public Element {
Expand Down
10 changes: 8 additions & 2 deletions libmscore/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3254,14 +3254,20 @@ void Score::cmdToggleLayoutBreak(LayoutBreak::Type type)
default: {
// find measure
Measure* measure = toMeasure(el->findMeasure());
// for start repeat, attach brek to previous measure
if (el->isBarLine()) {
BarLine* bl = toBarLine(el);
if (bl->barLineType() == BarLineType::START_REPEAT)
measure = measure->prevMeasure();
}
// if measure is mmrest, then propagate to last original measure
if (measure)
mb = measure->isMMRest() ? measure->mmRestLast() : measure;
}
}
}
if (mb)
mbl.append(mb);
if (mb)
mbl.append(mb);
}
// toggle the breaks
for (MeasureBase* mb: mbl) {
Expand Down
1 change: 1 addition & 0 deletions libmscore/layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3600,6 +3600,7 @@ void Score::layoutSystemElements(System* system, LayoutContext& lc)
BarLine* bl = toBarLine(s.element(0));
if (bl) {
qreal w = BarLine::layoutWidth(score(), bl->barLineType());
// TODO: actual vertical position and height for staff?
skyline.add(QRectF(0.0, 0.0, w, spatium() * 4.0).translated(bl->pos() + p));
}
}
Expand Down
10 changes: 10 additions & 0 deletions libmscore/measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,16 @@ Element* Measure::drop(EditData& data)
lmeasure->undoChangeProperty(Pid::REPEAT_END, true);
}
}
else if (bl->barLineType() == BarLineType::END_START_REPEAT) {
Measure* m2 = isMMRest() ? mmRestLast() : this;
for (Score* lscore : score()->scoreList()) {
Measure* lmeasure = lscore->tick2measure(m2->tick());
lmeasure->undoChangeProperty(Pid::REPEAT_END, true);
lmeasure = lmeasure->nextMeasure();
if (lmeasure)
lmeasure->undoChangeProperty(Pid::REPEAT_START, true);
}
}
else {
// drop to first end barline
seg = findSegmentR(SegmentType::EndBarLine, ticks());
Expand Down
1 change: 1 addition & 0 deletions libmscore/mscore.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ enum class BarLineType {
END_REPEAT = 8,
BROKEN = 0x10,
END = 0x20,
END_START_REPEAT = 0x40,
DOTTED = 0x80
};

Expand Down
4 changes: 2 additions & 2 deletions libmscore/read114.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static const StyleVal2 style114[] = {
{ Sid::lyricsDashForce, QVariant(false) },
{ Sid::frameSystemDistance, Spatium(1.0) },
{ Sid::minMeasureWidth, Spatium(4.0) },
{ Sid::endBarDistance, Spatium(0.30) },
// { Sid::endBarDistance, Spatium(0.30) },

{ Sid::repeatBarTips, QVariant(false) },
{ Sid::startBarlineSingle, QVariant(false) },
Expand Down Expand Up @@ -1586,7 +1586,7 @@ static void readMeasure(Measure* m, int staffIdx, XmlReader& e)
t = BarLineType::END;
break;
case 6:
// TODO t = BarLineType::END_START_REPEAT;
t = BarLineType::END_START_REPEAT;
break;
}
barLine->setBarLineType(t);
Expand Down
8 changes: 3 additions & 5 deletions mscore/capella.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -893,17 +893,15 @@ static Fraction readCapVoice(Score* score, CapVoice* cvoice, int staffIdx, const
//TODO if (pm && (st == BarLineType::DOUBLE || st == BarLineType::END || st == BarLineType::BROKEN))
// pm->setEndBarLineType(st, false, true);

//TODO if (st == BarLineType::START_REPEAT || st == BarLineType::END_START_REPEAT) {
if (st == BarLineType::START_REPEAT) {
if (st == BarLineType::START_REPEAT || st == BarLineType::END_START_REPEAT) {
Measure* nm = 0; // the next measure (the one started by this barline)
nm = score->getCreateMeasure(tick);
// qDebug("nm %p", nm);
if (nm)
nm->setRepeatStart(true);
}

// if (st == BarLineType::END_REPEAT || st == BarLineType::END_START_REPEAT) {
if (st == BarLineType::END_REPEAT) {
if (st == BarLineType::END_REPEAT || st == BarLineType::END_START_REPEAT) {
if (pm)
pm->setRepeatEnd(true);
}
Expand Down Expand Up @@ -2411,7 +2409,7 @@ void CapExplicitBarline::read()
else if (type == 2) _type = BarLineType::END;
else if (type == 3) _type = BarLineType::END_REPEAT;
else if (type == 4) _type = BarLineType::START_REPEAT;
//TODO else if (type == 5) _type = BarLineType::END_START_REPEAT;
else if (type == 5) _type = BarLineType::END_START_REPEAT;
else if (type == 6) _type = BarLineType::BROKEN;
else _type = BarLineType::NORMAL; // default
_barMode = b >> 4; // 0 = auto, 1 = nur Zeilen, 2 = durchgezogen
Expand Down
2 changes: 1 addition & 1 deletion mscore/capxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void CapExplicitBarline::readCapx(XmlReader& e)
else if (type == "end") _type = BarLineType::END;
else if (type == "repEnd") _type = BarLineType::END_REPEAT;
else if (type == "repBegin") _type = BarLineType::START_REPEAT;
//TODO else if (type == "repEndBegin") _type = BarLineType::END_START_REPEAT;
else if (type == "repEndBegin") _type = BarLineType::END_START_REPEAT;
else if (type == "dashed") _type = BarLineType::BROKEN;
else _type = BarLineType::NORMAL; // default
_barMode = 0;
Expand Down
5 changes: 2 additions & 3 deletions mscore/exportxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,7 @@ void ExportMusicXml::barlineRight(Measure* m)
_xml.tag("bar-style", QString("dotted"));
break;
case BarLineType::END:
// case BarLineType::END_START_REPEAT:
case BarLineType::END_START_REPEAT:
_xml.tag("bar-style", QString("light-heavy"));
break;
default:
Expand All @@ -1586,8 +1586,7 @@ void ExportMusicXml::barlineRight(Measure* m)
}
if (volta)
ending(_xml, volta, false);
// if (bst == BarLineType::END_REPEAT || bst == BarLineType::END_START_REPEAT)
if (bst == BarLineType::END_REPEAT)
if (bst == BarLineType::END_REPEAT || bst == BarLineType::END_START_REPEAT)
{
if (m->repeatCount() > 2) {
_xml.tagE(QString("repeat direction=\"backward\" times=\"%1\"").arg(m->repeatCount()));
Expand Down
3 changes: 1 addition & 2 deletions mscore/importgtp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2829,8 +2829,7 @@ Score::FileError importGTP(MasterScore* score, const QString& name)

for (Measure* m1 = score->firstMeasure(); m1; m1 = m1->nextMeasure(), ++idx) {
const GpBar& bar = gp->bars[idx];
//TODO if (bar.barLine != BarLineType::NORMAL && bar.barLine != BarLineType::END_REPEAT && bar.barLine != BarLineType::START_REPEAT && bar.barLine != BarLineType::END_START_REPEAT)
if (bar.barLine != BarLineType::NORMAL && bar.barLine != BarLineType::END_REPEAT && bar.barLine != BarLineType::START_REPEAT)
if (bar.barLine != BarLineType::NORMAL && bar.barLine != BarLineType::END_REPEAT && bar.barLine != BarLineType::START_REPEAT && bar.barLine != BarLineType::END_START_REPEAT)
m1->setEndBarLineType(bar.barLine, 0);
}
if (score->lastMeasure() && score->lastMeasure()->endBarLineType() != BarLineType::NORMAL)
Expand Down
3 changes: 1 addition & 2 deletions mscore/importove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1254,8 +1254,7 @@ void OveToMScore::convertMeasureMisc(Measure* measure, int part, int staff, int
break;
}

//TODO if (bartype != BarLineType::NORMAL && bartype != BarLineType::END_REPEAT && bartype != BarLineType::START_REPEAT && bartype != BarLineType::END_START_REPEAT && bartype != BarLineType::END)
if (bartype != BarLineType::NORMAL && bartype != BarLineType::END_REPEAT && bartype != BarLineType::START_REPEAT && bartype != BarLineType::END)
if (bartype != BarLineType::NORMAL && bartype != BarLineType::END_REPEAT && bartype != BarLineType::START_REPEAT && bartype != BarLineType::END_START_REPEAT && bartype != BarLineType::END)
measure->setEndBarLineType(bartype, 0);

if (bartype == BarLineType::END_REPEAT)
Expand Down
8 changes: 4 additions & 4 deletions mscore/inspector/inspectorBarline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ void InspectorBarLine::setElement()
// enable / disable individual type combo items according to score and selected bar line status
bool bMultiStaff = bl->score()->nstaves() > 1;
BarLineType blt = bl->barLineType();
// bool isRepeat = blt & (BarLineType::START_REPEAT | BarLineType::END_REPEAT | BarLineType::END_START_REPEAT);
bool isRepeat = blt & (BarLineType::START_REPEAT | BarLineType::END_REPEAT);
bool isRepeat = blt & (BarLineType::START_REPEAT | BarLineType::END_REPEAT | BarLineType::END_START_REPEAT);
// bool isRepeat = blt & (BarLineType::START_REPEAT | BarLineType::END_REPEAT);

const QStandardItemModel* model = qobject_cast<const QStandardItemModel*>(b.type->model());
int i = 0;
for (auto& k : BarLine::barLineTable) {
QStandardItem* item = model->item(i);
// if combo item is repeat type, should be disabled for multi-staff scores
// if (k.type & (BarLineType::START_REPEAT | BarLineType::END_REPEAT | BarLineType::END_START_REPEAT)) {
if (k.type & (BarLineType::START_REPEAT | BarLineType::END_REPEAT)) {
if (k.type & (BarLineType::START_REPEAT | BarLineType::END_REPEAT | BarLineType::END_START_REPEAT)) {
// if (k.type & (BarLineType::START_REPEAT | BarLineType::END_REPEAT)) {
// disable / enable
item->setFlags(bMultiStaff ?
item->flags() & ~(Qt::ItemIsSelectable|Qt::ItemIsEnabled) :
Expand Down
1 change: 1 addition & 0 deletions mscore/menus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ Palette* MuseScore::newRepeatsPalette()
switch (bti->type) {
case BarLineType::START_REPEAT:
case BarLineType::END_REPEAT:
case BarLineType::END_START_REPEAT:
break;
default:
continue;
Expand Down
3 changes: 3 additions & 0 deletions mscore/timeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,9 @@ void Timeline::barline_meta(Segment* seg, int* stagger, int pos)
case BarLineType::END_REPEAT:
repeat_text = QString("End repeat");
break;
case BarLineType::END_START_REPEAT:
repeat_text = QString("End-start repeat");
break;
case BarLineType::DOUBLE:
repeat_text = QString("Double barline");
break;
Expand Down
Loading

0 comments on commit 48d02c7

Please sign in to comment.