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  bool 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 GetStaffCount(bool excludeOStaves = true) const;
311  Staff *GetFirstStaff(bool excludeOStaves = true);
312  const Staff *GetFirstStaff(bool excludeOStaves = true) const;
313  Staff *GetLastStaff(bool excludeOStaves = true);
314  const Staff *GetLastStaff(bool excludeOStaves = true) const;
316 
321  int EnclosesTime(int time) const;
322 
327  Fraction GetScoreTimeOnset(int repeat = VRV_UNSET) const;
328  double GetRealTimeOnsetMilliseconds(int repeat = VRV_UNSET) const;
329  Fraction GetScoreTimeOffset(int repeat = VRV_UNSET) const;
330  double GetRealTimeOffsetMilliseconds(int repeat = VRV_UNSET) const;
332 
337  void ClearScoreTimeOnset() { m_scoreTimeOnset.clear(); }
338  void AddScoreTimeOnset(Fraction offset) { m_scoreTimeOnset.push_back(offset); }
339  void ClearRealTimeOnsetMilliseconds() { m_realTimeOnsetMilliseconds.clear(); }
340  void AddRealTimeOnsetMilliseconds(double milliseconds) { m_realTimeOnsetMilliseconds.push_back(milliseconds); }
341  void ClearScoreTimeOffset() { m_scoreTimeOffset.clear(); }
342  void AddScoreTimeOffset(Fraction offset) { m_scoreTimeOffset.push_back(offset); }
343  void ClearRealTimeOffsetMilliseconds() { m_realTimeOffsetMilliseconds.clear(); }
344  void AddRealTimeOffsetMilliseconds(double milliseconds) { m_realTimeOffsetMilliseconds.push_back(milliseconds); }
346 
351  void SetCurrentTempo(double tempo) { m_currentTempo = tempo; }
352  double GetCurrentTempo() const { return m_currentTempo; }
354 
358  std::vector<std::pair<LayerElement *, LayerElement *>> GetInternalTieEndpoints();
359 
360  //----------//
361  // Functors //
362  //----------//
363 
368  FunctorCode Accept(Functor &functor) override;
369  FunctorCode Accept(ConstFunctor &functor) const override;
370  FunctorCode AcceptEnd(Functor &functor) override;
371  FunctorCode AcceptEnd(ConstFunctor &functor) const override;
373 
374 public:
375  // flags for drawing measure barline based on visibility or other conditions
376  enum BarlineDrawingFlags {
377  SYSTEM_BREAK = 0x1,
378  SCORE_DEF_INSERT = 0x2,
379  INVISIBLE_MEASURE_CURRENT = 0x4,
380  INVISIBLE_MEASURE_PREVIOUS = 0x8
381  };
388  int m_drawingFacsX2;
390 
395 
396  TimestampAligner m_timestampAligner;
397 
398 protected:
404 
409 
414  int m_cachedOverflow;
415  int m_cachedWidth;
417 
418 private:
423  MeasureType m_measureType;
424 
428  int m_index;
429 
434  BarLine m_leftBarLine;
435  BarLine m_rightBarLine;
437 
443  ScoreDef *m_drawingScoreDef;
444 
449  Ending *m_drawingEnding;
450 
454  bool m_hasAlignmentRefWithMultipleLayers;
455 
460  std::vector<Fraction> m_scoreTimeOnset;
461  std::vector<double> m_realTimeOnsetMilliseconds;
462  std::vector<Fraction> m_scoreTimeOffset;
463  std::vector<double> m_realTimeOffsetMilliseconds;
464  double m_currentTempo;
465 
466  std::map<int, BarlineRenditionPair> m_invisibleStaffBarlines;
467 };
468 
469 } // namespace vrv
470 
471 #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:427
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:403
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 AddChildBack(Object *object)
Specific method for measures.
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:394
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:351
int GetStaffCount(bool excludeOStaves=true) const
Return the first or last staff taking into account ossias (or not).
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:408
int m_drawingFacsX1
The X absolute position of the measure for facsimile (transcription) encodings.
Definition: measure.h:387
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:337
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...
This class represents a basic object.
Definition: object.h:64
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:110
This class stores the timestamps (TimestampsAttr) in a measure.
Definition: horizontalaligner.h:666