From 473199fdc0fa6efc4a127fbe25447e633a23ebcc Mon Sep 17 00:00:00 2001 From: Yinan Zhou Date: Tue, 3 Dec 2024 15:29:37 -0500 Subject: [PATCH 1/2] fix: handle no-clef in `AdjustPitchFromPosition` - When there is no previous clef found, use the default clef defined in ``, instead of using clef found later on the staff refs: https://github.com/DDMAL/Neon/issues/1248#issuecomment-2510263075 --- src/editortoolkit_neume.cpp | 43 ++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/src/editortoolkit_neume.cpp b/src/editortoolkit_neume.cpp index 114348a41b..576e4c3549 100644 --- a/src/editortoolkit_neume.cpp +++ b/src/editortoolkit_neume.cpp @@ -4226,24 +4226,31 @@ bool EditorToolkitNeume::AdjustPitchFromPosition(Object *obj, Clef *clef) return false; } + int clefOffset = 0; if (clef == NULL) { ClassIdComparison ac(CLEF); clef = dynamic_cast(m_doc->GetDrawingPage()->FindPreviousChild(&ac, obj)); + int clefOffset = 0; if (clef == NULL) { - Layer *layer = vrv_cast(staff->FindDescendantByType(LAYER)); - assert(layer); - clef = layer->GetCurrentClef(); + 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(); + } + else { + Staff *clefStaff = dynamic_cast(clef->GetFirstAncestor(STAFF)); + assert(clefStaff); + clefOffset = round((double)(clefStaff->GetDrawingY() + - clefStaff->GetDrawingRotationOffsetFor(m_view->ToLogicalX(clef->GetZone()->GetUlx())) + - m_view->ToLogicalY(clef->GetZone()->GetUly()))); + } } } 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; @@ -4283,6 +4290,8 @@ 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; } + + int clefOffset = 0; if (clef == NULL) { ClassIdComparison ac(CLEF); clef = dynamic_cast(m_doc->GetDrawingPage()->FindPreviousChild(&ac, obj)); @@ -4291,17 +4300,17 @@ bool EditorToolkitNeume::AdjustPitchFromPosition(Object *obj, Clef *clef) assert(layer); clef = layer->GetCurrentClef(); } + else { + Staff *clefStaff = dynamic_cast(clef->GetFirstAncestor(STAFF)); + assert(clefStaff); + clefOffset = round((double)(clefStaff->GetDrawingY() + - clefStaff->GetDrawingRotationOffsetFor(m_view->ToLogicalX(clef->GetZone()->GetUlx())) + - m_view->ToLogicalY(clef->GetZone()->GetUly()))); + } } - 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; From 67a5a42181a6b3ca9d5f911b772f40776777afca Mon Sep 17 00:00:00 2001 From: Yinan Zhou Date: Tue, 3 Dec 2024 15:55:15 -0500 Subject: [PATCH 2/2] fix: update octave change in `AdjustPitchForNewClef` refs: https://github.com/DDMAL/Neon/issues/1248#issuecomment-2513344698 --- src/pitchinterface.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pitchinterface.cpp b/src/pitchinterface.cpp index 893e928d57..e7d08596f5 100644 --- a/src/pitchinterface.cpp +++ b/src/pitchinterface.cpp @@ -109,13 +109,13 @@ void PitchInterface::AdjustPitchForNewClef(const Clef *oldClef, const Clef *newC int pitchDiff = -2 * (newClef->GetLine() - oldClef->GetLine()); if (oldClef->GetShape() == CLEFSHAPE_F) { - pitchDiff -= 3; + pitchDiff += 4; } else if (oldClef->GetShape() == CLEFSHAPE_G) { pitchDiff -= 4; } if (newClef->GetShape() == CLEFSHAPE_F) { - pitchDiff += 3; + pitchDiff -= 4; } else if (newClef->GetShape() == CLEFSHAPE_G) { pitchDiff += 4;