Skip to content

Commit

Permalink
Merge pull request #3814 from mattmcclinch/274280-time-delete
Browse files Browse the repository at this point in the history
fix #274280: Undoing timewise delete does not restore slur position
  • Loading branch information
wschweer committed Jul 16, 2018
2 parents fab478d + 5cb1b06 commit a13cfc0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 25 deletions.
58 changes: 37 additions & 21 deletions libmscore/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2844,7 +2844,8 @@ bool Score::checkTimeDelete(Segment* startSegment, Segment* endSegment)
ChordRest* cr = toChordRest(s->element(track));
Tuplet* t = cr->tuplet();
DurationElement* de = t ? toDurationElement(t) : toDurationElement(cr);
int cetick = de->tick() + de->actualTicks();
Fraction f = de->ftick() + de->actualFraction();
int cetick = f.ticks();
if (cetick <= tick)
continue;
if (de->tick() >= etick)
Expand Down Expand Up @@ -2971,8 +2972,9 @@ void Score::timeDelete(Measure* m, Segment* startSegment, const Fraction& f)
if (m->hasVoice(track)) {
for (Segment* s = fs; s; s = s->next(CR_TYPE)) {
if (s->element(track)) {
ChordRest* cr = toChordRest(s->element(track));
int cetick = s->rtick() + cr->actualTicks();
ChordRest* cr = toChordRest(s->element(track));
Fraction ftick = cr->ftick() + cr->actualFraction();
int cetick = ftick.ticks() - m->tick();

if (cetick <= tick) {
continue;
Expand All @@ -2997,7 +2999,7 @@ void Score::timeDelete(Measure* m, Segment* startSegment, const Fraction& f)
}
else if (s->rtick() < tick && cetick <= etick) {
// running in
Fraction f1 = Fraction::fromTicks(tick - s->tick());
Fraction f1 = Fraction::fromTicks(tick - s->rtick());
changeCRlen(cr, f1, false);
}
else {
Expand All @@ -3009,6 +3011,7 @@ void Score::timeDelete(Measure* m, Segment* startSegment, const Fraction& f)
}
}
}
tick = startSegment->tick();
undoInsertTime(tick, -len);
undo(new InsertTime(this, tick, -len));

Expand Down Expand Up @@ -4544,15 +4547,17 @@ void Score::undoInsertTime(int tick, int len)
int tick2 = tick - len;
if (s->tick() >= tick2)
append = true;
else if ((s->tick() < tick) && (s->tick2() > tick2)) {
else if (s->tick() >= tick && s->tick2() <= tick2)
append = true;
else if ((s->tick() <= tick) && (s->tick2() >= tick2)) {
int t2 = s->tick2() + len;
if (t2 > s->tick())
append = true;
}
else if (s->tick() >= tick && s->tick2() <= tick2)
append = true;
else if (s->tick() > tick && s->tick2() > tick2)
append = true;
else if (s->tick() < tick && s->tick2() < tick2)
append = true;
}
for (Spanner* ss : sl) {
if (ss->linkList().contains(s)) {
Expand Down Expand Up @@ -4596,26 +4601,25 @@ void Score::undoInsertTime(int tick, int len)
t = 0;
s->undoChangeProperty(Pid::SPANNER_TICK, t);
}
else if ((s->tick() < tick) && (s->tick2() > tick2)) {
//
// case B:
// +----spanner--------+
// +---remove---+
//
int t2 = s->tick2() + len;
if (t2 > s->tick()) {
s->undoChangeProperty(Pid::SPANNER_TICKS, s->ticks() + len);
}
}
// else if (s->tick() >= tick && s->tick2() < tick2) {
else if (s->tick() >= tick && s->tick2() <= tick2) {
//
// case C:
// case B:
// +---spanner---+
// +----remove--------+
//
undoRemoveElement(s);
}
else if ((s->tick() <= tick) && (s->tick2() >= tick2)) {
//
// case C:
// +----spanner--------+
// +---remove---+
//
int t2 = s->tick2() + len;
if (t2 > s->tick())
s->undoChangeProperty(Pid::SPANNER_TICKS, s->ticks() + len);
}
else if (s->tick() > tick && s->tick2() > tick2) {
//
// case D:
Expand All @@ -4625,14 +4629,26 @@ void Score::undoInsertTime(int tick, int len)
int d1 = s->tick() - tick;
int d2 = tick2 - s->tick();
int len = s->ticks() - d2;
if (len == 0) {
if (len == 0)
undoRemoveElement(s);
}
else {
s->undoChangeProperty(Pid::SPANNER_TICK, s->tick() - d1);
s->undoChangeProperty(Pid::SPANNER_TICKS, len);
}
}
else if (s->tick() < tick && s->tick2() < tick2) {
//
// case E:
// +----spanner--------+
// +---remove---+
//
int d = s->tick2() - tick;
int len = s->ticks() - d;
if (len == 0)
undoRemoveElement(s);
else
s->undoChangeProperty(Pid::SPANNER_TICKS, len);
}
}
}

Expand Down
8 changes: 6 additions & 2 deletions libmscore/segment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,10 +586,14 @@ void Segment::remove(Element* el)
auto spanners = smap.findOverlapping(tick(), tick());
for (auto interval : spanners) {
Spanner* s = interval.value;
Element* start = s->startElement();
Element* end = s->endElement();
if (s->startElement() == el)
s->setStartElement(nullptr);
start = nullptr;
if (s->endElement() == el)
s->setEndElement(nullptr);
end = nullptr;
if (start != s->startElement() || end != s->endElement())
score()->undo(new ChangeStartEndSpanner(s, start, end));
}
}
break;
Expand Down
22 changes: 20 additions & 2 deletions libmscore/splitMeasure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "range.h"
#include "tuplet.h"
#include "spanner.h"
#include "undo.h"

namespace Ms {

Expand Down Expand Up @@ -54,12 +55,19 @@ void Score::splitMeasure(Segment* segment)
int stick = measure->tick();
int etick = measure->endTick();

std::list<std::tuple<Spanner*, int, int>> sl;
for (auto i : spanner()) {
Spanner* s = i.second;
Element* start = s->startElement();
Element* end = s->endElement();
if (s->tick() >= stick && s->tick() < etick)
s->setStartElement(0);
start = nullptr;
if (s->tick2() >= stick && s->tick2() < etick)
s->setEndElement(0);
end = nullptr;
if (start != s->startElement() || end != s->endElement())
undo(new ChangeStartEndSpanner(s, start, end));
if (s->tick() < stick && s->tick2() > stick)
sl.push_back(make_tuple(s, s->tick(), s->ticks()));
}

MeasureBase* nm = measure->next();
Expand All @@ -82,6 +90,16 @@ void Score::splitMeasure(Segment* segment)
m1->adjustToLen(Fraction::fromTicks(ticks1), false);
m2->adjustToLen(Fraction::fromTicks(ticks2), false);
range.write(this, m1->tick());

for (auto i : sl) {
Spanner* s = std::get<0>(i);
int tick = std::get<1>(i);
int ticks = std::get<2>(i);
if (s->tick() != tick)
s->undoChangeProperty(Pid::SPANNER_TICK, tick);
if (s->ticks() != ticks)
s->undoChangeProperty(Pid::SPANNER_TICKS, ticks);
}
}
}

0 comments on commit a13cfc0

Please sign in to comment.