Skip to content

Commit

Permalink
Merge pull request #4843 from MarcSabatella/barline-issues
Browse files Browse the repository at this point in the history
Barline issues
  • Loading branch information
anatoly-os committed Apr 12, 2019
2 parents f39ec0e + 8b91a01 commit 25c8a3e
Show file tree
Hide file tree
Showing 51 changed files with 352 additions and 99 deletions.
201 changes: 170 additions & 31 deletions libmscore/barline.cpp

Large diffs are not rendered by default.

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 break to previous measure
if (measure && 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
23 changes: 18 additions & 5 deletions libmscore/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1724,12 +1724,25 @@ void Score::deleteItem(Element* el)
undoRemoveElement(el);
}
else {
if (bl->barLineType() == BarLineType::START_REPEAT)
m->undoChangeProperty(Pid::REPEAT_START, false);
else if (bl->barLineType() == BarLineType::END_REPEAT)
m->undoChangeProperty(Pid::REPEAT_END, false);
else
if (bl->barLineType() == BarLineType::START_REPEAT) {
Measure* m2 = m->isMMRest() ? m->mmRestFirst() : m;
for (Score* lscore : score()->scoreList()) {
Measure* lmeasure = lscore->tick2measure(m2->tick());
if (lmeasure)
lmeasure->undoChangeProperty(Pid::REPEAT_START, false);
}
}
else if (bl->barLineType() == BarLineType::END_REPEAT) {
Measure* m2 = m->isMMRest() ? m->mmRestLast() : m;
for (Score* lscore : score()->scoreList()) {
Measure* lmeasure = lscore->tick2measure(m2->tick());
if (lmeasure)
lmeasure->undoChangeProperty(Pid::REPEAT_END, false);
}
}
else {
bl->undoChangeProperty(Pid::BARLINE_TYPE, QVariant::fromValue(BarLineType::NORMAL));
}
}
}
break;
Expand Down
19 changes: 14 additions & 5 deletions libmscore/layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1759,11 +1759,14 @@ void Score::createMMRest(Measure* m, Measure* lm, const Fraction& len)

Measure* mmr = m->mmRest();
if (mmr) {
// reuse existing mmrest
if (mmr->ticks() != len) {
Segment* s = mmr->findSegmentR(SegmentType::EndBarLine, mmr->ticks());
// adjust length
mmr->setTicks(len);
// move existing end barline
if (s)
s->setRtick(mmr->ticks());
s->setRtick(len);
}
}
else {
Expand All @@ -1779,21 +1782,26 @@ void Score::createMMRest(Measure* m, Measure* lm, const Fraction& len)

Segment* ss = lm->findSegmentR(SegmentType::EndBarLine, lm->ticks());
if (ss) {
Segment* ds = mmr->undoGetSegment(SegmentType::EndBarLine, lm->endTick());
Segment* ds = mmr->undoGetSegmentR(SegmentType::EndBarLine, mmr->ticks());
for (int staffIdx = 0; staffIdx < nstaves(); ++staffIdx) {
Element* e = ss->element(staffIdx * VOICES);
if (e) {
bool generated = e->generated();
if (!ds->element(staffIdx * VOICES)) {
Element* ee = e->clone();
Element* ee = generated ? e->clone() : e->linkedClone();
ee->setGenerated(generated);
ee->setParent(ds);
undoAddElement(ee);
}
else {
BarLine* bd = toBarLine(ds->element(staffIdx * VOICES));
BarLine* bs = toBarLine(e);
if (!generated && !bd->links())
undo(new Link(bd, bs));
if (bd->barLineType() != bs->barLineType()) {
bd->undoChangeProperty(Pid::BARLINE_TYPE, QVariant::fromValue(bs->barLineType()));
bd->undoChangeProperty(Pid::GENERATED, true);
// change directly when generating mmrests, do not change underlying measures or follow links
undo(new ChangeProperty(bd, Pid::BARLINE_TYPE, QVariant::fromValue(bs->barLineType()), PropertyFlags::NOSTYLE));
undo(new ChangeProperty(bd, Pid::GENERATED, generated, PropertyFlags::NOSTYLE));
}
}
}
Expand Down Expand Up @@ -3594,6 +3602,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
50 changes: 48 additions & 2 deletions libmscore/measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,7 @@ void Measure::cmdAddStaves(int sStaff, int eStaff, bool createRest)
score()->undo(new InsertStaves(this, sStaff, eStaff));

Segment* ts = findSegment(SegmentType::TimeSig, tick());
Segment* bs = findSegmentR(SegmentType::EndBarLine, ticks());

for (int i = sStaff; i < eStaff; ++i) {
Staff* staff = score()->staff(i);
Expand Down Expand Up @@ -1189,6 +1190,25 @@ void Measure::cmdAddStaves(int sStaff, int eStaff, bool createRest)
delete ots;
}
}

// replicate barline
if (bs) {
BarLine* obl = nullptr;
for (unsigned track = 0; track < _mstaves.size() * VOICES; ++track) {
Element* e = bs->element(track);
if (e && !e->generated()) {
obl = toBarLine(e);
break;
}
}
if (obl) {
BarLine* barline = new BarLine(*obl);
barline->setTrack(staffIdx * VOICES);
barline->setParent(bs);
barline->setGenerated(false);
score()->undoAddElement(barline);
}
}
}
}

Expand Down Expand Up @@ -1517,8 +1537,34 @@ Element* Measure::drop(EditData& data)
if (cbl)
cbl->drop(data);
}
else if (bl->barLineType() == BarLineType::START_REPEAT)
undoChangeProperty(Pid::REPEAT_START, true);
else if (bl->barLineType() == BarLineType::START_REPEAT) {
Measure* m2 = isMMRest() ? mmRestFirst() : this;
for (Score* lscore : score()->scoreList()) {
Measure* lmeasure = lscore->tick2measure(m2->tick());
if (lmeasure)
lmeasure->undoChangeProperty(Pid::REPEAT_START, true);
}
}
else if (bl->barLineType() == BarLineType::END_REPEAT) {
Measure* m2 = isMMRest() ? mmRestLast() : this;
for (Score* lscore : score()->scoreList()) {
Measure* lmeasure = lscore->tick2measure(m2->tick());
if (lmeasure)
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());
if (lmeasure) {
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
20 changes: 19 additions & 1 deletion libmscore/staff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1304,8 +1304,26 @@ bool Staff::setProperty(Pid id, const QVariant& v)
case Pid::PLAYBACK_VOICE4:
setPlaybackVoice(3, v.toBool());
break;
case Pid::STAFF_BARLINE_SPAN:
case Pid::STAFF_BARLINE_SPAN: {
setBarLineSpan(v.toInt());
// update non-generated barlines
int track = idx() * VOICES;
std::vector<Element*> blList;
for (Measure* m = score()->firstMeasure(); m; m = m->nextMeasure()) {
Segment* s = m->getSegmentR(SegmentType::EndBarLine, m->ticks());
if (s && s->element(track))
blList.push_back(s->element(track));
if (Measure* mm = m->mmRest()) {
Segment* ss = mm->getSegmentR(SegmentType::EndBarLine, mm->ticks());
if (ss && ss->element(track))
blList.push_back(ss->element(track));
}
}
for (Element* e : blList) {
if (e && e->isBarLine() && !e->generated())
toBarLine(e)->setSpanStaff(v.toInt());
}
}
break;
case Pid::STAFF_BARLINE_SPAN_FROM:
setBarLineFrom(v.toInt());
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
Loading

0 comments on commit 25c8a3e

Please sign in to comment.