Skip to content

Commit

Permalink
Handle empty staff when inserting new staff
Browse files Browse the repository at this point in the history
  • Loading branch information
yinanazhou committed Dec 11, 2023
1 parent 600b100 commit e847556
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions src/editortoolkit_neume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -816,28 +816,27 @@ bool EditorToolkitNeume::Insert(std::string elementType, std::string staffId, in
Layer *newLayer = new Layer();
newStaff->AddChild(newLayer);

// Find index to insert new staff
ListOfObjects staves = parent->FindAllDescendantsByType(STAFF, false);
std::vector<Object *> stavesVector(staves.begin(), staves.end());
stavesVector.push_back(newStaff);
StaffSort staffSort;
std::stable_sort(stavesVector.begin(), stavesVector.end(), staffSort);
for (int i = 0; i < (int)staves.size(); ++i) {
if (stavesVector.at(i) == newStaff) {
parent->InsertChild(newStaff, i);
parent->Modify();

m_editInfo.import("uuid", newStaff->GetID());
m_editInfo.import("status", status);
m_editInfo.import("message", message);

return true;
if (staff) {
// Find index to insert new staff
ListOfObjects staves = parent->FindAllDescendantsByType(STAFF, false);
std::vector<Object *> stavesVector(staves.begin(), staves.end());
stavesVector.push_back(newStaff);
StaffSort staffSort;
std::stable_sort(stavesVector.begin(), stavesVector.end(), staffSort);
for (int i = 0; i < (int)staves.size(); ++i) {
if (stavesVector.at(i) == newStaff) {
parent->InsertChild(newStaff, i);
parent->Modify();

m_editInfo.import("uuid", newStaff->GetID());
m_editInfo.import("status", status);
m_editInfo.import("message", message);

return true;
}
}
}
LogWarning("Failed to insert newStaff into staff");
message += "Failed to insert newStaff into staves.";
parent->AddChild(newStaff);
parent->Modify();

m_editInfo.import("uuid", newStaff->GetID());
m_editInfo.import("status", status);
Expand Down

0 comments on commit e847556

Please sign in to comment.