Verovio
Source code documentation
layerelement.h
1 // Name: layerelement.h
3 // Author: Laurent Pugin
4 // Created: 2011
5 // Copyright (c) Authors and others. All rights reserved.
7 
8 #ifndef __VRV_LAYER_ELEMENT_H__
9 #define __VRV_LAYER_ELEMENT_H__
10 
11 #include <set>
12 
13 //----------------------------------------------------------------------------
14 
15 #include "atts_shared.h"
16 #include "facsimileinterface.h"
17 #include "fraction.h"
18 #include "linkinginterface.h"
19 #include "object.h"
20 
21 namespace vrv {
22 
23 class Beam;
24 class BeamElementCoord;
25 class FTrem;
26 class Layer;
27 class Liquescent;
28 class Mensur;
29 class MeterSig;
30 class Staff;
31 class StaffAlignment;
32 
33 struct AlignMeterParams;
34 
35 // Helper enums
36 enum StaffSearch { ANCESTOR_ONLY = 0, RESOLVE_CROSS_STAFF };
37 
38 //----------------------------------------------------------------------------
39 // LayerElement
40 //----------------------------------------------------------------------------
41 
46 class LayerElement : public Object,
47  public FacsimileInterface,
48  public LinkingInterface,
49  public AttCoordX1,
50  public AttLabelled,
51  public AttTyped {
52 public:
58  LayerElement();
59  LayerElement(ClassId classId);
60  virtual ~LayerElement();
61  void Reset() override;
63 
67  void CloneReset() override;
68 
73  FacsimileInterface *GetFacsimileInterface() override { return vrv_cast<FacsimileInterface *>(this); }
74  const FacsimileInterface *GetFacsimileInterface() const override
75  {
76  return vrv_cast<const FacsimileInterface *>(this);
77  }
78  LinkingInterface *GetLinkingInterface() override { return vrv_cast<LinkingInterface *>(this); }
79  const LinkingInterface *GetLinkingInterface() const override { return vrv_cast<const LinkingInterface *>(this); }
81 
86  virtual bool HasToBeAligned() const { return false; }
87 
91  virtual bool IsScoreDefElement() const { return false; }
92 
97  virtual bool IsRelativeToStaff() const { return false; }
98 
104  const LayerElement *ThisOrSameasLink() const;
106 
114  ElementScoreDefRole GetScoreDefRole() const { return m_scoreDefRole; }
115  void SetScoreDefRole(ElementScoreDefRole scoreDefRole) { m_scoreDefRole = scoreDefRole; }
117 
122 
123  bool IsGraceNote() const;
125  bool IsInLigature() const;
128  const FTrem *GetAncestorFTrem() const;
136  const Beam *GetAncestorBeam() const;
137  bool IsInBeam() const;
139 
144  void SetDrawingCueSize(bool drawingCueSize) { m_drawingCueSize = drawingCueSize; }
145  bool GetDrawingCueSize() const { return m_drawingCueSize; }
147 
152  void SetIsInBeamSpan(bool isInBeamSpan);
153  bool GetIsInBeamSpan() const { return m_isInBeamspan; }
155 
160  int GetAlignmentLayerN() const { return m_alignmentLayerN; }
161  void SetAlignmentLayerN(int alignmentLayerN) { m_alignmentLayerN = alignmentLayerN; }
163 
167  int GetOriginalLayerN() const;
168 
173  int GetDrawingX() const override;
174  int GetDrawingY() const override;
176 
181  int GetDrawingXRel() const { return m_drawingXRel; }
182  virtual void SetDrawingXRel(int drawingXRel);
183  void CacheXRel(bool restore = false);
184  int GetDrawingYRel() const { return m_drawingYRel; }
185  virtual void SetDrawingYRel(int drawingYRel);
186  void CacheYRel(bool restore = false);
188 
193 
201  int GetDrawingTop(const Doc *doc, int staffSize, bool withArtic = true, ArticType articType = ARTIC_INSIDE) const;
202  int GetDrawingBottom(
203  const Doc *doc, int staffSize, bool withArtic = true, ArticType articType = ARTIC_INSIDE) const;
204 
208  int GetDrawingRadius(const Doc *doc, bool isInLigature = false) const;
209 
214  Alignment *GetAlignment() { return m_alignment; }
215  const Alignment *GetAlignment() const { return m_alignment; }
216  void ResetAlignment() { m_alignment = NULL; }
217  void SetAlignment(Alignment *alignment) { m_alignment = alignment; }
219 
224  Staff *GetAncestorStaff(StaffSearch strategy = ANCESTOR_ONLY, bool assertExistence = true);
225  const Staff *GetAncestorStaff(StaffSearch strategy = ANCESTOR_ONLY, bool assertExistence = true) const;
227 
235  const Staff *GetCrossStaff(const Layer *&layer) const;
237 
241  data_STAFFREL_basic GetCrossStaffRel() const;
242 
249 
254  Alignment *GetGraceAlignment();
255  const Alignment *GetGraceAlignment() const;
256  void ResetGraceAlignment() { m_graceAlignment = NULL; }
257  void SetGraceAlignment(Alignment *graceAlignment);
258  bool HasGraceAlignment() const { return (m_graceAlignment != NULL); }
260 
264  Fraction GetAlignmentDuration(const AlignMeterParams &params, bool notGraceOnly = true,
265  data_NOTATIONTYPE notationType = NOTATIONTYPE_cmn) const;
266 
271  Fraction GetAlignmentDuration(bool notGraceOnly = true, data_NOTATIONTYPE notationType = NOTATIONTYPE_cmn) const;
272 
277  Fraction GetSameAsContentAlignmentDuration(const AlignMeterParams &params, bool notGraceOnly = true,
278  data_NOTATIONTYPE notationType = NOTATIONTYPE_cmn) const;
279 
280  Fraction GetContentAlignmentDuration(const AlignMeterParams &params, bool notGraceOnly = true,
281  data_NOTATIONTYPE notationType = NOTATIONTYPE_cmn) const;
282 
283  Fraction GetContentAlignmentDuration(
284  bool notGraceOnly = true, data_NOTATIONTYPE notationType = NOTATIONTYPE_cmn) const;
285 
290  bool GenerateZoneBounds(int *ulx, int *uly, int *lrx, int *lry) const;
291 
296  virtual int AdjustOverlappingLayers(const Doc *doc, const std::vector<LayerElement *> &otherElements,
297  bool areDotsAdjusted, bool &isUnison, bool &stemSameAs);
298 
303  std::pair<int, bool> CalcElementHorizontalOverlap(const Doc *doc, const std::vector<LayerElement *> &otherElements,
304  bool areDotsAdjusted, bool isChordElement, bool isLowerElement = false, bool unison = true);
305 
309  virtual data_STEMMODIFIER GetDrawingStemMod() const;
310 
314  virtual bool HasCrossStaff() const { return (m_crossStaff != NULL); }
315 
319  char32_t StemModToGlyph(data_STEMMODIFIER stemMod) const;
320 
325  MapOfDotLocs CalcOptimalDotLocations();
326 
327  //----------//
328  // Functors //
329  //----------//
330 
335  FunctorCode Accept(Functor &functor) override;
336  FunctorCode Accept(ConstFunctor &functor) const override;
337  FunctorCode AcceptEnd(Functor &functor) override;
338  FunctorCode AcceptEnd(ConstFunctor &functor) const override;
340 
341 protected:
348  std::vector<int> GetElementsInUnison(
349  const std::set<int> &firstChord, const std::set<int> &secondChord, data_STEMDIRECTION stemDirection) const;
350 
354  virtual MapOfNoteLocs CalcNoteLocations(NotePredicate = NULL) const { return {}; }
355 
361  virtual MapOfDotLocs CalcDotLocations(int, bool) const { return {}; }
362 
363  //----------------//
364  // Static methods //
365  //----------------//
366 
371  static int GetDotCount(const MapOfDotLocs &dotLocations);
372 
376  static int GetCollisionCount(const MapOfDotLocs &dotLocs1, const MapOfDotLocs &dotLocs2);
377 
378 private:
379  int GetDrawingArticulationTopOrBottom(data_STAFFREL place, ArticType type) const;
380 
384  void GetChordOverflow(StaffAlignment *&above, StaffAlignment *&below, int staffN);
385 
386 public:
389  int m_drawingFacsY; // This is used only for accid, syl
395  Layer *m_crossLayer;
396 
397 protected:
398  Alignment *m_alignment;
399 
404 
410 
415 
421 
426 
431 
432 private:
436  ElementScoreDefRole m_scoreDefRole;
437 
442  int m_alignmentLayerN;
443 
444  // flag to indicate that layerElement belongs to the beamSpan
445  bool m_isInBeamspan;
446 };
447 
448 } // namespace vrv
449 
450 #endif
This class stores an alignment position elements will point to.
Definition: horizontalaligner.h:73
Definition: beam.h:284
This abstract class is the base class for all const functors.
Definition: functor.h:126
This class is a hold the data and corresponds to the model of a MVC design pattern.
Definition: doc.h:41
This class models the MEI <fTrem> element.
Definition: ftrem.h:25
Definition: facsimileinterface.h:27
Definition: fraction.h:19
This abstract class is the base class for all mutable functors.
Definition: functor.h:101
This class is a base class for the Layer (<layer>) content.
Definition: layerelement.h:51
void CloneReset() override
Overriding CloneReset() method to be called after copy / assignment calls.
virtual bool HasToBeAligned() const
Return true if the element has to be aligned horizontally It is typically set to false for mRest,...
Definition: layerelement.h:86
int m_cachedXRel
The cached value for m_drawingXRel for caching horizontal layout.
Definition: layerelement.h:425
int m_drawingYRel
The Y drawing relative position of the object.
Definition: layerelement.h:409
int GetOriginalLayerN() const
bool GenerateZoneBounds(int *ulx, int *uly, int *lrx, int *lry) const
Get zone bounds using child elements with facsimile information.
int GetDrawingTop(const Doc *doc, int staffSize, bool withArtic=true, ArticType articType=ARTIC_INSIDE) const
Returns the drawing top and bottom taking into accound stem, etc.
Staff * GetAncestorStaff(StaffSearch strategy=ANCESTOR_ONLY, bool assertExistence=true)
Get the ancestor or cross staff.
FunctorCode Accept(Functor &functor) override
Interface for class functor visitation.
Fraction GetSameAsContentAlignmentDuration(const AlignMeterParams &params, bool notGraceOnly=true, data_NOTATIONTYPE notationType=NOTATIONTYPE_cmn) const
Return the duration if the content of the layer element with a @sameas attribute.
std::pair< int, bool > CalcElementHorizontalOverlap(const Doc *doc, const std::vector< LayerElement * > &otherElements, bool areDotsAdjusted, bool isChordElement, bool isLowerElement=false, bool unison=true)
Calculate note horizontal overlap with elemenents from another layers.
int m_drawingXRel
The X drawing relative position of the object.
Definition: layerelement.h:420
virtual data_STEMMODIFIER GetDrawingStemMod() const
Get the stem mod for the element (if any)
FTrem * GetAncestorFTrem()
Return the FTrem parten if the element is a note or a chord within a fTrem.
void Reset() override
Virtual reset method.
bool IsInLigature() const
Return true if the element is a note within a ligature.
Alignment * m_graceAlignment
An alignment for grace notes.
Definition: layerelement.h:403
virtual bool IsScoreDefElement() const
Return true if the element is part of a scoreDef or staffDef.
Definition: layerelement.h:91
MapOfDotLocs CalcOptimalDotLocations()
Calculate the optimal dot location for a note or chord Takes two layers into account in order to avoi...
Beam * GetAncestorBeam()
Return the beam parent if in beam Look if the note or rest is in a beam.
int m_drawingFacsX
Absolute position X.
Definition: layerelement.h:388
virtual bool HasCrossStaff() const
Return true if cross-staff is set.
Definition: layerelement.h:314
void CenterDrawingX()
Adjust the m_drawingYRel for the element to be centered on the inner content of the measure.
virtual bool IsRelativeToStaff() const
Return true if the element is relative to the staff and not to its parent.
Definition: layerelement.h:97
bool m_drawingCueSize
The cached drawing cue size set by PrepareCueSizeFunctor.
Definition: layerelement.h:430
std::vector< int > GetElementsInUnison(const std::set< int > &firstChord, const std::set< int > &secondChord, data_STEMDIRECTION stemDirection) const
Helper to figure whether two chords are in fully in unison based on the locations of the notes.
void GetOverflowStaffAlignments(StaffAlignment *&above, StaffAlignment *&below)
Get the StaffAlignment for which overflows need to be calculated against.
bool IsGraceNote() const
Return true if the element is a grace note.
Alignment * GetAlignment()
Alignment setter and getter.
Definition: layerelement.h:214
data_STAFFREL_basic GetCrossStaffRel() const
Retrieve the direction of a cross-staff situation.
int m_cachedYRel
The cached value for m_drawingYRel for caching horizontal layout.
Definition: layerelement.h:414
LayerElement * ThisOrSameasLink()
Return itself or the resolved @sameas (if any)
virtual MapOfNoteLocs CalcNoteLocations(NotePredicate=NULL) const
The note locations w.r.t.
Definition: layerelement.h:354
Staff * GetCrossStaff(Layer *&layer)
Look for a cross or a a parent LayerElement (note, chord, rest) with a cross staff.
static int GetDotCount(const MapOfDotLocs &dotLocations)
Helper to count the number of dots This can be used as an indicator to choose between different sets ...
virtual int AdjustOverlappingLayers(const Doc *doc, const std::vector< LayerElement * > &otherElements, bool areDotsAdjusted, bool &isUnison, bool &stemSameAs)
Helper to adjust overlapping layers for notes, chords, stems, etc.
virtual MapOfDotLocs CalcDotLocations(int, bool) const
The dot locations w.r.t.
Definition: layerelement.h:361
Fraction GetAlignmentDuration(bool notGraceOnly=true, data_NOTATIONTYPE notationType=NOTATIONTYPE_cmn) const
Return the duration if the element has a DurationInterface.
int GetDrawingRadius(const Doc *doc, bool isInLigature=false) const
Return the drawing radius for notes and chords.
Staff * m_crossStaff
This stores a pointer to the cross-staff (if any) and the appropriate layer See PrepareCrossStaffFunc...
Definition: layerelement.h:394
char32_t StemModToGlyph(data_STEMMODIFIER stemMod) const
Convert stem mode to corresponding glyph code.
Fraction GetAlignmentDuration(const AlignMeterParams &params, bool notGraceOnly=true, data_NOTATIONTYPE notationType=NOTATIONTYPE_cmn) const
Return the duration if the element has a DurationInterface.
static int GetCollisionCount(const MapOfDotLocs &dotLocs1, const MapOfDotLocs &dotLocs2)
Helper to count the collisions between two sets of dots.
This class represents a layer in a laid-out score (Doc).
Definition: layer.h:39
This class is an interface for elements having a link It is not an abstract class but should not be i...
Definition: linkinginterface.h:31
This class represents a basic object.
Definition: object.h:61
This class stores an alignement position staves will point to.
Definition: verticalaligner.h:172
This class represents a staff in a laid-out score (Doc).
Definition: staff.h:107
Regroup pointers to meterSig, mensur and proport objects.
Definition: alignfunctor.h:21