diff --git a/src/editortoolkit_neume.cpp b/src/editortoolkit_neume.cpp index 114348a41b..f9c239c5ee 100644 --- a/src/editortoolkit_neume.cpp +++ b/src/editortoolkit_neume.cpp @@ -4229,35 +4229,34 @@ bool EditorToolkitNeume::AdjustPitchFromPosition(Object *obj, Clef *clef) if (clef == NULL) { ClassIdComparison ac(CLEF); clef = dynamic_cast(m_doc->GetDrawingPage()->FindPreviousChild(&ac, obj)); - if (clef == NULL) { - Layer *layer = vrv_cast(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(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(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); @@ -4286,30 +4285,26 @@ bool EditorToolkitNeume::AdjustPitchFromPosition(Object *obj, Clef *clef) if (clef == NULL) { ClassIdComparison ac(CLEF); clef = dynamic_cast(m_doc->GetDrawingPage()->FindPreviousChild(&ac, obj)); - if (clef == NULL) { - Layer *layer = vrv_cast(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(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(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) { @@ -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);