Skip to content

Commit

Permalink
Merge pull request #3857 from rism-digital/develop-ledger-lines
Browse files Browse the repository at this point in the history
Add ledger lines to accid not child of note
  • Loading branch information
lpugin authored Nov 11, 2024
2 parents c87b3d6 + f96a142 commit 911d63c
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 51 deletions.
5 changes: 5 additions & 0 deletions include/vrv/calcledgerlinesfunctor.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,18 @@ class CalcLedgerLinesFunctor : public DocFunctor {
* Functor interface
*/
///@{
FunctorCode VisitAccid(Accid *accid) override;
FunctorCode VisitNote(Note *note) override;
FunctorCode VisitStaffEnd(Staff *staff) override;
///@}

protected:
//
private:
/**
*
*/
void CalcForLayerElement(LayerElement *layerElement, int width, data_HORIZONTALALIGNMENT alignment);
/**
* Shorten ledger lines which overlap with neighbors
*/
Expand Down
22 changes: 0 additions & 22 deletions include/vrv/note.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*/
Expand Down
8 changes: 8 additions & 0 deletions include/vrv/positioninterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 //
//-----------------//
Expand Down
3 changes: 2 additions & 1 deletion src/accid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ void Accid::AdjustX(LayerElement *element, const Doc *doc, int staffSize, std::v
Note *note = vrv_cast<Note *>(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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/adjustaccidxfunctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ std::vector<Accid *> AdjustAccidXFunctor::GetAccidentalsForAdjustment(AlignmentR
for (Object *child : alignmentReference->GetChildren()) {
if (child->Is(ACCID)) {
Accid *accid = vrv_cast<Accid *>(child);
if (accid->HasAccid()) accidentals.push_back(accid);
if (accid->HasAccid() && accid->GetFirstAncestor(NOTE)) accidentals.push_back(accid);
}
}
return accidentals;
Expand Down
51 changes: 41 additions & 10 deletions src/calcledgerlinesfunctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//----------------------------------------------------------------------------

#include "doc.h"
#include "dot.h"
#include "note.h"
#include "staff.h"

Expand All @@ -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) {
Expand All @@ -31,31 +47,46 @@ 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);
}
else {
staff->AddLedgerLineBelow(linesBelow, left, right, extension, drawingCueSize);
}

return FUNCTOR_SIBLINGS;
}

FunctorCode CalcLedgerLinesFunctor::VisitStaffEnd(Staff *staff)
Expand Down
4 changes: 3 additions & 1 deletion src/calcstemfunctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 0 additions & 16 deletions src/note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ void Note::Reset()
m_noteGroupPosition = 0;
m_noteGroup = NULL;

m_drawingLoc = 0;
m_flippedNotehead = false;

m_stemSameas = NULL;
Expand Down Expand Up @@ -214,21 +213,6 @@ const Accid *Note::GetDrawingAccid() const
return vrv_cast<const Accid *>(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<Chord *>(this->GetFirstAncestor(CHORD, MAX_CHORD_DEPTH));
Expand Down
16 changes: 16 additions & 0 deletions src/positioninterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "layer.h"
#include "pitchinterface.h"
#include "staff.h"

namespace vrv {

Expand Down Expand Up @@ -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)
//----------------------------------------------------------------------------
Expand Down

0 comments on commit 911d63c

Please sign in to comment.