diff --git a/src/editortoolkit_neume.cpp b/src/editortoolkit_neume.cpp index b29dfd18f8..114348a41b 100644 --- a/src/editortoolkit_neume.cpp +++ b/src/editortoolkit_neume.cpp @@ -4236,22 +4236,23 @@ bool EditorToolkitNeume::AdjustPitchFromPosition(Object *obj, Clef *clef) } } - assert(clef); + data_PITCHNAME pname; + 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()))); - // Reset pitch to be "on clef" - if (clef->GetShape() == CLEFSHAPE_C) { - pi->SetPname(PITCHNAME_c); - } - else if (clef->GetShape() == CLEFSHAPE_F) { - pi->SetPname(PITCHNAME_f); - } - else if (clef->GetShape() == CLEFSHAPE_G) { - pi->SetPname(PITCHNAME_g); - } - else { - LogError("Clef %s does not have valid shape. Shape is %s", clef->GetID().c_str(), clef->GetShape()); - return false; + 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 @@ -4261,12 +4262,10 @@ bool EditorToolkitNeume::AdjustPitchFromPosition(Object *obj, Clef *clef) } pi->SetOct(octave); - const int staffSize = m_doc->GetDrawingUnit(staff->m_drawingStaffSize); - const int pitchDifference = round((double)((staff->GetDrawingY() - staff->GetDrawingRotationOffsetFor(m_view->ToLogicalX(fi->GetZone()->GetUlx())) - - m_view->ToLogicalY(fi->GetZone()->GetUly()))) + - m_view->ToLogicalY(fi->GetZone()->GetUly()) - clefOffset)) / (double)(staffSize)); pi->AdjustPitchByOffset(-pitchDifference); return true; @@ -4284,7 +4283,6 @@ bool EditorToolkitNeume::AdjustPitchFromPosition(Object *obj, Clef *clef) LogWarning("Syllable/neume had no pitched children to reorder for syllable/neume %s", obj->GetID().c_str()); return true; } - if (clef == NULL) { ClassIdComparison ac(CLEF); clef = dynamic_cast(m_doc->GetDrawingPage()->FindPreviousChild(&ac, obj)); @@ -4298,6 +4296,13 @@ bool EditorToolkitNeume::AdjustPitchFromPosition(Object *obj, Clef *clef) assert(clef); data_PITCHNAME pname; + 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; @@ -4307,8 +4312,6 @@ bool EditorToolkitNeume::AdjustPitchFromPosition(Object *obj, Clef *clef) return false; } - const int staffSize = m_doc->GetDrawingUnit(staff->m_drawingStaffSize); - for (auto it = pitchedChildren.begin(); it != pitchedChildren.end(); ++it) { if ((*it)->Is(LIQUESCENT)) continue; @@ -4333,8 +4336,9 @@ bool EditorToolkitNeume::AdjustPitchFromPosition(Object *obj, Clef *clef) const int pitchDifference = round((double)((staff->GetDrawingY() - staff->GetDrawingRotationOffsetFor(m_view->ToLogicalX(fi->GetZone()->GetUlx())) - - m_view->ToLogicalY(fi->GetZone()->GetUly()))) + - m_view->ToLogicalY(fi->GetZone()->GetUly()) - clefOffset)) / (double)(staffSize)); + pi->AdjustPitchByOffset(-pitchDifference); }