Skip to content

Commit

Permalink
fix #22988
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed Jul 10, 2014
1 parent 8831b5d commit 8fcdf0d
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 21 deletions.
5 changes: 1 addition & 4 deletions libmscore/slur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,7 @@ bool SlurSegment::edit(MuseScoreView* viewer, int curGrip, int key, Qt::Keyboard
int endTrack = part->endTrack();
cr = searchCR(e->segment(), startTrack, endTrack);
}
if (cr && cr != e1
// && ((curGrip == int(GripSlurSegment::END) && cr->tick() > sl->tick())
// || (curGrip == int(GripSlurSegment::START) && cr->tick() < sl->tick2() ))
)
if (cr && cr != e1)
changeAnchor(viewer, curGrip, cr);
return true;
}
Expand Down
47 changes: 45 additions & 2 deletions libmscore/spanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "chord.h"
#include "segment.h"
#include "measure.h"
#include "undo.h"

namespace Ms {

Expand All @@ -25,6 +26,8 @@ int Spanner::editTick2;
int Spanner::editTrack2;
QList<QPointF> Spanner::userOffsets2;
QList<QPointF> Spanner::userOffsets;
Element* Spanner::editEndElement;
Element* Spanner::editStartElement;

//---------------------------------------------------------
// SpannerSegment
Expand Down Expand Up @@ -251,10 +254,13 @@ void Spanner::setScore(Score* s)

void Spanner::startEdit(MuseScoreView*, const QPointF&)
{
editTick = _tick;
editTick2 = _tick2;
editTick = _tick;
editTick2 = _tick2;
editTrack2 = _track2;

editStartElement = _startElement;
editEndElement = _endElement;

userOffsets.clear();
userOffsets2.clear();
foreach (SpannerSegment* ss, spannerSegments()) {
Expand Down Expand Up @@ -283,6 +289,43 @@ void Spanner::endEdit()
rebuild = true;
}

if (type() == Element::Type::SLUR) {
if ((editStartElement != _startElement) || (editEndElement != _endElement)) {
//
// handle parts:
// search new start/end elements
//
for (Element* e : linkList()) {
Spanner* spanner = static_cast<Spanner*>(e);
if (spanner == this)
score()->undo()->push1(new ChangeStartEndSpanner(this, editStartElement, editEndElement));
else {
Element* se = 0;
Element* ee = 0;
if (_startElement) {
QList<Element*> sel = _startElement->linkList();
for (Element* e : sel) {
if (e->score() == spanner->score() && e->track() == spanner->track()) {
se = e;
break;
}
}
}
if (_endElement) {
QList<Element*> sel = _endElement->linkList();
for (Element* e : sel) {
if (e->score() == spanner->score() && e->track() == spanner->track2()) {
ee = e;
break;
}
}
}
score()->undo(new ChangeStartEndSpanner(spanner, se, ee));
}
}
}
}

if (rebuild)
score()->rebuildBspTree();

Expand Down
2 changes: 2 additions & 0 deletions libmscore/spanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ class Spanner : public Element {

protected:
static int editTick, editTick2, editTrack2;
static Element* editStartElement;
static Element* editEndElement;

public:
Spanner(Score* = 0);
Expand Down
55 changes: 45 additions & 10 deletions libmscore/undo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -880,12 +880,6 @@ void Score::undoAddElement(Element* element)
#endif
ne->score()->updateNotes();
}
/* else if (ne->type() == Element::Type::SLUR) {
Slur* slur = static_cast<Slur*>(ne);
slur->setStartElement(e);
slur->setEndElement(e->parent());
}
*/
}
return;
}
Expand Down Expand Up @@ -1020,13 +1014,39 @@ void Score::undoAddElement(Element* element)
|| element->type() == Element::Type::TEXTLINE
|| element->type() == Element::Type::PEDAL
|| element->type() == Element::Type::VOLTA) {
// ne->setParent(0); ???
Spanner* nsp = static_cast<Spanner*>(ne);
Spanner* sp = static_cast<Spanner*>(element);
Spanner* sp = static_cast<Spanner*>(element);
Spanner* nsp = static_cast<Spanner*>(ne);
int staffIdx1 = sp->track() / VOICES;
int staffIdx2 = sp->track2() / VOICES;
int diff = staffIdx2 - staffIdx1;
int diff = staffIdx2 - staffIdx1;
nsp->setTrack2((staffIdx + diff) * VOICES + (sp->track2() % VOICES));

// determine start/end element for slurs
// this is only necessary if start/end element is
// a grace note, otherwise the element can be set to zero
// and will later be calculated from tick/track values
//
if (element->type() == Element::Type::SLUR && sp != nsp) {
if (sp->startElement()) {
QList<Element*> sel = sp->startElement()->linkList();
for (Element* e : sel) {
if (e->score() == nsp->score() && e->track() == nsp->track()) {
nsp->setStartElement(e);
break;
}
}
}
if (sp->endElement()) {
QList<Element*> eel = sp->endElement()->linkList();
for (Element* e : eel) {
if (e->score() == nsp->score() && e->track() == nsp->track2()) {
nsp->setEndElement(e);
break;
}
}
}
}

undo(new AddElement(nsp));
}
else if (element->type() == Element::Type::TREMOLO && static_cast<Tremolo*>(element)->twoNotes()) {
Expand Down Expand Up @@ -3396,5 +3416,20 @@ void Unlink::redo()
Q_ASSERT(le);
e->unlink();
}

//---------------------------------------------------------
// ChangeStartEndSpanner::flip
//---------------------------------------------------------

void ChangeStartEndSpanner::flip()
{
Element* s = spanner->startElement();
Element* e = spanner->endElement();
spanner->setStartElement(start);
spanner->setEndElement(end);
start = s;
end = e;
}

}

16 changes: 16 additions & 0 deletions libmscore/undo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,22 @@ class Unlink : public UndoCommand {
virtual void redo();
};

//---------------------------------------------------------
// ChangeStartEndSpanner
//---------------------------------------------------------

class ChangeStartEndSpanner : public UndoCommand {
Spanner* spanner;
Element* start;
Element* end;

void flip();

public:
ChangeStartEndSpanner(Spanner* sp, Element*s, Element*e) : spanner(sp), start(s), end(e) {}
};


} // namespace Ms
#endif

6 changes: 1 addition & 5 deletions mscore/scoreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4030,11 +4030,7 @@ void ScoreView::cmdAddSlur(Note* firstNote, Note* lastNote)
{
_score->startCmd();
ChordRest* cr1 = firstNote->chord();
ChordRest* cr2;
if (cr1->isGrace())
cr2 = static_cast<Chord*>(cr1->parent());
else
cr2 = lastNote ? lastNote->chord() : nextChordRest(cr1);
ChordRest* cr2 = lastNote ? lastNote->chord() : nextChordRest(cr1);

if (cr2 == 0)
cr2 = cr1;
Expand Down

0 comments on commit 8fcdf0d

Please sign in to comment.