Skip to content

Commit

Permalink
Merge pull request #3617 from Matthew-w56/fix-delete-editing
Browse files Browse the repository at this point in the history
Added ClearCoords call when editing a beam
  • Loading branch information
lpugin authored Mar 12, 2024
2 parents 24dd9de + 38747a8 commit 3a14994
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/editortoolkit_cmn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ bool EditorToolkitCMN::Delete(std::string &elementId)
{
Object *element = this->GetElement(elementId);
if (!element) return false;

if (element->Is(NOTE)) {
return this->DeleteNote(vrv_cast<Note *>(element));
}
Expand Down Expand Up @@ -452,7 +451,8 @@ bool EditorToolkitCMN::InsertNote(Object *object)
}

if (currentNote->HasEditorialContent()) {
LogInfo("Inserting a note where a note has editorial content is not possible");
LogInfo("Inserting a note where a note has editorial content is not "
"possible");
return false;
}

Expand Down Expand Up @@ -512,10 +512,10 @@ bool EditorToolkitCMN::DeleteNote(Note *note)

Chord *chord = note->IsChordTone();
Beam *beam = note->GetAncestorBeam();

if (chord) {
if (chord->HasEditorialContent()) {
LogInfo("Deleting a note in a chord that has editorial content is not possible");
LogInfo("Deleting a note in a chord that has editorial content is not "
"possible");
return false;
}
int count = chord->GetChildCount(NOTE, UNLIMITED_DEPTH);
Expand Down Expand Up @@ -560,6 +560,8 @@ bool EditorToolkitCMN::DeleteNote(Note *note)
}
}
else if (beam) {
// If the beam has exactly 2 notes (take apart and leave a single note and a
// rest)
if ((int)beam->m_beamSegment.GetElementCoordRefs()->size() == 2) {
bool insertBefore = true;
LayerElement *otherElement = beam->m_beamSegment.GetElementCoordRefs()->back()->m_element;
Expand All @@ -584,16 +586,17 @@ bool EditorToolkitCMN::DeleteNote(Note *note)
m_chainedId = rest->GetID();
return true;
}
if (beam->IsFirstIn(note)) {
// If the beam has more than 2 and this is first
else if (beam->IsFirstIn(note)) {
Rest *rest = new Rest();
rest->DurationInterface::operator=(*note);
Object *parent = beam->GetParent();
assert(parent);
parent->InsertBefore(beam, rest);
beam->DeleteChild(note);
m_chainedId = rest->GetID();
return true;
}
// If the beam has more than 2 and this is last
else if (beam->IsLastIn(note)) {
Rest *rest = new Rest();
rest->DurationInterface::operator=(*note);
Expand All @@ -602,18 +605,25 @@ bool EditorToolkitCMN::DeleteNote(Note *note)
parent->InsertAfter(beam, rest);
beam->DeleteChild(note);
m_chainedId = rest->GetID();
return true;
}
// If the beam has more than 2 and this in the middle
else {
Rest *rest = new Rest();
rest->DurationInterface::operator=(*note);
beam->ReplaceChild(note, rest);
delete note;
m_chainedId = rest->GetID();
return true;
}
// All but the first IF statement branches lead here
/* Clearing the coords here fixes an error where the children get updated,
* but the internal m_beamElementCoordRefs does not. By clearing it, the
* system is forced to update that structure to reflect the current
* children. */
beam->ClearCoords();
return true;
}
else {
// Deal with just a single note (Not in beam or chord)
Rest *rest = new Rest();
rest->DurationInterface::operator=(*note);
Object *parent = note->GetParent();
Expand Down

0 comments on commit 3a14994

Please sign in to comment.