From 0df6a66ceda933bc4b5a5f3c66393faa4bbe64b4 Mon Sep 17 00:00:00 2001 From: Yinan Zhou Date: Wed, 26 Jun 2024 12:41:56 -0400 Subject: [PATCH 1/4] Fix closest staff finding and pitch alignment for new inserted element - Revert changes in `ClosestBB::distanceToBB()` - Call `Page::LayOutPitchPos()` after adjust pitch Refs: https://github.com/DDMAL/Neon/issues/1226 --- include/vrv/editortoolkit_neume.h | 4 ++-- src/editortoolkit_neume.cpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/vrv/editortoolkit_neume.h b/include/vrv/editortoolkit_neume.h index 90dd931c667..1a925b0c8f9 100644 --- a/include/vrv/editortoolkit_neume.h +++ b/include/vrv/editortoolkit_neume.h @@ -122,8 +122,8 @@ struct ClosestBB { int offset = (x - ulx) * tan(rotate * M_PI / 180.0); uly = uly + offset; lry = lry + offset; - int xDiff = std::abs(x - ulx); - int yDiff = std::abs(y - uly); + int xDiff = std::max((ulx > x ? ulx - x : 0), (x > lrx ? x - lrx : 0)); + int yDiff = std::max((uly > y ? uly - y : 0), (y > lry ? y - lry : 0)); return sqrt(xDiff * xDiff + yDiff * yDiff); } diff --git a/src/editortoolkit_neume.cpp b/src/editortoolkit_neume.cpp index 73decbabee9..8c440f79d81 100644 --- a/src/editortoolkit_neume.cpp +++ b/src/editortoolkit_neume.cpp @@ -1250,6 +1250,7 @@ bool EditorToolkitNeume::Insert(std::string elementType, std::string staffId, in } layer->ReorderByXPos(); + m_doc->GetDrawingPage()->LayOutPitchPos(); if (m_doc->IsTranscription() && m_doc->HasFacsimile()) m_doc->SyncFromFacsimileDoc(); m_editInfo.import("status", status); From fc2fdb36703913b4b56423c2eaa9adea93fa656d Mon Sep 17 00:00:00 2001 From: Yinan Zhou Date: Thu, 27 Jun 2024 09:53:38 -0400 Subject: [PATCH 2/4] Remove redundant for loop --- src/editortoolkit_neume.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/editortoolkit_neume.cpp b/src/editortoolkit_neume.cpp index 8c440f79d81..e602ae8f6ce 100644 --- a/src/editortoolkit_neume.cpp +++ b/src/editortoolkit_neume.cpp @@ -664,18 +664,17 @@ bool EditorToolkitNeume::Drag(std::string elementId, int x, int y) } // Move staff and all staff children with facsimiles + Zone *staffZone = staff->GetZone(); + assert(staffZone); + staffZone->ShiftByXY(x, -y); ListOfObjects children; InterfaceComparison ic(INTERFACE_FACSIMILE); staff->FindAllDescendantsByComparison(&children, &ic); - std::set zones; - zones.insert(staff->GetZone()); for (auto it = children.begin(); it != children.end(); ++it) { FacsimileInterface *fi = (*it)->GetFacsimileInterface(); assert(fi); - if (fi->GetZone() != NULL) zones.insert(fi->GetZone()); - } - for (auto it = zones.begin(); it != zones.end(); ++it) { - (*it)->ShiftByXY(x, -y); + Zone *zone = fi->GetZone(); + if (zone) zone->ShiftByXY(x, -y); } SortStaves(); From e0f40a9138db5d3bca3571e90c0221472da32c58 Mon Sep 17 00:00:00 2001 From: Yinan Zhou Date: Thu, 27 Jun 2024 10:23:49 -0400 Subject: [PATCH 3/4] Align staff children after staff drag - Call `Page::ResetAligners()` after dragging staff Refs: https://github.com/DDMAL/Neon/issues/1230 --- src/editortoolkit_neume.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/editortoolkit_neume.cpp b/src/editortoolkit_neume.cpp index e602ae8f6ce..1bd268778c8 100644 --- a/src/editortoolkit_neume.cpp +++ b/src/editortoolkit_neume.cpp @@ -679,6 +679,7 @@ bool EditorToolkitNeume::Drag(std::string elementId, int x, int y) SortStaves(); + m_doc->GetDrawingPage()->ResetAligners(); if (m_doc->IsTranscription() && m_doc->HasFacsimile()) m_doc->SyncFromFacsimileDoc(); return true; // Can't reorder by layer since staves contain layers From 3ae461739514f0c38d3f17b0ba7ab7b287786014 Mon Sep 17 00:00:00 2001 From: Yinan Zhou Date: Thu, 27 Jun 2024 12:23:48 -0400 Subject: [PATCH 4/4] Remove empty system after staff merging Refs: https://github.com/DDMAL/Neon/issues/1220 --- src/editortoolkit_neume.cpp | 39 +++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/src/editortoolkit_neume.cpp b/src/editortoolkit_neume.cpp index 1bd268778c8..50cf062f61d 100644 --- a/src/editortoolkit_neume.cpp +++ b/src/editortoolkit_neume.cpp @@ -1711,6 +1711,8 @@ bool EditorToolkitNeume::MatchHeight(std::string elementId) bool EditorToolkitNeume::Merge(std::vector 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. @@ -1777,8 +1779,35 @@ bool EditorToolkitNeume::Merge(std::vector elementIds) Layer *sourceLayer = vrv_cast(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(); @@ -1790,14 +1819,12 @@ bool EditorToolkitNeume::Merge(std::vector elementIds) fillLayer->ReorderByXPos(); + if (m_doc->IsTranscription() && m_doc->HasFacsimile()) m_doc->SyncFromFacsimileDoc(); + m_editInfo.import("uuid", fillStaff->GetID()); m_editInfo.import("status", "OK"); m_editInfo.import("message", ""); - if (m_doc->IsTranscription() && m_doc->HasFacsimile()) m_doc->SyncFromFacsimileDoc(); - - // TODO change zones for staff children - return true; }