Verovio
Source code documentation
measure.h
1 // Name: measure.h
3 // Author: Laurent Pugin
4 // Created: 2012
5 // Copyright (c) Authors and others. All rights reserved.
7 
8 #ifndef __VRV_MEASURE_H__
9 #define __VRV_MEASURE_H__
10 
11 #include "atts_cmn.h"
12 #include "atts_shared.h"
13 #include "barline.h"
14 #include "facsimileinterface.h"
15 #include "horizontalaligner.h"
16 #include "object.h"
17 
18 namespace vrv {
19 
20 class ControlElement;
21 class Ending;
22 class LayerElement;
23 class ScoreDef;
24 class System;
25 class TimestampAttr;
26 
27 //----------------------------------------------------------------------------
28 // Measure
29 //----------------------------------------------------------------------------
30 
37 class Measure : public Object,
38  public FacsimileInterface,
39  public AttBarring,
40  public AttCoordX1,
41  public AttCoordX2,
42  public AttMeasureLog,
43  public AttMeterConformanceBar,
44  public AttNNumberLike,
45  public AttPointing,
46  public AttTyped {
47 private:
48  using BarlineRenditionPair = std::pair<data_BARRENDITION, data_BARRENDITION>;
49 
50 public:
56  Measure(MeasureType measuredMusic = MEASURED, int logMeasureNb = -1);
57  virtual ~Measure();
58  Object *Clone() const override { return new Measure(*this); };
59  void Reset() override;
60  std::string GetClassName() const override { return "measure"; }
62 
66  void CloneReset() override;
67 
72  FacsimileInterface *GetFacsimileInterface() override { return vrv_cast<FacsimileInterface *>(this); }
73  const FacsimileInterface *GetFacsimileInterface() const override
74  {
75  return vrv_cast<const FacsimileInterface *>(this);
76  }
78 
82  bool IsMeasuredMusic() const { return (m_measureType == MEASURED); }
83 
87  bool IsNeumeLine() const { return (m_measureType == NEUMELINE); }
88 
93  int GetIndex() const { return m_index; }
94  void SetIndex(int index) { m_index = index; }
96 
100  bool IsSupportedChild(ClassId classId) override;
101 
105  bool AddChildAdditionalCheck(Object *child) override;
106 
110  void AddChildBack(Object *object);
111 
115  bool HasCachedHorizontalLayout() const { return (m_cachedWidth != VRV_UNSET); }
116 
120  int GetDrawingX() const override;
121 
125  void ResetCachedDrawingX() const override;
126 
131  int GetDrawingXRel() const { return m_drawingXRel; }
132  void SetDrawingXRel(int drawingXRel);
133  void CacheXRel(bool restore = false);
134  int GetCachedXRel() const { return m_cachedXRel; }
135  void ResetCachedXRel() { m_cachedXRel = VRV_UNSET; }
137 
142  bool IsFirstInSystem() const;
143  bool IsLastInSystem() const;
145 
149  int GetMeasureIdx() const { return Object::GetIdx(); }
150 
161  data_BARRENDITION GetDrawingLeftBarLine() const { return m_leftBarLine.GetForm(); }
162  void SetDrawingLeftBarLine(data_BARRENDITION type) { m_leftBarLine.SetForm(type); }
163  data_BARRENDITION GetDrawingRightBarLine() const { return m_rightBarLine.GetForm(); }
164  void SetDrawingRightBarLine(data_BARRENDITION type) { m_rightBarLine.SetForm(type); }
165  data_BARRENDITION GetDrawingLeftBarLineByStaffN(int staffN) const;
166  data_BARRENDITION GetDrawingRightBarLineByStaffN(int staffN) const;
168 
172  bool HasInvisibleStaffBarlines() const { return !m_invisibleStaffBarlines.empty(); }
173 
178  BarlineRenditionPair SelectDrawingBarLines(const Measure *previous) const;
179 
184  void SetDrawingBarLines(Measure *previous, int barlineDrawingFlags);
185 
191  Measure *previous, ListOfObjects &currentInvisible, ListOfObjects &previousInvisible, int barlineDrawingFlags);
192 
200  BarLine *GetLeftBarLine() { return &m_leftBarLine; }
201  const BarLine *GetLeftBarLine() const { return &m_leftBarLine; }
202  BarLine *GetRightBarLine() { return &m_rightBarLine; }
203  const BarLine *GetRightBarLine() const { return &m_rightBarLine; }
205 
209  int GetNonJustifiableLeftMargin() const { return m_measureAligner.GetNonJustifiableMargin(); }
210 
215  int GetLeftBarLineXRel() const;
216  int GetLeftBarLineLeft() const;
217  int GetLeftBarLineRight() const;
218  int GetRightBarLineXRel() const;
219  int GetRightBarLineLeft() const;
220  int GetRightBarLineRight() const;
222 
226  int CalculateRightBarLineWidth(const Doc *doc, int staffSize) const;
227 
231  int GetWidth() const;
232 
236  int GetInnerWidth() const;
237 
241  int GetInnerCenterX() const;
242 
247  int GetCachedWidth() const { return m_cachedWidth; }
248  int GetCachedOverflow() const { return m_cachedOverflow; }
249  void ResetCachedWidth() { m_cachedWidth = VRV_UNSET; }
250  void ResetCachedOverflow() { m_cachedOverflow = VRV_UNSET; }
252 
258 
262  int GetSectionRestartShift(const Doc *doc) const;
263 
268  ScoreDef *GetDrawingScoreDef() { return m_drawingScoreDef; }
269  const ScoreDef *GetDrawingScoreDef() const { return m_drawingScoreDef; }
270  void SetDrawingScoreDef(ScoreDef *drawingScoreDef);
271  void ResetDrawingScoreDef();
273 
278  Ending *GetDrawingEnding() { return m_drawingEnding; }
279  const Ending *GetDrawingEnding() const { return m_drawingEnding; }
280  void SetDrawingEnding(Ending *ending) { m_drawingEnding = ending; }
282 
288  bool HasAlignmentRefWithMultipleLayers() const { return m_hasAlignmentRefWithMultipleLayers; }
289  void HasAlignmentRefWithMultipleLayers(bool hasRef) { m_hasAlignmentRefWithMultipleLayers = hasRef; }
291 
292  /*
293  * Return the first staff of each staffGrp according to the scoreDef
294  */
295  std::vector<Staff *> GetFirstStaffGrpStaves(ScoreDef *scoreDef);
296 
303  const Staff *GetBottomVisibleStaff() const;
305 
310  int EnclosesTime(int time) const;
311 
316  Fraction GetScoreTimeOnset(int repeat = VRV_UNSET) const;
317  double GetRealTimeOnsetMilliseconds(int repeat = VRV_UNSET) const;
318  Fraction GetScoreTimeOffset(int repeat = VRV_UNSET) const;
319  double GetRealTimeOffsetMilliseconds(int repeat = VRV_UNSET) const;
321 
326  void ClearScoreTimeOnset() { m_scoreTimeOnset.clear(); }
327  void AddScoreTimeOnset(Fraction offset) { m_scoreTimeOnset.push_back(offset); }
328  void ClearRealTimeOnsetMilliseconds() { m_realTimeOnsetMilliseconds.clear(); }
329  void AddRealTimeOnsetMilliseconds(double milliseconds) { m_realTimeOnsetMilliseconds.push_back(milliseconds); }
330  void ClearScoreTimeOffset() { m_scoreTimeOffset.clear(); }
331  void AddScoreTimeOffset(Fraction offset) { m_scoreTimeOffset.push_back(offset); }
332  void ClearRealTimeOffsetMilliseconds() { m_realTimeOffsetMilliseconds.clear(); }
333  void AddRealTimeOffsetMilliseconds(double milliseconds) { m_realTimeOffsetMilliseconds.push_back(milliseconds); }
335 
340  void SetCurrentTempo(double tempo) { m_currentTempo = tempo; }
341  double GetCurrentTempo() const { return m_currentTempo; }
343 
347  std::vector<std::pair<LayerElement *, LayerElement *>> GetInternalTieEndpoints();
348 
349  //----------//
350  // Functors //
351  //----------//
352 
357  FunctorCode Accept(Functor &functor) override;
358  FunctorCode Accept(ConstFunctor &functor) const override;
359  FunctorCode AcceptEnd(Functor &functor) override;
360  FunctorCode AcceptEnd(ConstFunctor &functor) const override;
362 
363 public:
364  // flags for drawing measure barline based on visibility or other conditions
365  enum BarlineDrawingFlags {
366  SYSTEM_BREAK = 0x1,
367  SCORE_DEF_INSERT = 0x2,
368  INVISIBLE_MEASURE_CURRENT = 0x4,
369  INVISIBLE_MEASURE_PREVIOUS = 0x8
370  };
377  int m_drawingFacsX2;
379 
384 
385  TimestampAligner m_timestampAligner;
386 
387 protected:
393 
398 
403  int m_cachedOverflow;
404  int m_cachedWidth;
406 
407 private:
412  MeasureType m_measureType;
413 
417  int m_index;
418 
423  BarLine m_leftBarLine;
424  BarLine m_rightBarLine;
426 
432  ScoreDef *m_drawingScoreDef;
433 
438  Ending *m_drawingEnding;
439 
443  bool m_hasAlignmentRefWithMultipleLayers;
444 
449  std::vector<Fraction> m_scoreTimeOnset;
450  std::vector<double> m_realTimeOnsetMilliseconds;
451  std::vector<Fraction> m_scoreTimeOffset;
452  std::vector<double> m_realTimeOffsetMilliseconds;
453  double m_currentTempo;
454 
455  std::map<int, BarlineRenditionPair> m_invisibleStaffBarlines;
456 };
457 
458 } // namespace vrv
459 
460 #endif
This class models the MEI <barLine> element.
Definition: barline.h:34
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 a MEI ending.
Definition: ending.h:33
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 aligns the content of a measure It contains a vector of Alignment.
Definition: horizontalaligner.h:425
This class represents a measure in a page-based score (Doc).
Definition: measure.h:46
int m_drawingXRel
The X relative position of the measure.
Definition: measure.h:392
int GetInnerCenterX() const
Return the center x of the inner of the measure.
bool AddChildAdditionalCheck(Object *child) override
Additional check when adding a child.
std::vector< std::pair< LayerElement *, LayerElement * > > GetInternalTieEndpoints()
Return vector with tie endpoints for ties that start and end in current measure.
bool IsSupportedChild(ClassId classId) override
Methods for adding allowed content.
int GetDrawingX() const override
Get the X drawing position.
MeasureAligner m_measureAligner
The measure aligner that holds the x positions of the content of the measure.
Definition: measure.h:383
int GetIndex() const
Get and set the measure index.
Definition: measure.h:93
Object * Clone() const override
Method call for copying child classes.
Definition: measure.h:58
void SetCurrentTempo(double tempo)
Setter and getter for the current tempo.
Definition: measure.h:340
int GetSectionRestartShift(const Doc *doc) const
Calculates the section restart shift.
int GetCachedWidth() const
Return and reset the cached width / overflow.
Definition: measure.h:247
int GetNonJustifiableLeftMargin() const
Return the non-justifiable left margin for the measure.
Definition: measure.h:209
bool IsMeasuredMusic() const
Return true if measured music (otherwise we have fake measures)
Definition: measure.h:82
int GetInnerWidth() const
Return the inner width of the measure.
int GetMeasureIdx() const
Return the index position of the measure in its system parent.
Definition: measure.h:149
bool HasCachedHorizontalLayout() const
Return true if the Measure has cached values for the horizontal layout.
Definition: measure.h:115
bool IsNeumeLine() const
Return true if the measure represents a neume (section) line.
Definition: measure.h:87
int m_cachedXRel
The cached value for m_drawingXRel for caching horizontal layout.
Definition: measure.h:397
int m_drawingFacsX1
The X absolute position of the measure for facsimile (transcription) encodings.
Definition: measure.h:376
int EnclosesTime(int time) const
Check if the measure encloses the given time (in millisecond) Return the playing repeat time (1-based...
int CalculateRightBarLineWidth(const Doc *doc, int staffSize) const
Return the width of the right barline based on the barline form.
void SetInvisibleStaffBarlines(Measure *previous, ListOfObjects &currentInvisible, ListOfObjects &previousInvisible, int barlineDrawingFlags)
Create mapping of original barline values to staves in the measure that are neighbored by invisible s...
Fraction GetScoreTimeOnset(int repeat=VRV_UNSET) const
Read-only access to onset and offset.
int GetDrawingOverflow()
Return the right overflow of the control events in the measure.
int GetWidth() const
Return the width of the measure, including the barLine width.
void ResetCachedDrawingX() const override
Reset the cached values of the drawingX values.
void Reset() override
Virtual reset method.
void ClearScoreTimeOnset()
Setter for the time offset.
Definition: measure.h:326
void SetDrawingBarLines(Measure *previous, int barlineDrawingFlags)
Set the drawing barlines for the measure.
bool HasInvisibleStaffBarlines() const
Return whether there is mapping of barline values to invisible staves present in measure.
Definition: measure.h:172
void CloneReset() override
Overriding CloneReset() method to be called after copy / assignment calls.
Staff * GetBottomVisibleStaff()
Return the bottom (last) visible staff in the measure (if any).
FunctorCode Accept(Functor &functor) override
Interface for class functor visitation.
BarlineRenditionPair SelectDrawingBarLines(const Measure *previous) const
Select drawing barlines based on the previous right and current left barlines (to avoid duplicated do...
void AddChildBack(Object *object)
Specific method for measures.
This class represents a basic object.
Definition: object.h:61
int GetIdx() const
Return the index position of the object in its parent (-1 if not found)
This class represents a MEI scoreDef.
Definition: scoredef.h:135
This class represents a staff in a laid-out score (Doc).
Definition: staff.h:107
This class stores the timestamps (TimestampsAttr) in a measure.
Definition: horizontalaligner.h:664