Skip to content

Commit

Permalink
fix #49916 Crash when adding, changing and removing staves with slurr…
Browse files Browse the repository at this point in the history
…ed grace notes
  • Loading branch information
wschweer committed Mar 10, 2015
1 parent c26913b commit 39164ce
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 105 deletions.
16 changes: 8 additions & 8 deletions libmscore/chord.cpp
Expand Up @@ -205,15 +205,13 @@ Chord::Chord(const Chord& c, bool link)
: ChordRest(c, link)
{
if (link)
linkTo((Chord*)&c); // HACK!
score()->undo(new Link(this, const_cast<Chord*>(&c)));
_ledgerLines = 0;
int n = c._notes.size();
for (int i = 0; i < n; ++i) {
Note* onote = c._notes[i];

for (Note* onote : c._notes) {
Note* nnote = new Note(*onote, link);
add(nnote);
}

for (Chord* gn : c.graceNotes()) {
Chord* nc = new Chord(*gn, link);
add(nc);
Expand Down Expand Up @@ -243,13 +241,13 @@ Chord::Chord(const Chord& c, bool link)
Arpeggio* a = new Arpeggio(*(c._arpeggio));
add(a);
if (link)
a->linkTo(c._arpeggio);
score()->undo(new Link(a, const_cast<Arpeggio*>(c._arpeggio)));
}
if (c._tremolo && !c._tremolo->twoNotes()) {
Tremolo* t = new Tremolo(*(c._tremolo));
add(t);
if (link)
t->linkTo(c._tremolo);
score()->undo(new Link(t, const_cast<Tremolo*>(c._tremolo)));
}

for (Element* e : c.el()) {
Expand All @@ -258,7 +256,7 @@ Chord::Chord(const Chord& c, bool link)
ChordLine* ncl = new ChordLine(*cl);
add(ncl);
if (link)
cl->linkTo(ncl);
score()->undo(new Link(cl, const_cast<ChordLine*>(ncl)));
}
}
}
Expand Down Expand Up @@ -308,6 +306,7 @@ Chord::~Chord()
delete ll;
ll = llNext;
}
qDeleteAll(_graceNotes);
qDeleteAll(_notes);
}

Expand Down Expand Up @@ -472,6 +471,7 @@ void Chord::add(Element* e)
case Element::Type::CHORD:
{
Chord* gc = static_cast<Chord*>(e);
Q_ASSERT(gc->noteType() != NoteType::NORMAL);
int idx = gc->graceIndex();
gc->setFlags(ElementFlag::MOVABLE);
_graceNotes.insert(_graceNotes.begin() + idx, gc);
Expand Down
4 changes: 2 additions & 2 deletions libmscore/note.cpp
Expand Up @@ -198,7 +198,7 @@ Note::Note(const Note& n, bool link)
: Element(n)
{
if (link)
linkTo((Note*)&n); // HACK!
score()->undo(new Link(this, const_cast<Note*>(&n)));
_subchannel = n._subchannel;
_line = n._line;
_fret = n._fret;
Expand Down Expand Up @@ -233,7 +233,7 @@ Note::Note(const Note& n, bool link)
Element* ce = e->clone();
add(ce);
if (link)
ce->linkTo(e);
score()->undo(new Link(ce, const_cast<Element*>(e)));
}

_playEvents = n._playEvents;
Expand Down
2 changes: 0 additions & 2 deletions libmscore/score.cpp
Expand Up @@ -1344,13 +1344,11 @@ Measure* Score::getCreateMeasure(int tick)

void Score::addElement(Element* element)
{
#if 0
if (MScore::debugMode) {
qDebug(" Score(%p)::addElement %p(%s) parent %p(%s)",
this, element, element->name(), element->parent(),
element->parent() ? element->parent()->name() : "");
}
#endif

if (element->parent() && element->parent()->type() == Element::Type::SEGMENT)
static_cast<Segment*>(element->parent())->measure()->setDirty();
Expand Down
95 changes: 15 additions & 80 deletions libmscore/undo.cpp
Expand Up @@ -451,15 +451,15 @@ void Score::undoChangePitch(Note* note, int pitch, int tpc1, int tpc2)

void Score::undoChangeFretting(Note* note, int pitch, int string, int fret, int tpc1, int tpc2)
{
const LinkedElements* l = note->links();
if (l) {
for (ScoreElement* e : *l) {
Note* n = static_cast<Note*>(e);
undo()->push(new ChangeFretting(n, pitch, string, fret, tpc1, tpc2));
}
const LinkedElements* l = note->links();
if (l) {
for (ScoreElement* e : *l) {
Note* n = static_cast<Note*>(e);
undo()->push(new ChangeFretting(n, pitch, string, fret, tpc1, tpc2));
}
else
undo()->push(new ChangeFretting(note, pitch, string, fret, tpc1, tpc2));
}
else
undo()->push(new ChangeFretting(note, pitch, string, fret, tpc1, tpc2));
}

//---------------------------------------------------------
Expand Down Expand Up @@ -3515,31 +3515,16 @@ void ChangeNoteEvent::flip()
}

//---------------------------------------------------------
// Unlink
//---------------------------------------------------------

Unlink::Unlink(ScoreElement* _e) : e(_e)
{
Q_ASSERT(e->links());
}

//---------------------------------------------------------
// Unlink::undo
// (link)
// LinkUnlink
//---------------------------------------------------------

void Unlink::undo()
void LinkUnlink::doLink()
{
e->linkTo(le);
le = nullptr;
}

//---------------------------------------------------------
// Unlink::redo
// (unlink)
//---------------------------------------------------------

void Unlink::redo()
void LinkUnlink::doUnlink()
{
Q_ASSERT(le == nullptr);
const LinkedElements* l = e->links();
Expand All @@ -3549,63 +3534,13 @@ void Unlink::redo()
break;
}
}
// Q_ASSERT(le);
e->unlink();
}

