Skip to content

Commit

Permalink
fix: handle no-clef in AdjustPitchFromPosition
Browse files Browse the repository at this point in the history
- When there is no previous clef found, use the default clef defined in `<staffDef>`, instead of using clef found later on the staff

refs: DDMAL/Neon#1248 (comment)
  • Loading branch information
yinanazhou committed Dec 3, 2024
1 parent 3db5a20 commit 2c9f356
Showing 1 changed file with 37 additions and 42 deletions.
79 changes: 37 additions & 42 deletions src/editortoolkit_neume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4229,35 +4229,34 @@ bool EditorToolkitNeume::AdjustPitchFromPosition(Object *obj, Clef *clef)
if (clef == NULL) {
ClassIdComparison ac(CLEF);
clef = dynamic_cast<Clef *>(m_doc->GetDrawingPage()->FindPreviousChild(&ac, obj));
if (clef == NULL) {
Layer *layer = vrv_cast<Layer *>(staff->FindDescendantByType(LAYER));
assert(layer);
clef = layer->GetCurrentClef();
}
}

data_PITCHNAME pname;
data_PITCHNAME pname = PITCHNAME_c;
const int staffSize = m_doc->GetDrawingUnit(staff->m_drawingStaffSize);
Staff *clefStaff = dynamic_cast<Staff *>(clef->GetFirstAncestor(STAFF));
assert(clefStaff);
const int clefOffset = round((double)(clefStaff->GetDrawingY()
- clefStaff->GetDrawingRotationOffsetFor(m_view->ToLogicalX(clef->GetZone()->GetUlx()))
- m_view->ToLogicalY(clef->GetZone()->GetUly())));

switch (clef->GetShape()) {
case CLEFSHAPE_C: pname = PITCHNAME_c; break;
case CLEFSHAPE_F: pname = PITCHNAME_f; break;
case CLEFSHAPE_G: pname = PITCHNAME_g; break;
default:
LogError("Clef %s does not have valid shape. Shape is %s", clef->GetID().c_str(), clef->GetShape());
return false;
int clefOffset = 0;
if (clef) {
Staff *clefStaff = dynamic_cast<Staff *>(clef->GetFirstAncestor(STAFF));
assert(clefStaff);
const int clefOffset = round((double)(clefStaff->GetDrawingY()
- clefStaff->GetDrawingRotationOffsetFor(m_view->ToLogicalX(clef->GetZone()->GetUlx()))
- m_view->ToLogicalY(clef->GetZone()->GetUly())));

switch (clef->GetShape()) {
case CLEFSHAPE_C: pname = PITCHNAME_c; break;
case CLEFSHAPE_F: pname = PITCHNAME_f; break;
case CLEFSHAPE_G: pname = PITCHNAME_g; break;
default:
LogError("Clef %s does not have valid shape. Shape is %s", clef->GetID().c_str(), clef->GetShape());
return false;
}
}

pi->SetPname(pname);

// The default octave = 4, but the actual octave is calculated by
// taking into account the displacement of the clef
int octave = 4;
if (clef->GetDis() && clef->GetDisPlace()) {
if (clef && clef->GetDis() && clef->GetDisPlace()) {
octave += (clef->GetDisPlace() == STAFFREL_basic_above ? 1 : -1) * (clef->GetDis() / 7);
}
pi->SetOct(octave);
Expand Down Expand Up @@ -4286,30 +4285,26 @@ bool EditorToolkitNeume::AdjustPitchFromPosition(Object *obj, Clef *clef)
if (clef == NULL) {
ClassIdComparison ac(CLEF);
clef = dynamic_cast<Clef *>(m_doc->GetDrawingPage()->FindPreviousChild(&ac, obj));
if (clef == NULL) {
Layer *layer = vrv_cast<Layer *>(staff->FindDescendantByType(LAYER));
assert(layer);
clef = layer->GetCurrentClef();
}
}

assert(clef);

data_PITCHNAME pname;
data_PITCHNAME pname = PITCHNAME_c;
const int staffSize = m_doc->GetDrawingUnit(staff->m_drawingStaffSize);
Staff *clefStaff = dynamic_cast<Staff *>(clef->GetFirstAncestor(STAFF));
assert(clefStaff);
const int clefOffset = round((double)(clefStaff->GetDrawingY()
- clefStaff->GetDrawingRotationOffsetFor(m_view->ToLogicalX(clef->GetZone()->GetUlx()))
- m_view->ToLogicalY(clef->GetZone()->GetUly())));

switch (clef->GetShape()) {
case CLEFSHAPE_C: pname = PITCHNAME_c; break;
case CLEFSHAPE_F: pname = PITCHNAME_f; break;
case CLEFSHAPE_G: pname = PITCHNAME_g; break;
default:
LogError("Clef %s does not have valid shape. Shape is %s", clef->GetID().c_str(), clef->GetShape());
return false;
int clefOffset = 0;
if (clef) {
Staff *clefStaff = dynamic_cast<Staff *>(clef->GetFirstAncestor(STAFF));
assert(clefStaff);
int clefOffset = round((double)(clefStaff->GetDrawingY()
- clefStaff->GetDrawingRotationOffsetFor(m_view->ToLogicalX(clef->GetZone()->GetUlx()))
- m_view->ToLogicalY(clef->GetZone()->GetUly())));

switch (clef->GetShape()) {
case CLEFSHAPE_C: pname = PITCHNAME_c; break;
case CLEFSHAPE_F: pname = PITCHNAME_f; break;
case CLEFSHAPE_G: pname = PITCHNAME_g; break;
default:
LogError("Clef %s does not have valid shape. Shape is %s", clef->GetID().c_str(), clef->GetShape());
return false;
}
}

for (auto it = pitchedChildren.begin(); it != pitchedChildren.end(); ++it) {
Expand All @@ -4328,7 +4323,7 @@ bool EditorToolkitNeume::AdjustPitchFromPosition(Object *obj, Clef *clef)
// The default octave = 4, but the actual octave is calculated by
// taking into account the displacement of the clef
int octave = 4;
if (clef->GetDis() && clef->GetDisPlace()) {
if (clef && clef->GetDis() && clef->GetDisPlace()) {
octave += (clef->GetDisPlace() == STAFFREL_basic_above ? 1 : -1) * (clef->GetDis() / 7);
}
pi->SetOct(octave);
Expand Down

0 comments on commit 2c9f356

Please sign in to comment.