Verovio
Source code documentation
staff.h
1 // Name: staff.h
3 // Author: Laurent Pugin
4 // Created: 2011
5 // Copyright (c) Authors and others. All rights reserved.
7 
8 #ifndef __VRV_STAFF_H__
9 #define __VRV_STAFF_H__
10 
11 #include "atts_shared.h"
12 #include "facsimileinterface.h"
13 #include "object.h"
14 
15 namespace vrv {
16 
17 class DeviceContext;
18 class Layer;
19 class LedgerLine;
20 class StaffAlignment;
21 class StaffDef;
22 class Syl;
23 class TimeSpanningInterface;
24 class Tuning;
25 
26 //----------------------------------------------------------------------------
27 // LedgerLine
28 //----------------------------------------------------------------------------
29 
35 class LedgerLine {
36 public:
40  LedgerLine() = default;
41 
46  void AddDash(int left, int right, int extension, const Object *event);
47 
48  class Dash {
49  public:
50  int m_x1;
51  int m_x2;
52  ListOfConstObjects m_events;
53 
54  // Constructor
55  Dash(int x1, int x2, const Object *object)
56  {
57  m_x1 = x1;
58  m_x2 = x2;
59  m_events.push_back(object);
60  }
61 
62  // Merge function to merge another Dash object into this one
63  void MergeWith(const Dash &other)
64  {
65  // Keep the first int from this Dash object, and the second int from the other
66  this->m_x1 = std::min(other.m_x1, this->m_x1);
67  this->m_x2 = std::max(other.m_x2, this->m_x2);
68  // Append the list from other to this
69  if (!other.m_events.empty()) {
70  this->m_events.insert(this->m_events.end(), other.m_events.begin(), other.m_events.end());
71  }
72  }
73  };
74 
75 protected:
76  //
77 private:
78  //
79 public:
83  // std::list<std::pair<int, int>> m_dashes;
84  std::list<Dash> m_dashes;
85 
86 protected:
87  //
88 private:
89  //
90 };
91 
92 //----------------------------------------------------------------------------
93 // Staff
94 //----------------------------------------------------------------------------
95 
102 class Staff : public Object,
103  public FacsimileInterface,
104  public AttCoordY1,
105  public AttNInteger,
106  public AttTyped,
107  public AttVisibility {
108 
109 public:
115  Staff(int n = 1);
116  virtual ~Staff();
117  Object *Clone() const override { return new Staff(*this); }
118  void Reset() override;
119  std::string GetClassName() const override { return "staff"; }
121 
125  void CloneReset() override;
126 
131  FacsimileInterface *GetFacsimileInterface() override { return vrv_cast<FacsimileInterface *>(this); }
132  const FacsimileInterface *GetFacsimileInterface() const override
133  {
134  return vrv_cast<const FacsimileInterface *>(this);
135  }
137 
143  void SetDrawingRotation(double drawingRotation) { m_drawingRotation = drawingRotation; }
144  double GetDrawingRotation() const { return m_drawingRotation; }
145  bool HasDrawingRotation() const { return (m_drawingRotation != 0.0); }
146  int GetDrawingRotationOffsetFor(int x);
148 
153 
158  bool IsSupportedChild(ClassId classId) override;
160 
164  bool AddChildAdditionalCheck(Object *child) override;
165 
170  int GetDrawingX() const override;
171  int GetDrawingY() const override;
172  virtual double GetDrawingRotate() const;
174 
179 
184 
189  bool DrawingIsVisible() const;
190 
195  bool IsMensural() const;
196  bool IsNeume() const;
197  bool IsTablature() const;
198  bool IsTabGuitar() const { return m_drawingNotationType == NOTATIONTYPE_tab_guitar; }
199  bool IsTabLuteFrench() const { return m_drawingNotationType == NOTATIONTYPE_tab_lute_french; }
200  bool IsTabLuteGerman() const { return m_drawingNotationType == NOTATIONTYPE_tab_lute_german; }
201  bool IsTabLuteItalian() const { return m_drawingNotationType == NOTATIONTYPE_tab_lute_italian; }
202  bool IsTabWithStemsOutside() const;
204 
208  int GetStaffIdx() const { return Object::GetIdx(); }
209 
213  int CalcPitchPosYRel(const Doc *doc, int loc) const;
214 
219  StaffAlignment *GetAlignment() { return m_staffAlignment; }
220  const StaffAlignment *GetAlignment() const { return m_staffAlignment; }
221  void SetAlignment(StaffAlignment *alignment) { m_staffAlignment = alignment; }
223 
228  ArrayOfLedgerLines &GetLedgerLinesAbove() { return m_ledgerLinesAbove; }
229  const ArrayOfLedgerLines &GetLedgerLinesAbove() const { return m_ledgerLinesAbove; }
230  ArrayOfLedgerLines &GetLedgerLinesAboveCue() { return m_ledgerLinesAboveCue; }
231  const ArrayOfLedgerLines &GetLedgerLinesAboveCue() const { return m_ledgerLinesAboveCue; }
232  ArrayOfLedgerLines &GetLedgerLinesBelow() { return m_ledgerLinesBelow; }
233  const ArrayOfLedgerLines &GetLedgerLinesBelow() const { return m_ledgerLinesBelow; }
234  ArrayOfLedgerLines &GetLedgerLinesBelowCue() { return m_ledgerLinesBelowCue; }
235  const ArrayOfLedgerLines &GetLedgerLinesBelowCue() const { return m_ledgerLinesBelowCue; }
237 
243  void AddLedgerLineAbove(int count, int left, int right, int extension, bool cueSize, const Object *event);
244  void AddLedgerLineBelow(int count, int left, int right, int extension, bool cueSize, const Object *event);
246 
251  bool IsOnStaffLine(int y, const Doc *doc) const;
252 
257  int GetNearestInterStaffPosition(int y, const Doc *doc, data_STAFFREL place) const;
258 
264  void SetFromFacsimile(Doc *doc);
265 
266  //----------//
267  // Functors //
268  //----------//
269 
274  FunctorCode Accept(Functor &functor) override;
275  FunctorCode Accept(ConstFunctor &functor) const override;
276  FunctorCode AcceptEnd(Functor &functor) override;
277  FunctorCode AcceptEnd(ConstFunctor &functor) const override;
279 
280 private:
284  void AddLedgerLines(ArrayOfLedgerLines &lines, int count, int left, int right, int extension, const Object *event);
285 
286 public:
291 
295  data_NOTATIONTYPE m_drawingNotationType;
296 
301 
305  std::vector<Object *> m_timeSpanningElements;
306 
312 
313  StaffDef *m_drawingStaffDef;
314 
315  Tuning *m_drawingTuning;
316 
317 private:
321  StaffAlignment *m_staffAlignment;
322 
327  ArrayOfLedgerLines m_ledgerLinesAbove;
328  ArrayOfLedgerLines m_ledgerLinesBelow;
329  ArrayOfLedgerLines m_ledgerLinesAboveCue;
330  ArrayOfLedgerLines m_ledgerLinesBelowCue;
332 
337  double m_drawingRotation;
338 };
339 
340 } // namespace vrv
341 
342 #endif
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
Definition: facsimileinterface.h:27
This abstract class is the base class for all mutable functors.
Definition: functor.h:101
Definition: staff.h:48
This is a class with no MEI equivalent for representing legder lines.
Definition: staff.h:35
void AddDash(int left, int right, int extension, const Object *event)
Add a dash to the ledger line object.
std::list< Dash > m_dashes
A list of dashes relative to the staff position.
Definition: staff.h:84
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 stores an alignement position staves will point to.
Definition: verticalaligner.h:172
This class represents a MEI staffDef.
Definition: staffdef.h:37
This class represents a staff in a laid-out score (Doc).
Definition: staff.h:107
std::vector< Object * > m_timeSpanningElements
A vector of all the spanning elements overlapping with the previous measure.
Definition: staff.h:305
void SetFromFacsimile(Doc *doc)
Set staff parameters based on facsimile information (if it exists).
ArrayOfLedgerLines & GetLedgerLinesAbove()
Return the ledger line arrays.
Definition: staff.h:228
int GetNearestInterStaffPosition(int y, const Doc *doc, data_STAFFREL place) const
Find the nearest unit position in the direction indicated by place.
int m_drawingFacsY
The Y absolute position of the staff for facsimile (transcription) encodings.
Definition: staff.h:311
data_NOTATIONTYPE m_drawingNotationType
Notation type (CMN, mensural, black mensural, etc.), from the staffDef.
Definition: staff.h:295
int GetDrawingStaffNotationSize() const
Return the drawing staff size for staff notation, including for tablature staves.
void ClearLedgerLines()
Delete all the legder line arrays.
void Reset() override
Virtual reset method.
bool AddChildAdditionalCheck(Object *child) override
Additional check when adding a child.
Object * Clone() const override
Method call for copying child classes.
Definition: staff.h:117
int CalcPitchPosYRel(const Doc *doc, int loc) const
Calculate the yRel for the staff given a @loc value.
StaffAlignment * GetAlignment()
Getter and setter for the StaffAlignment.
Definition: staff.h:219
bool DrawingIsVisible() const
Check if the staff is currently visible.
int GetStaffIdx() const
Return the index position of the staff in its measure parent.
Definition: staff.h:208
int m_drawingLines
Number of lines copied from the staffDef for fast access when drawing.
Definition: staff.h:290
bool IsSupportedChild(ClassId classId) override
Base method for checking if a child can be added.
FunctorCode Accept(Functor &functor) override
Interface for class functor visitation.
void AddLedgerLineAbove(int count, int left, int right, int extension, bool cueSize, const Object *event)
Add the ledger lines above or below.
void AdjustDrawingStaffSize()
Adjust drawingStaffSize based on rotate angle.
void CloneReset() override
Overriding CloneReset() method to be called after copy / assignment calls.
int m_drawingStaffSize
The drawing staff size (scale), from the staffDef.
Definition: staff.h:300
bool IsOnStaffLine(int y, const Doc *doc) const
Used for calculating note groups information/dot position.
This class models the MEI <tuning> element.
Definition: tuning.h:23