Skip to content

Commit

Permalink
Apply JustifyYAdjustCrossStaff and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
brdvd committed Apr 13, 2023
1 parent 1035d92 commit 8400686
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 95 deletions.
5 changes: 0 additions & 5 deletions include/vrv/chord.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,6 @@ class Chord : public LayerElement,
*/
int InitOnsetOffsetEnd(FunctorParams *functorParams) override;

/**
* See Object::JustifyYAdjustCrossStaff
*/
int JustifyYAdjustCrossStaff(FunctorParams *functorParams) override;

/**
* See Object::GenerateMIDI
*/
Expand Down
18 changes: 0 additions & 18 deletions include/vrv/functorparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<StaffAlignment *, int> m_shiftForStaff;
Doc *m_doc;
};

//----------------------------------------------------------------------------
// InitMIDIParams
//----------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions include/vrv/justifyfunctor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
12 changes: 0 additions & 12 deletions include/vrv/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
55 changes: 0 additions & 55 deletions src/chord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,61 +646,6 @@ int Chord::InitOnsetOffsetEnd(FunctorParams *functorParams)
return FUNCTOR_CONTINUE;
}

int Chord::JustifyYAdjustCrossStaff(FunctorParams *functorParams)
{
JustifyYAdjustCrossStaffParams *params = vrv_params_cast<JustifyYAdjustCrossStaffParams *>(functorParams);
assert(params);

// Check if chord spreads across several staves
std::map<int, Staff *> 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<Stem *>(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<Flag *>(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<GenerateMIDIParams *>(functorParams);
Expand Down
8 changes: 3 additions & 5 deletions src/page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 8400686

Please sign in to comment.