Skip to content

Commit

Permalink
Remove empty system after staff merging
Browse files Browse the repository at this point in the history
  • Loading branch information
yinanazhou committed Jun 27, 2024
1 parent 04b49aa commit 141d546
Showing 1 changed file with 47 additions and 6 deletions.
53 changes: 47 additions & 6 deletions src/editortoolkit_neume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1711,6 +1711,8 @@ bool EditorToolkitNeume::MatchHeight(std::string elementId)
bool EditorToolkitNeume::Merge(std::vector<std::string> elementIds)
{
if (!m_doc->GetDrawingPage()) return false;
Object *page = m_doc->GetDrawingPage();

ListOfObjects staves;

// Get the staves by element ID and fail if a staff does not exist.
Expand Down Expand Up @@ -1777,8 +1779,35 @@ bool EditorToolkitNeume::Merge(std::vector<std::string> elementIds)
Layer *sourceLayer = vrv_cast<Layer *>(sourceStaff->GetFirst(LAYER));
fillLayer->MoveChildrenFrom(sourceLayer);
assert(sourceLayer->GetChildCount() == 0);
Object *parent = sourceStaff->GetParent();
parent->DeleteChild(sourceStaff);

// Delete empty staff with its system parent
// Move SECTION, PB, and SYSTEM_MILESTONE_END if any
Object *system = sourceStaff->GetFirstAncestor(SYSTEM);
if (system->FindDescendantByType(SECTION)) {
Object *section = system->FindDescendantByType(SECTION);
Object *nextSystem = page->GetNext(system, SYSTEM);
if (nextSystem) {
section = system->DetachChild(section->GetIdx());
nextSystem->InsertChild(section, 0);
}
}
if (system->FindDescendantByType(PB)) {
Object *pb = system->FindDescendantByType(PB);
Object *nextSystem = page->GetNext(system, SYSTEM);
if (nextSystem) {
pb = system->DetachChild(pb->GetIdx());
nextSystem->InsertChild(pb, 1);
}
}
if (system->FindDescendantByType(SYSTEM_MILESTONE_END)) {
Object *milestoneEnd = system->FindDescendantByType(SYSTEM_MILESTONE_END);
Object *previousSystem = page->GetPrevious(system, SYSTEM);
if (previousSystem) {
milestoneEnd = system->DetachChild(milestoneEnd->GetIdx());
previousSystem->InsertChild(milestoneEnd, previousSystem->GetChildCount());
}
}
page->DeleteChild(system);
}
// Set the bounding box for the staff to the new bounds
Zone *staffZone = fillStaff->GetZone();
Expand All @@ -1790,13 +1819,25 @@ bool EditorToolkitNeume::Merge(std::vector<std::string> elementIds)

fillLayer->ReorderByXPos();

m_editInfo.import("uuid", fillStaff->GetID());
m_editInfo.import("status", "OK");
m_editInfo.import("message", "");
for (Object *child = page->GetFirst(); child != NULL; child = page->GetNext()) {
LogError("%s", child->GetClassName().c_str());
if (child->Is(SYSTEM)) {
for (Object *grandchild = child->GetFirst(); grandchild != NULL; grandchild = child->GetNext()) {
LogError("system child %s", grandchild->GetClassName().c_str());
if (grandchild->Is(MEASURE)) {
for (Object *ggchild = grandchild->GetFirst(); ggchild != NULL; ggchild = grandchild->GetNext()) {
LogError("system measure child %s", ggchild->GetClassName().c_str());
}
}
}
}
}

if (m_doc->IsTranscription() && m_doc->HasFacsimile()) m_doc->SyncFromFacsimileDoc();

// TODO change zones for staff children
m_editInfo.import("uuid", fillStaff->GetID());
m_editInfo.import("status", "OK");
m_editInfo.import("message", "");

return true;
}
Expand Down

0 comments on commit 141d546

Please sign in to comment.