//---------------------------------------------------------
// Link::redo
//---------------------------------------------------------

void Link::redo()
{
e1->linkTo(e2);
}

//---------------------------------------------------------
// Link::redo
//---------------------------------------------------------

void Link::undo()
{
e2->unlink();
}

//---------------------------------------------------------
// LinkStaff::redo
//---------------------------------------------------------

void LinkStaff::redo()
{
s1->linkTo(s2);
}

//---------------------------------------------------------
// LinkStaff::undo
//---------------------------------------------------------

void LinkStaff::undo()
{
s1->unlink(s2);
}

//---------------------------------------------------------
// UnlinkStaff::redo
//---------------------------------------------------------

void UnlinkStaff::redo()
{
s1->unlink(s2);
}

//---------------------------------------------------------
// UnlinkStaff::undo
//---------------------------------------------------------

void UnlinkStaff::undo()
{
s1->linkTo(s2);
}
void LinkStaff::redo() { s1->linkTo(s2); }
void LinkStaff::undo() { s1->unlink(s2); }
void UnlinkStaff::redo() { s1->unlink(s2); }
void UnlinkStaff::undo() { s1->linkTo(s2); }

//---------------------------------------------------------
// ChangeStartEndSpanner::flip
Expand Down
37 changes: 24 additions & 13 deletions libmscore/undo.h
Expand Up @@ -1294,32 +1294,43 @@ class ChangeNoteEvent : public UndoCommand {
};

//---------------------------------------------------------
// Unlink
// LinkUnlink
//---------------------------------------------------------

class Unlink : public UndoCommand {
class LinkUnlink : public UndoCommand {
ScoreElement* e;
ScoreElement* le = 0;
ScoreElement* le;

protected:
void doLink();
void doUnlink();

public:
Unlink(ScoreElement* _e);
virtual void undo();
virtual void redo();
LinkUnlink(ScoreElement* _e, ScoreElement* _le) : e(_e), le(_le) {}
};

//---------------------------------------------------------
// Unlink
//---------------------------------------------------------

class Unlink : public LinkUnlink {

public:
Unlink(ScoreElement* e) : LinkUnlink(e, nullptr) {};
virtual void undo() override { doLink(); }
virtual void redo() override { doUnlink(); }
UNDO_NAME("Unlink")
};

//---------------------------------------------------------
// Link
//---------------------------------------------------------

class Link : public UndoCommand {
Element* e1;
Element* e2;

class Link : public LinkUnlink {
public:
Link(Element* _e1, Element* _e2) : e1(_e1), e2(_e2) {}
virtual void undo();
virtual void redo();
Link(ScoreElement* e, ScoreElement* le) : LinkUnlink(e, le) {}
virtual void undo() override { doUnlink(); }
virtual void redo() override { doLink(); }
UNDO_NAME("Link")
};

Expand Down

0 comments on commit 39164ce

Please sign in to comment.