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 Alignment;
16 class AttSpacing;
17 class FloatingObject;
18 class LyricElement;
19 class ScoreDef;
20 class StaffAlignment;
21 class StaffDef;
22 class System;
23 class SystemAligner;
24 
25 //----------------------------------------------------------------------------
26 // SystemAligner
27 //----------------------------------------------------------------------------
28 
33 class SystemAligner : public Object {
34 public:
38  enum class SpacingType { System, Staff, Brace, Bracket, Ossia, None };
39 
40  // constructors and destructors
41  SystemAligner();
42  virtual ~SystemAligner();
43 
47  bool IsSupportedChild(ClassId classId) override;
48 
52  bool CopyChildren() const override { return false; }
53 
57  void Reset() override;
58 
64  StaffAlignment *GetBottomAlignment() { return m_bottomAlignment; }
65  const StaffAlignment *GetBottomAlignment() const { return m_bottomAlignment; }
67 
75  StaffAlignment *GetStaffAlignment(int idx, Staff *staff, const Doc *doc);
76 
82  void ReorderBy(const std::vector<int> &staffNs);
83 
89 
96  const StaffAlignment *GetStaffAlignmentForStaffN(int staffN) const;
98 
104 
108  void FindAllPositionerPointingTo(ArrayOfFloatingPositioners *positioners, const FloatingObject *object);
109 
114  SegmentedLine &line, const BoundingBox &boundingBox, const std::vector<ClassId> &classIds, int margin) const;
118  int GetOverflowAbove(const Doc *doc, bool scoreDefClef = false) const;
119  int GetOverflowBelow(const Doc *doc, bool scoreDefClef = false) const;
120 
124  double GetJustificationSum(const Doc *doc) const;
125 
129  void SetSpacing(const ScoreDef *scoreDef);
130 
131  //----------//
132  // Functors //
133  //----------//
134 
139  FunctorCode Accept(Functor &functor) override;
140  FunctorCode Accept(ConstFunctor &functor) const override;
141  FunctorCode AcceptEnd(Functor &functor) override;
142  FunctorCode AcceptEnd(ConstFunctor &functor) const override;
144 
145 private:
150  SpacingType GetAboveSpacingType(const Staff *staff);
154  SpacingType CalculateSpacingAbove(const StaffDef *staffDef) const;
155 
156 public:
157  //
158 private:
162  StaffAlignment *m_bottomAlignment;
166  std::map<int, SpacingType> m_spacingTypes;
170  System *m_system;
171 };
172 
173 //----------------------------------------------------------------------------
174 // StaffAlignment
175 //----------------------------------------------------------------------------
176 
180 class StaffAlignment : public Object {
181 public:
187  StaffAlignment();
188  virtual ~StaffAlignment();
190 
194  void SetYRel(int yRel);
195  int GetYRel() const { return m_yRel; }
196 
206  void AddLyricElement(const LyricElement *lyricElement);
207  void AddVerseN(int verseN, data_STAFFREL place, int lineCount = 1);
208  int GetVerseCount(bool collapse) const;
209  int GetVerseCountAbove(bool collapse) const;
210  int GetVerseCountBelow(bool collapse) const;
211  int GetVersePositionAbove(int verseN, bool collapse, int lineN = 1) const;
212  int GetVersePositionBelow(int verseN, bool collapse, int lineN = 1) const;
214 
220  void ShareLyricsWithPrevious(StaffAlignment *previous);
221  const StaffAlignment *GetSharedLyricsAlignment() const { return m_sharedLyricsAlignment; }
223 
227  void SetCurrentFloatingPositioner(FloatingObject *object, Object *objectX, Object *objectY, char spanningType);
228 
232  const ArrayOfFloatingPositioners &GetFloatingPositioners() { return m_floatingPositioners; }
233 
240  const FloatingPositioner *FindFirstFloatingPositioner(ClassId classId) const;
242 
246  ArrayOfFloatingPositioners FindAllFloatingPositioners(ClassId classId);
247 
256 
262  Staff *GetStaff() { return m_staff; }
263  const Staff *GetStaff() const { return m_staff; }
264  void SetStaff(Staff *staff, const Doc *doc, SystemAligner::SpacingType spacingType);
266 
271  System *GetParentSystem() { return m_system; }
272  const System *GetParentSystem() const { return m_system; }
273  void SetParentSystem(System *system);
275 
279  int GetStaffSize() const;
280 
284  const AttSpacing *GetAttSpacing() const;
285 
292  int CalcOverflowAbove(const BoundingBox *box) const;
293  int CalcOverflowBelow(const BoundingBox *box) const;
295 
300  int GetMinimumSpacing(const Doc *doc) const;
301  int CalcMinimumRequiredSpacing(const Doc *doc) const;
302  SystemAligner::SpacingType GetSpacingType() const { return m_spacingType; }
304 
309  void SetOverflowAbove(int overflowAbove);
310  int GetOverflowAbove() const { return m_overflowAbove; }
311  void SetOverflowBelow(int overflowBottom);
312  int GetOverflowBelow() const { return m_overflowBelow; }
313  void SetOverlap(int overlap);
314  int GetOverlap() const { return m_overlap; }
315  void SetRequestedSpaceAbove(int space);
316  int GetRequestedSpaceAbove() const { return m_requestedSpaceAbove; }
317  void SetRequestedSpaceBelow(int space);
318  int GetRequestedSpaceBelow() const { return m_requestedSpaceBelow; }
319  void SetRequestedSpacing(int spacing) { m_requestedSpacing = spacing; }
320  int GetRequestedSpacing() const { return m_requestedSpacing; }
321  int GetStaffHeight() const { return m_staffHeight; }
322  void SetScoreDefClefOverflowAbove(int overflowAbove) { m_scoreDefClefOverflowAbove = overflowAbove; }
323  int GetScoreDefClefOverflowAbove() const { return m_scoreDefClefOverflowAbove; }
324  void SetScoreDefClefOverflowBelow(int overflowBelow) { m_scoreDefClefOverflowBelow = overflowBelow; }
325  int GetScoreDefClefOverflowBelow() const { return m_scoreDefClefOverflowBelow; }
327 
332  double GetJustificationFactor(const Doc *doc) const;
334 
339  void AddBBoxAbove(BoundingBox *box) { m_overflowAboveBBoxes.push_back(box); }
340  void AddBBoxBelow(BoundingBox *box) { m_overflowBelowBBoxes.push_back(box); }
341  void ClearBBoxesAbove() { m_overflowAboveBBoxes.clear(); }
342  void ClearBBoxesBelow() { m_overflowBelowBBoxes.clear(); }
343  ArrayOfBoundingBoxes &GetBBoxesAboveForModification() { return m_overflowAboveBBoxes; }
344  ArrayOfBoundingBoxes &GetBBoxesBelowForModification() { return m_overflowBelowBBoxes; }
345  const ArrayOfBoundingBoxes &GetBBoxesAbove() { return m_overflowAboveBBoxes; }
346  const ArrayOfBoundingBoxes &GetBBoxesBelow() { return m_overflowBelowBBoxes; }
348 
353 
358 
363  SegmentedLine &line, const BoundingBox &boundingBox, const std::vector<ClassId> &classIds, int margin) const;
364 
368  void AdjustBracketGroupSpacing(const Doc *doc, const StaffAlignment *previous, int spacing);
369 
370  //----------//
371  // Functors //
372  //----------//
373 
378  FunctorCode Accept(Functor &functor) override;
379  FunctorCode Accept(ConstFunctor &functor) const override;
380  FunctorCode AcceptEnd(Functor &functor) override;
381  FunctorCode AcceptEnd(ConstFunctor &functor) const override;
383 
384 private:
388  int GetMinimumStaffSpacing(const Doc *doc, const AttSpacing *attSpacing) const;
389 
393  bool IsInBracketGroup(bool isFirst) const;
394 
395 public:
396  //
397 private:
401  SystemAligner::SpacingType m_spacingType = SystemAligner::SpacingType::None;
402 
406  ArrayOfFloatingPositioners m_floatingPositioners;
410  bool m_floatingPositionersSorted;
415  Staff *m_staff;
420  System *m_system;
424  int m_yRel;
428  std::map<int, int> m_verseAboveNs;
429  std::map<int, int> m_verseBelowNs;
433  std::vector<std::pair<int, const Alignment *>> m_lyricPositionsAbove;
434  std::vector<std::pair<int, const Alignment *>> m_lyricPositionsBelow;
438  const StaffAlignment *m_sharedLyricsAlignment;
439 
444  int m_overflowAbove;
445  int m_overflowBelow;
446  int m_overlap;
447  int m_requestedSpaceAbove;
448  int m_requestedSpaceBelow;
449  int m_requestedSpacing;
450  int m_staffHeight;
451  int m_scoreDefClefOverflowAbove;
452  int m_scoreDefClefOverflowBelow;
454 
458  ArrayOfBoundingBoxes m_overflowAboveBBoxes;
459  ArrayOfBoundingBoxes m_overflowBelowBBoxes;
460 };
461 
462 } // namespace vrv
463 
464 #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:180
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:232
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:33
SpacingType
Declares different spacing types between staves.
Definition: verticalaligner.h:38
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)
void ShareLyricLines()
Merge the verses above a staff into the verses below the previous staff when both have lyrics.
StaffAlignment * GetBottomAlignment()
Get bottom StaffAlignment for the system.
Definition: verticalaligner.h:64
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:52
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