Skip to content

Commit

Permalink
Keep Pb & SystemMilestoneEnd order after staff sort
Browse files Browse the repository at this point in the history
  • Loading branch information
yinanazhou committed Apr 30, 2024
1 parent fd2a480 commit 39dac7a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
9 changes: 5 additions & 4 deletions include/vrv/editortoolkit_neume.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class EditorToolkitNeume : public EditorToolkit {
bool SetText(std::string elementId, const std::string &text);
bool SetClef(std::string elementId, std::string shape);
bool SetLiquescent(std::string elementId, std::string shape);
bool SortStaves();
bool Split(std::string elementId, int x);
bool SplitNeume(std::string elementId, std::string ncId);
bool Remove(std::string elementId);
Expand Down Expand Up @@ -187,10 +188,10 @@ struct StaffSort {
// Need to sort Measure to sort staff
bool operator()(Object *a, Object *b)
{
if (!a->Is(MEASURE) || !b->Is(MEASURE)) return false;
Measure *measureA = dynamic_cast<Measure *>(a);
Measure *measureB = dynamic_cast<Measure *>(b);

if (!a->Is(SYSTEM) || !b->Is(SYSTEM)) return false;
if (!a->FindDescendantByType(MEASURE) || !b->FindDescendantByType(MEASURE)) return false;
Measure *measureA = dynamic_cast<Measure *>(a->FindDescendantByType(MEASURE));
Measure *measureB = dynamic_cast<Measure *>(b->FindDescendantByType(MEASURE));
if (!measureA->IsNeumeLine() || !measureB->IsNeumeLine()) return true;
Object *staffA = a->FindDescendantByType(STAFF);
Object *staffB = b->FindDescendantByType(STAFF);
Expand Down
41 changes: 39 additions & 2 deletions src/editortoolkit_neume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,8 @@ bool EditorToolkitNeume::Drag(std::string elementId, int x, int y)
(*it)->ShiftByXY(x, -y);
}

staff->GetParent()->GetParent()->StableSort(StaffSort());
SortStaves();

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

return true; // Can't reorder by layer since staves contain layers
Expand Down Expand Up @@ -2039,6 +2040,42 @@ bool EditorToolkitNeume::SetLiquescent(std::string elementId, std::string curve)
return true;
}

bool EditorToolkitNeume::SortStaves()
{
if (!m_doc->GetDrawingPage()) {
LogError("Could not get drawing page.");
m_editInfo.import("status", "FAILURE");
m_editInfo.import("message", "Could not get drawing page.");
return false;
}

Object *page = m_doc->GetDrawingPage();

page->StableSort(StaffSort());

Object *pb = page->FindDescendantByType(PB);
Object *milestoneEnd = page->FindDescendantByType(SYSTEM_MILESTONE_END);
assert(pb);
assert(milestoneEnd);
Object *pbParent = pb->GetParent();
Object *milestoneEndParent = milestoneEnd->GetParent();
int pbIdx = pbParent->GetChildIndex(pb);
int milestoneEndIdx = milestoneEndParent->GetChildIndex(milestoneEnd);

pb = pbParent->DetachChild(pbIdx);
milestoneEnd = milestoneEndParent->DetachChild(milestoneEndIdx);

Object *firstSystem = page->GetFirst(SYSTEM);
Object *lastSystem = page->GetLast(SYSTEM);
assert(firstSystem);
assert(lastSystem);

firstSystem->InsertChild(pb, 0);
lastSystem->InsertChild(milestoneEnd, lastSystem->GetChildCount());

return true;
}

bool EditorToolkitNeume::Split(std::string elementId, int x)
{
if (!m_doc->GetDrawingPage()) {
Expand Down Expand Up @@ -2369,7 +2406,7 @@ bool EditorToolkitNeume::Resize(std::string elementId, int ulx, int uly, int lrx
zone->SetRotate(rotate);
}
zone->Modify();
staff->GetParent()->StableSort(StaffSort());
SortStaves();
}
else if (obj->Is(SYL)) {
Syl *syl = vrv_cast<Syl *>(obj);
Expand Down

0 comments on commit 39dac7a

Please sign in to comment.