Verovio
Source code documentation
verticalaligner.h
1 // Name: verticalaligner.h
3 // Author: Laurent Pugin
4 // Created: 2013
5 // Copyright (c) Authors and others. All rights reserved.
7 
8 #ifndef __VRV_VERTICAL_ALIGNER_H__
9 #define __VRV_VERTICAL_ALIGNER_H__
10 
11 #include "object.h"
12 
13 namespace vrv {
14 
15 class AttSpacing;
16 class FloatingObject;
17 class LyricElement;
18 class ScoreDef;
19 class StaffAlignment;
20 class StaffDef;
21 class System;
22 class SystemAligner;
23 
24 //----------------------------------------------------------------------------
25 // SystemAligner
26 //----------------------------------------------------------------------------
27 
32 class SystemAligner : public Object {
33 public:
37  enum class SpacingType { System, Staff, Brace, Bracket, Ossia, None };
38 
39  // constructors and destructors
40  SystemAligner();
41  virtual ~SystemAligner();
42 
46  bool IsSupportedChild(ClassId classId) override;
47 
51  bool CopyChildren() const override { return false; }
52 
56  void Reset() override;
57 
63  StaffAlignment *GetBottomAlignment() { return m_bottomAlignment; }
64  const StaffAlignment *GetBottomAlignment() const { return m_bottomAlignment; }
66 
74  StaffAlignment *GetStaffAlignment(int idx, Staff *staff, const Doc *doc);
75 
81  void ReorderBy(const std::vector<int> &staffNs);
82 
89  const StaffAlignment *GetStaffAlignmentForStaffN(int staffN) const;
91 
97 
101  void FindAllPositionerPointingTo(ArrayOfFloatingPositioners *positioners, const FloatingObject *object);
102 
107  SegmentedLine &line, const BoundingBox &boundingBox, const std::vector<ClassId> &classIds, int margin) const;
111  int GetOverflowAbove(const Doc *doc, bool scoreDefClef = false) const;
112  int GetOverflowBelow(const Doc *doc, bool scoreDefClef = false) const;
113 
117  double GetJustificationSum(const Doc *doc) const;
118 
122  void SetSpacing(const ScoreDef *scoreDef);
123 
124  //----------//
125  // Functors //
126  //----------//
127 
132  FunctorCode Accept(Functor &functor) override;
133  FunctorCode Accept(ConstFunctor &functor) const override;
134  FunctorCode AcceptEnd(Functor &functor) override;
135  FunctorCode AcceptEnd(ConstFunctor &functor) const override;
137 
138 private:
143  SpacingType GetAboveSpacingType(const Staff *staff);
147  SpacingType CalculateSpacingAbove(const StaffDef *staffDef) const;
148 
149 public:
150  //
151 private:
155  StaffAlignment *m_bottomAlignment;
159  std::map<int, SpacingType> m_spacingTypes;
163  System *m_system;
164 };
165 
166 //----------------------------------------------------------------------------
167 // StaffAlignment
168 //----------------------------------------------------------------------------
169 
173 class StaffAlignment : public Object {
174 public:
180  StaffAlignment();
181  virtual ~StaffAlignment();
183 
187  void SetYRel(int yRel);
188  int GetYRel() const { return m_yRel; }
189 
199  void AddLyricElement(const LyricElement *lyricElement);
200  void AddVerseN(int verseN, data_STAFFREL place, int lineCount = 1);
201  int GetVerseCount(bool collapse) const;
202  int GetVerseCountAbove(bool collapse) const;
203  int GetVerseCountBelow(bool collapse) const;
204  int GetVersePositionAbove(int verseN, bool collapse, int lineN = 1) const;
205  int GetVersePositionBelow(int verseN, bool collapse, int lineN = 1) const;
207 
211  void SetCurrentFloatingPositioner(FloatingObject *object, Object *objectX, Object *objectY, char spanningType);
212 
216  const ArrayOfFloatingPositioners &GetFloatingPositioners() { return m_floatingPositioners; }
217 
224  const FloatingPositioner *FindFirstFloatingPositioner(ClassId classId) const;
226 
230  ArrayOfFloatingPositioners FindAllFloatingPositioners(ClassId classId);
231 
240 
246  Staff *GetStaff() { return m_staff; }
247  const Staff *GetStaff() const { return m_staff; }
248  void SetStaff(Staff *staff, const Doc *doc, SystemAligner::SpacingType spacingType);
250 
255  System *GetParentSystem() { return m_system; }
256  const System *GetParentSystem() const { return m_system; }
257  void SetParentSystem(System *system);
259 
263  int GetStaffSize() const;
264 
268  const AttSpacing *GetAttSpacing() const;
269 
276  int CalcOverflowAbove(const BoundingBox *box) const;
277  int CalcOverflowBelow(const BoundingBox *box) const;
279 
284  int GetMinimumSpacing(const Doc *doc) const;
285  int CalcMinimumRequiredSpacing(const Doc *doc) const;
286  SystemAligner::SpacingType GetSpacingType() const { return m_spacingType; }
288 
293  void SetOverflowAbove(int overflowAbove);
294  int GetOverflowAbove() const { return m_overflowAbove; }
295  void SetOverflowBelow(int overflowBottom);
296  int GetOverflowBelow() const { return m_overflowBelow; }
297  void SetOverlap(int overlap);
298  int GetOverlap() const { return m_overlap; }
299  void SetRequestedSpaceAbove(int space);
300  int GetRequestedSpaceAbove() const { return m_requestedSpaceAbove; }
301  void SetRequestedSpaceBelow(int space);
302  int GetRequestedSpaceBelow() const { return m_requestedSpaceBelow; }
303  void SetRequestedSpacing(int spacing) { m_requestedSpacing = spacing; }
304  int GetRequestedSpacing() const { return m_requestedSpacing; }
305  int GetStaffHeight() const { return m_staffHeight; }
306  void SetScoreDefClefOverflowAbove(int overflowAbove) { m_scoreDefClefOverflowAbove = overflowAbove; }
307  int GetScoreDefClefOverflowAbove() const { return m_scoreDefClefOverflowAbove; }
308  void SetScoreDefClefOverflowBelow(int overflowBelow) { m_scoreDefClefOverflowBelow = overflowBelow; }
309  int GetScoreDefClefOverflowBelow() const { return m_scoreDefClefOverflowBelow; }
311 
316  double GetJustificationFactor(const Doc *doc) const;
318 
323  void AddBBoxAbove(BoundingBox *box) { m_overflowAboveBBoxes.push_back(box); }
324  void AddBBoxBelow(BoundingBox *box) { m_overflowBelowBBoxes.push_back(box); }
325  void ClearBBoxesAbove() { m_overflowAboveBBoxes.clear(); }
326  void ClearBBoxesBelow() { m_overflowBelowBBoxes.clear(); }
327  ArrayOfBoundingBoxes &GetBBoxesAboveForModification() { return m_overflowAboveBBoxes; }
328  ArrayOfBoundingBoxes &GetBBoxesBelowForModification() { return m_overflowBelowBBoxes; }
329  const ArrayOfBoundingBoxes &GetBBoxesAbove() { return m_overflowAboveBBoxes; }
330  const ArrayOfBoundingBoxes &GetBBoxesBelow() { return m_overflowBelowBBoxes; }
332 
337 
342 
347  SegmentedLine &line, const BoundingBox &boundingBox, const std::vector<ClassId> &classIds, int margin) const;
348 
352  void AdjustBracketGroupSpacing(const Doc *doc, const StaffAlignment *previous, int spacing);
353 
354  //----------//
355  // Functors //
356  //----------//
357 
362  FunctorCode Accept(Functor &functor) override;
363  FunctorCode Accept(ConstFunctor &functor) const override;
364  FunctorCode AcceptEnd(Functor &functor) override;
365  FunctorCode AcceptEnd(ConstFunctor &functor) const override;
367 
368 private:
372  int GetMinimumStaffSpacing(const Doc *doc, const AttSpacing *attSpacing) const;
373 
377  bool IsInBracketGroup(bool isFirst) const;
378 
379 public:
380  //
381 private:
385  SystemAligner::SpacingType m_spacingType = SystemAligner::SpacingType::None;
386 
390  ArrayOfFloatingPositioners m_floatingPositioners;
394  bool m_floatingPositionersSorted;
399  Staff *m_staff;
404  System *m_system;
408  int m_yRel;
412  std::map<int, int> m_verseAboveNs;
413  std::map<int, int> m_verseBelowNs;
414 
419  int m_overflowAbove;
420  int m_overflowBelow;
421  int m_overlap;
422  int m_requestedSpaceAbove;
423  int m_requestedSpaceBelow;
424  int m_requestedSpacing;
425  int m_staffHeight;
426  int m_scoreDefClefOverflowAbove;
427  int m_scoreDefClefOverflowBelow;
429 
433  ArrayOfBoundingBoxes m_overflowAboveBBoxes;
434  ArrayOfBoundingBoxes m_overflowBelowBBoxes;
435 };
436 
437 } // namespace vrv
438 
439 #endif
This class represents a basic object in the layout domain.
Definition: boundingbox.h:32
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 represents elements appearing within a measure.
Definition: floatingobject.h:28
This class represents a basic object in the layout domain.
Definition: floatingobject.h:165
This abstract class is the base class for all mutable functors.
Definition: functor.h:101
Shared implementation for note-attached verse and refrain lyrics.
Definition: lyricelement.h:33
This class represents a basic object.
Definition: object.h:66
This class represents an ossia.
Definition: ossia.h:28
This class represents a MEI scoreDef.
Definition: scoredef.h:136
Definition: boundingbox.h:340
This class stores an alignement position staves will point to.
Definition: verticalaligner.h:173
void SetCurrentFloatingPositioner(FloatingObject *object, Object *objectX, Object *objectY, char spanningType)
Retrieves or creates the FloatingPositioner for the FloatingObject on this staff.
ArrayOfFloatingPositioners FindAllFloatingPositioners(ClassId classId)
Find all FloatingPositioner corresponding to a FloatingObject with given ClassId.
FunctorCode Accept(Functor &functor) override
Interface for class functor visitation.
int GetStaffSize() const
Returns the staff size (100 if no staff object is refered to)
const AttSpacing * GetAttSpacing() const
Returns the spacing attribute object of correspond ScoreDef.
void ClearPositioners()
Deletes all the FloatingPositioner objects.
void FindAllIntersectionPoints(SegmentedLine &line, const BoundingBox &boundingBox, const std::vector< ClassId > &classIds, int margin) const
Find all the intersection points with a vertical line (top to bottom)
FloatingPositioner * GetCorrespFloatingPositioner(const FloatingObject *object)
Look for the FloatingPositioner corresponding to the FloatingObject.
const ArrayOfFloatingPositioners & GetFloatingPositioners()
Retrieve all FloatingPositioner.
Definition: verticalaligner.h:216
void AdjustBracketGroupSpacing(const Doc *doc, const StaffAlignment *previous, int spacing)
Find overflow for the alignments taking bracket group elements into account.
void SortPositioners()
Sort the FloatingPositioner objects.
FloatingPositioner * FindFirstFloatingPositioner(ClassId classId)
Look for the first FloatingPositioner corresponding to the FloatingObject of the ClassId.
This class represents a MEI staffDef.
Definition: staffdef.h:37
This class represents a staff in a laid-out score (Doc).
Definition: staff.h:110
This class aligns the content of a system It contains a vector of StaffAlignment.
Definition: verticalaligner.h:32
SpacingType
Declares different spacing types between staves.
Definition: verticalaligner.h:37
void SetSpacing(const ScoreDef *scoreDef)
Calculates and sets spacing for specified ScoreDef.
FunctorCode Accept(Functor &functor) override
Interface for class functor visitation.
double GetJustificationSum(const Doc *doc) const
Get justification sum.
void ReorderBy(const std::vector< int > &staffNs)
Reorder the staff alignment as given in the staffNs.
StaffAlignment * GetStaffAlignmentForStaffN(int staffN)
Get the StaffAlignment for the staffN.
System * GetSystem()
Get pointer to the parent system.
StaffAlignment * GetStaffAlignment(int idx, Staff *staff, const Doc *doc)
Get the StaffAlignment at index idx.
void Reset() override
Reset the aligner (clear the content) and creates the end (bottom) alignement.
int GetOverflowAbove(const Doc *doc, bool scoreDefClef=false) const
Get System Overflows.
void FindAllIntersectionPoints(SegmentedLine &line, const BoundingBox &boundingBox, const std::vector< ClassId > &classIds, int margin) const
Find all the intersection points with a vertical line (top to bottom)
StaffAlignment * GetBottomAlignment()
Get bottom StaffAlignment for the system.
Definition: verticalaligner.h:63
void FindAllPositionerPointingTo(ArrayOfFloatingPositioners *positioners, const FloatingObject *object)
Find all the positioners pointing to an object;.
bool CopyChildren() const override
Do not copy children for HorizontalAligner.
Definition: verticalaligner.h:51
bool IsSupportedChild(ClassId classId) override
Override the method of adding AlignmentReference children.
This class represents a system in a laid-out score (Doc).
Definition: system.h:36