Skip to content

Commit

Permalink
fix: add clef offset in AdjustPitchFromPosition
Browse files Browse the repository at this point in the history
  • Loading branch information
yinanazhou committed Nov 30, 2024
1 parent a0278a8 commit b32093d
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions src/editortoolkit_neume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<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())));

// 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
Expand All @@ -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;
Expand All @@ -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<Clef *>(m_doc->GetDrawingPage()->FindPreviousChild(&ac, obj));
Expand All @@ -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<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;
Expand All @@ -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;

Expand All @@ -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);
}

Expand Down

0 comments on commit b32093d

Please sign in to comment.