diff --git a/include/vrv/calcledgerlinesfunctor.h b/include/vrv/calcledgerlinesfunctor.h index d2d83ab482..826d66a220 100644 --- a/include/vrv/calcledgerlinesfunctor.h +++ b/include/vrv/calcledgerlinesfunctor.h @@ -38,6 +38,7 @@ class CalcLedgerLinesFunctor : public DocFunctor { * Functor interface */ ///@{ + FunctorCode VisitAccid(Accid *accid) override; FunctorCode VisitNote(Note *note) override; FunctorCode VisitStaffEnd(Staff *staff) override; ///@} @@ -45,6 +46,10 @@ class CalcLedgerLinesFunctor : public DocFunctor { protected: // private: + /** + * + */ + void CalcForLayerElement(LayerElement *layerElement, int width, data_HORIZONTALALIGNMENT alignment); /** * Shorten ledger lines which overlap with neighbors */ diff --git a/include/vrv/note.h b/include/vrv/note.h index 2ab4cc48bc..aaf6a461b5 100644 --- a/include/vrv/note.h +++ b/include/vrv/note.h @@ -123,23 +123,6 @@ class Note : public LayerElement, const Accid *GetDrawingAccid() const; ///@} - /** - * @name Setter and getter for the drawing staff loc. - * This is set by the CalcAlignmentPitchPosFunctor. - */ - ///@{ - void SetDrawingLoc(int drawingLoc) { m_drawingLoc = drawingLoc; } - int GetDrawingLoc() const { return m_drawingLoc; } - ///@} - - /** - * Check if the note has ledger lines. - * If staff is passed, use it for getting the staff line number. - * Otherwise, it will look for the Staff ancestor. - * Set the value of ledger lines above or below. - */ - bool HasLedgerLines(int &linesAbove, int &linesBelow, const Staff *staff = NULL) const; - /** * Overriding functions to return information from chord parent if any */ @@ -326,11 +309,6 @@ class Note : public LayerElement, public: // private: - /** - * The drawing location of the note - */ - int m_drawingLoc; - /** * A fling indicating if the note head is flipped */ diff --git a/include/vrv/positioninterface.h b/include/vrv/positioninterface.h index 4cc01c4990..554b200037 100644 --- a/include/vrv/positioninterface.h +++ b/include/vrv/positioninterface.h @@ -57,6 +57,14 @@ class PositionInterface : public Interface, public AttStaffLoc, public AttStaffL */ bool HasIdenticalPositionInterface(const PositionInterface *otherPositionInterface) const; + /** + * Check if the note has ledger lines. + * If staff is passed, use it for getting the staff line number. + * Otherwise, it will look for the Staff ancestor. + * Set the value of ledger lines above or below. + */ + bool HasLedgerLines(int &linesAbove, int &linesBelow, const Staff *staff) const; + //-----------------// // Pseudo functors // //-----------------// diff --git a/src/accid.cpp b/src/accid.cpp index 73a12003ff..e97ed1e5f8 100644 --- a/src/accid.cpp +++ b/src/accid.cpp @@ -130,7 +130,8 @@ void Accid::AdjustX(LayerElement *element, const Doc *doc, int staffSize, std::v Note *note = vrv_cast(element); int ledgerAbove = 0; int ledgerBelow = 0; - if (note->HasLedgerLines(ledgerAbove, ledgerBelow)) { + Staff *staff = note->GetAncestorStaff(RESOLVE_CROSS_STAFF); + if (note->HasLedgerLines(ledgerAbove, ledgerBelow, staff)) { const int value = doc->GetOptions()->m_ledgerLineExtension.GetValue() * unit + 0.5 * horizontalMargin; horizontalMargin = std::max(horizontalMargin, value); } diff --git a/src/adjustaccidxfunctor.cpp b/src/adjustaccidxfunctor.cpp index f4baadfb23..d02ca42636 100644 --- a/src/adjustaccidxfunctor.cpp +++ b/src/adjustaccidxfunctor.cpp @@ -133,7 +133,7 @@ std::vector AdjustAccidXFunctor::GetAccidentalsForAdjustment(AlignmentR for (Object *child : alignmentReference->GetChildren()) { if (child->Is(ACCID)) { Accid *accid = vrv_cast(child); - if (accid->HasAccid()) accidentals.push_back(accid); + if (accid->HasAccid() && accid->GetFirstAncestor(NOTE)) accidentals.push_back(accid); } } return accidentals; diff --git a/src/calcledgerlinesfunctor.cpp b/src/calcledgerlinesfunctor.cpp index a1cf9b5b5b..bef0616bf2 100644 --- a/src/calcledgerlinesfunctor.cpp +++ b/src/calcledgerlinesfunctor.cpp @@ -10,6 +10,7 @@ //---------------------------------------------------------------------------- #include "doc.h" +#include "dot.h" #include "note.h" #include "staff.h" @@ -21,6 +22,21 @@ namespace vrv { CalcLedgerLinesFunctor::CalcLedgerLinesFunctor(Doc *doc) : DocFunctor(doc) {} +FunctorCode CalcLedgerLinesFunctor::VisitAccid(Accid *accid) +{ + if (accid->GetFirstAncestor(NOTE)) { + return FUNCTOR_SIBLINGS; + } + + Staff *staff = accid->GetAncestorStaff(); + + const int width = m_doc->GetGlyphWidth(Accid::GetAccidGlyph(accid->GetAccid()), staff->m_drawingStaffSize, false); + + this->CalcForLayerElement(accid, width, HORIZONTALALIGNMENT_center); + + return FUNCTOR_SIBLINGS; +} + FunctorCode CalcLedgerLinesFunctor::VisitNote(Note *note) { if (note->GetVisible() == BOOLEAN_false) { @@ -31,22 +47,39 @@ FunctorCode CalcLedgerLinesFunctor::VisitNote(Note *note) return FUNCTOR_SIBLINGS; } - Staff *staff = note->GetAncestorStaff(RESOLVE_CROSS_STAFF); - const int staffSize = staff->m_drawingStaffSize; - const int staffX = staff->GetDrawingX(); - const bool drawingCueSize = note->GetDrawingCueSize(); const int radius = note->GetDrawingRadius(m_doc); - /************** Ledger lines: **************/ + this->CalcForLayerElement(note, 2 * radius, HORIZONTALALIGNMENT_left); + + return FUNCTOR_SIBLINGS; +} + +void CalcLedgerLinesFunctor::CalcForLayerElement( + LayerElement *layerElement, int width, data_HORIZONTALALIGNMENT alignment) +{ + Staff *staff = layerElement->GetAncestorStaff(RESOLVE_CROSS_STAFF); + assert(staff); + + const int staffSize = staff->m_drawingStaffSize; + const int staffX = staff->GetDrawingX(); + const bool drawingCueSize = layerElement->GetDrawingCueSize(); int linesAbove = 0; int linesBelow = 0; - if (!note->HasLedgerLines(linesAbove, linesBelow, staff)) return FUNCTOR_SIBLINGS; + PositionInterface *interface = layerElement->GetPositionInterface(); + assert(interface); + + if (!interface->HasLedgerLines(linesAbove, linesBelow, staff)) return; const int extension = m_doc->GetDrawingLedgerLineExtension(staffSize, drawingCueSize); - const int left = note->GetDrawingX() - extension - staffX; - int right = note->GetDrawingX() + 2 * radius + extension - staffX; + int left = layerElement->GetDrawingX() - extension - staffX; + int right = layerElement->GetDrawingX() + width + extension - staffX; + + if (alignment == HORIZONTALALIGNMENT_center) { + right -= width / 2; + left -= width / 2; + } if (linesAbove > 0) { staff->AddLedgerLineAbove(linesAbove, left, right, extension, drawingCueSize); @@ -54,8 +87,6 @@ FunctorCode CalcLedgerLinesFunctor::VisitNote(Note *note) else { staff->AddLedgerLineBelow(linesBelow, left, right, extension, drawingCueSize); } - - return FUNCTOR_SIBLINGS; } FunctorCode CalcLedgerLinesFunctor::VisitStaffEnd(Staff *staff) diff --git a/src/calcstemfunctor.cpp b/src/calcstemfunctor.cpp index 17a65040e5..df7a50f18c 100644 --- a/src/calcstemfunctor.cpp +++ b/src/calcstemfunctor.cpp @@ -660,7 +660,9 @@ void CalcStemFunctor::AdjustFlagPlacement( } int ledgerAbove = 0; int ledgerBelow = 0; - if (!note || !note->HasLedgerLines(ledgerAbove, ledgerBelow)) return; + + Staff *staff = note->GetAncestorStaff(RESOLVE_CROSS_STAFF); + if (!note || !note->HasLedgerLines(ledgerAbove, ledgerBelow, staff)) return; if (((stemDirection == STEMDIRECTION_up) && !ledgerBelow) || ((stemDirection == STEMDIRECTION_down) && !ledgerAbove)) return; diff --git a/src/note.cpp b/src/note.cpp index 54af2ee569..f0bd536eca 100644 --- a/src/note.cpp +++ b/src/note.cpp @@ -121,7 +121,6 @@ void Note::Reset() m_noteGroupPosition = 0; m_noteGroup = NULL; - m_drawingLoc = 0; m_flippedNotehead = false; m_stemSameas = NULL; @@ -214,21 +213,6 @@ const Accid *Note::GetDrawingAccid() const return vrv_cast(this->FindDescendantByType(ACCID)); } -bool Note::HasLedgerLines(int &linesAbove, int &linesBelow, const Staff *staff) const -{ - if (!staff) { - staff = this->GetAncestorStaff(); - } - - linesAbove = (this->GetDrawingLoc() - staff->m_drawingLines * 2 + 2) / 2; - linesBelow = -(this->GetDrawingLoc()) / 2; - - linesAbove = std::max(linesAbove, 0); - linesBelow = std::max(linesBelow, 0); - - return ((linesAbove > 0) || (linesBelow > 0)); -} - Chord *Note::IsChordTone() { return vrv_cast(this->GetFirstAncestor(CHORD, MAX_CHORD_DEPTH)); diff --git a/src/positioninterface.cpp b/src/positioninterface.cpp index 05c0ce496b..d3bf0abed6 100644 --- a/src/positioninterface.cpp +++ b/src/positioninterface.cpp @@ -15,6 +15,7 @@ #include "layer.h" #include "pitchinterface.h" +#include "staff.h" namespace vrv { @@ -71,6 +72,21 @@ int PositionInterface::CalcDrawingLoc(const Layer *layer, const LayerElement *el return m_drawingLoc; } +bool PositionInterface::HasLedgerLines(int &linesAbove, int &linesBelow, const Staff *staff) const +{ + if (!staff) return false; + + linesAbove = (this->GetDrawingLoc() - staff->m_drawingLines * 2 + 2) / 2; + linesBelow = -(this->GetDrawingLoc()) / 2; + + linesAbove = std::max(linesAbove, 0); + linesBelow = std::max(linesBelow, 0); + + return ((linesAbove > 0) || (linesBelow > 0)); + + return false; +} + //---------------------------------------------------------------------------- // Interface pseudo functor (redirected) //----------------------------------------------------------------------------