diff --git a/include/vrv/chord.h b/include/vrv/chord.h index d806d5bc883..36b4e1662dd 100644 --- a/include/vrv/chord.h +++ b/include/vrv/chord.h @@ -204,11 +204,6 @@ class Chord : public LayerElement, */ int InitOnsetOffsetEnd(FunctorParams *functorParams) override; - /** - * See Object::JustifyYAdjustCrossStaff - */ - int JustifyYAdjustCrossStaff(FunctorParams *functorParams) override; - /** * See Object::GenerateMIDI */ diff --git a/include/vrv/functorparams.h b/include/vrv/functorparams.h index 68386b11ca9..a8bba349d2f 100644 --- a/include/vrv/functorparams.h +++ b/include/vrv/functorparams.h @@ -536,24 +536,6 @@ class InitProcessingListsParams : public FunctorParams { IntTree m_layerTree; }; -//---------------------------------------------------------------------------- -// JustifyYAdjustCrossStaffParams -//---------------------------------------------------------------------------- - -/** - * member 0: a map of calculated shifts per StaffAlignment - * => this is transferred from JustifyY - * member 1: the doc - **/ - -class JustifyYAdjustCrossStaffParams : public FunctorParams { -public: - JustifyYAdjustCrossStaffParams(Doc *doc) { m_doc = doc; } - - std::map m_shiftForStaff; - Doc *m_doc; -}; - //---------------------------------------------------------------------------- // InitMIDIParams //---------------------------------------------------------------------------- diff --git a/include/vrv/justifyfunctor.h b/include/vrv/justifyfunctor.h index 4ed55d958fd..fb6c1af93d0 100644 --- a/include/vrv/justifyfunctor.h +++ b/include/vrv/justifyfunctor.h @@ -154,6 +154,11 @@ class JustifyYAdjustCrossStaffFunctor : public DocFunctor { */ bool ImplementsEndInterface() const override { return false; } + /* + * Transfer the shift map + */ + void SetShiftForStaff(const ShiftMap &shiftMap) { m_shiftForStaff = shiftMap; } + /* * Functor interface */ diff --git a/include/vrv/object.h b/include/vrv/object.h index db516e1b9ed..ab517ed3d01 100644 --- a/include/vrv/object.h +++ b/include/vrv/object.h @@ -795,18 +795,6 @@ class Object : public BoundingBox { ///@} - /** - * @name Functors for justification. - */ - ///@{ - - /** - * Adjust cross staff content after vertical justification - */ - virtual int JustifyYAdjustCrossStaff(FunctorParams *) { return FUNCTOR_CONTINUE; } - - ///@} - /** * @name Functors for generating MIDI output. */ diff --git a/src/chord.cpp b/src/chord.cpp index e21896a4406..7a8aab0305a 100644 --- a/src/chord.cpp +++ b/src/chord.cpp @@ -646,61 +646,6 @@ int Chord::InitOnsetOffsetEnd(FunctorParams *functorParams) return FUNCTOR_CONTINUE; } -int Chord::JustifyYAdjustCrossStaff(FunctorParams *functorParams) -{ - JustifyYAdjustCrossStaffParams *params = vrv_params_cast(functorParams); - assert(params); - - // Check if chord spreads across several staves - std::map extremalStaves; - for (Note *note : { this->GetTopNote(), this->GetBottomNote() }) { - Staff *staff = note->GetAncestorStaff(RESOLVE_CROSS_STAFF); - extremalStaves.insert({ staff->GetN(), staff }); - } - // get chord parent staff - Staff *staff = this->GetAncestorStaff(RESOLVE_CROSS_STAFF); - extremalStaves.insert({ staff->GetN(), staff }); - - if (extremalStaves.size() < 2) return FUNCTOR_CONTINUE; - - // Now calculate the shift due to vertical justification - auto getShift = [params](Staff *staff) { - StaffAlignment *alignment = staff->GetAlignment(); - if (params->m_shiftForStaff.find(alignment) != params->m_shiftForStaff.end()) { - return params->m_shiftForStaff.at(alignment); - } - return 0; - }; - - const int shift = getShift(extremalStaves.rbegin()->second) - getShift(extremalStaves.begin()->second); - - // Add the shift to the stem length of the chord - Stem *stem = vrv_cast(this->FindDescendantByType(STEM)); - if (!stem) return FUNCTOR_CONTINUE; - - const int stemLen = stem->GetDrawingStemLen(); - if (stem->GetDrawingStemDir() == STEMDIRECTION_up) { - stem->SetDrawingStemLen(stemLen - shift); - } - else { - stem->SetDrawingStemLen(stemLen + shift); - } - - // Reposition the stem - Staff *rootStaff = (stem->GetDrawingStemDir() == STEMDIRECTION_up) ? extremalStaves.rbegin()->second - : extremalStaves.begin()->second; - stem->SetDrawingYRel(stem->GetDrawingYRel() + getShift(staff) - getShift(rootStaff)); - - // Add the shift to the flag position - Flag *flag = vrv_cast(stem->FindDescendantByType(FLAG)); - if (flag) { - const int sign = (stem->GetDrawingStemDir() == STEMDIRECTION_up) ? 1 : -1; - flag->SetDrawingYRel(flag->GetDrawingYRel() + sign * shift); - } - - return FUNCTOR_CONTINUE; -} - int Chord::GenerateMIDI(FunctorParams *functorParams) { GenerateMIDIParams *params = vrv_params_cast(functorParams); diff --git a/src/page.cpp b/src/page.cpp index 659c906266d..a6d6ef37594 100644 --- a/src/page.cpp +++ b/src/page.cpp @@ -628,11 +628,9 @@ void Page::JustifyVertically() if (!justifyY.GetShiftForStaff().empty()) { // Adjust cross staff content which is displaced through vertical justification - Functor justifyYAdjustCrossStaff(&Object::JustifyYAdjustCrossStaff); - JustifyYAdjustCrossStaffParams justifyYAdjustCrossStaffParams(doc); - // TODO: adjust later - // justifyYAdjustCrossStaffParams.m_shiftForStaff = justifyY.GetShiftForStaff(); - this->Process(&justifyYAdjustCrossStaff, &justifyYAdjustCrossStaffParams); + JustifyYAdjustCrossStaffFunctor justifyYAdjustCrossStaff(doc); + justifyYAdjustCrossStaff.SetShiftForStaff(justifyY.GetShiftForStaff()); + this->Process(justifyYAdjustCrossStaff); } }