Skip to content
Permalink
Browse files

fix #222031: remove ties and spanners when removing induvidual notes …

…within a chord
  • Loading branch information...
dmitrio95 committed Mar 20, 2018
1 parent 6969419 commit 1b8679d9c56e610c0ed85a50d243b3f5fb4e40e8
Showing with 62 additions and 25 deletions.
  1. +2 −8 libmscore/chord.cpp
  2. +30 −0 libmscore/note.cpp
  3. +2 −0 libmscore/note.h
  4. +28 −17 libmscore/undo.cpp
@@ -444,10 +444,7 @@ void Chord::add(Element* e)
}
if (!found)
_notes.push_back(note);
if (note->tieFor()) {
if (note->tieFor()->endNote())
note->tieFor()->endNote()->setTieBack(note->tieFor());
}
note->connectTiedNotes();
if (voice() && measure() && note->visible())
measure()->setHasVoices(staffIdx(), true);
}
@@ -529,10 +526,7 @@ void Chord::remove(Element* e)
auto i = std::find(_notes.begin(), _notes.end(), note);
if (i != _notes.end()) {
_notes.erase(i);
if (note->tieFor()) {
if (note->tieFor()->endNote())
note->tieFor()->endNote()->setTieBack(0);
}
note->disconnectTiedNotes();
for (Spanner* s : note->spannerBack())
note->removeSpannerBack(s);
for (Spanner* s : note->spannerFor())
@@ -3122,6 +3122,36 @@ std::vector<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
//---------------------------------------------------------
@@ -367,6 +367,8 @@ class Note final : public Element {
void setTieBack(Tie* t) { _tieBack = t; }
Note* firstTiedNote() const;
const Note* lastTiedNote() const;
void disconnectTiedNotes();
void connectTiedNotes();

Chord* chord() const { return (Chord*)parent(); }
void setChord(Chord* a) { setParent((Element*)a); }
@@ -560,6 +560,26 @@ const char* AddElement::name() const
return buffer;
}

//---------------------------------------------------------
// 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
//---------------------------------------------------------
@@ -582,19 +602,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 (element->isNote()) {
// Removing an individual note within a chord
const Note* note = toNote(element);
removeNote(note);
}
}

//---------------------------------------------------------
@@ -621,10 +637,7 @@ void RemoveElement::undo(EditData*)
if (element->isChord()) {
Chord* chord = toChord(element);
for (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(toChordRest(element));
@@ -648,9 +661,7 @@ void RemoveElement::redo(EditData*)
if (element->isChord()) {
Chord* chord = toChord(element);
for (Note* note : chord->notes()) {
if (note->tieFor() && note->tieFor()->endNote()) {
note->tieFor()->endNote()->setTieBack(0);
}
note->disconnectTiedNotes();
}
}
}

0 comments on commit 1b8679d

Please sign in to comment.
You can’t perform that action at this time.