Skip to content

Commit

Permalink
fix #222031: remove ties and spanners when removing induvidual notes …
Browse files Browse the repository at this point in the history
…within a chord (patch backport to 2.3)
  • Loading branch information
dmitrio95 committed Jun 7, 2018
1 parent d0d38d1 commit 1b736ba
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 25 deletions.
10 changes: 2 additions & 8 deletions libmscore/chord.cpp
Expand Up @@ -424,10 +424,7 @@ void Chord::add(Element* e)
}
if (!found)
_notes.append(note);
if (note->tieFor()) {
if (note->tieFor()->endNote())
note->tieFor()->endNote()->setTieBack(note->tieFor());
}
note->connectTiedNotes();
if (voice() && measure() && note->visible())
measure()->mstaff(staffIdx())->hasVoices = true;
}
Expand Down Expand Up @@ -504,10 +501,7 @@ void Chord::remove(Element* e)
{
Note* note = static_cast<Note*>(e);
if (_notes.removeOne(note)) {
if (note->tieFor()) {
if (note->tieFor()->endNote())
note->tieFor()->endNote()->setTieBack(0);
}
note->disconnectTiedNotes();
for (Spanner* s : note->spannerBack()) {
note->removeSpannerBack(s);
}
Expand Down
30 changes: 30 additions & 0 deletions libmscore/note.cpp
Expand Up @@ -2873,6 +2873,36 @@ QList<Note*> Note::tiedNotes() const
return notes;
}

//---------------------------------------------------------
// disconnectTiedNotes
//---------------------------------------------------------

void Note::disconnectTiedNotes()
{
if (tieBack() && tieBack()->startNote()) {
tieBack()->startNote()->remove(tieBack());
}
if (tieFor() && tieFor()->endNote()) {
tieFor()->endNote()->setTieBack(0);
}
}

//---------------------------------------------------------
// connectTiedNotes
//---------------------------------------------------------

void Note::connectTiedNotes()
{
if (tieBack()) {
tieBack()->setEndNote(this);
if (tieBack()->startNote())
tieBack()->startNote()->add(tieBack());
}
if (tieFor() && tieFor()->endNote()) {
tieFor()->endNote()->setTieBack(tieFor());
}
}

//---------------------------------------------------------
// accidentalType
//---------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions libmscore/note.h
Expand Up @@ -359,6 +359,8 @@ class Note : public Element {
Note* firstTiedNote() const;
Note* lastTiedNote() const;
QList<Note*> tiedNotes() const;
void disconnectTiedNotes();
void connectTiedNotes();

Chord* chord() const { return (Chord*)parent(); }
void setChord(Chord* a) { setParent((Element*)a); }
Expand Down
45 changes: 28 additions & 17 deletions libmscore/undo.cpp
Expand Up @@ -1596,6 +1596,26 @@ const char* AddElement::name() const
}
#endif

//---------------------------------------------------------
// removeNote
// Helper function for RemoveElement class
//---------------------------------------------------------

static void removeNote(const Note* note)
{
Score* score = note->score();
if (note->tieFor() && note->tieFor()->endNote())
score->undo(new RemoveElement(note->tieFor()));
if (note->tieBack())
score->undo(new RemoveElement(note->tieBack()));
for (Spanner* s : note->spannerBack()) {
score->undo(new RemoveElement(s));
}
for (Spanner* s : note->spannerFor()) {
score->undo(new RemoveElement(s));
}
}

//---------------------------------------------------------
// RemoveElement
//---------------------------------------------------------
Expand Down Expand Up @@ -1647,19 +1667,15 @@ RemoveElement::RemoveElement(Element* e)
score->undo(new RemoveElement(tremolo));
}
for (const Note* note : chord->notes()) {
if (note->tieFor() && note->tieFor()->endNote())
score->undo(new RemoveElement(note->tieFor()));
if (note->tieBack())
score->undo(new RemoveElement(note->tieBack()));
for (Spanner* s : note->spannerBack()) {
score->undo(new RemoveElement(s));
}
for (Spanner* s : note->spannerFor()) {
score->undo(new RemoveElement(s));
}
removeNote(note);
}
}
}
else if (e->type() == Element::Type::NOTE) {
// Removing an individual note within a chord
const Note* note = static_cast<const Note*>(e);
removeNote(note);
}
}

//---------------------------------------------------------
Expand Down Expand Up @@ -1687,10 +1703,7 @@ void RemoveElement::undo()
if (element->type() == Element::Type::CHORD) {
Chord* chord = static_cast<Chord*>(element);
foreach(Note* note, chord->notes()) {
if (note->tieBack())
note->tieBack()->setEndNote(note);
if (note->tieFor() && note->tieFor()->endNote())
note->tieFor()->endNote()->setTieBack(note->tieFor());
note->connectTiedNotes();
}
}
undoAddTuplet(static_cast<ChordRest*>(element));
Expand All @@ -1710,9 +1723,7 @@ void RemoveElement::redo()
if (element->type() == Element::Type::CHORD) {
Chord* chord = static_cast<Chord*>(element);
foreach(Note* note, chord->notes()) {
if (note->tieFor() && note->tieFor()->endNote()) {
note->tieFor()->endNote()->setTieBack(0);
}
note->disconnectTiedNotes();
}
}
}
Expand Down

0 comments on commit 1b736ba

Please sign in to comment.