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 "drawinginterface.h"
13 #include "facsimileinterface.h"
14 #include "object.h"
15 
16 namespace vrv {
17 
18 class DeviceContext;
19 class Layer;
20 class LedgerLine;
21 class Measure;
22 class StaffAlignment;
23 class StaffDef;
24 class Syl;
25 class TimeSpanningInterface;
26 class Tuning;
27 
28 //----------------------------------------------------------------------------
29 // LedgerLine
30 //----------------------------------------------------------------------------
31 
37 class LedgerLine {
38 public:
42  LedgerLine() = default;
43 
48  void AddDash(int left, int right, int extension, const Object *event);
49 
50  class Dash {
51  public:
52  int m_x1;
53  int m_x2;
54  ListOfConstObjects m_events;
55 
56  // Constructor
57  Dash(int x1, int x2, const Object *object)
58  {
59  m_x1 = x1;
60  m_x2 = x2;
61  m_events.push_back(object);
62  }
63 
64  // Merge function to merge another Dash object into this one
65  void MergeWith(const Dash &other)
66  {
67  // Keep the first int from this Dash object, and the second int from the other
68  this->m_x1 = std::min(other.m_x1, this->m_x1);
69  this->m_x2 = std::max(other.m_x2, this->m_x2);
70  // Append the list from other to this
71  if (!other.m_events.empty()) {
72  this->m_events.insert(this->m_events.end(), other.m_events.begin(), other.m_events.end());
73  }
74  }
75  };
76 
77 protected:
78  //
79 private:
80  //
81 public:
85  // std::list<std::pair<int, int>> m_dashes;
86  std::list<Dash> m_dashes;
87 
88 protected:
89  //
90 private:
91  //
92 };
93 
94 //----------------------------------------------------------------------------
95 // Staff
96 //----------------------------------------------------------------------------
97 
104 class Staff : public Object,
106  public FacsimileInterface,
107  public AttCoordY1,
108  public AttNInteger,
109  public AttTyped,
110  public AttVisibility {
111 
112 public:
118  Staff(int n = 1, bool isOssia = false);
119  virtual ~Staff();
120  Object *Clone() const override { return new Staff(*this); }
121  void Reset() override;
122  std::string GetClassName() const override { return (this->IsOssia() ? "oStaff" : "staff"); }
124 
128  void CloneReset() override;
129 
134  FacsimileInterface *GetFacsimileInterface() override { return vrv_cast<FacsimileInterface *>(this); }
135  const FacsimileInterface *GetFacsimileInterface() const override
136  {
137  return vrv_cast<const FacsimileInterface *>(this);
138  }
139  VisibilityDrawingInterface *GetVisibilityDrawingInterface() override
140  {
141  return vrv_cast<VisibilityDrawingInterface *>(this);
142  }
143  const VisibilityDrawingInterface *GetVisibilityDrawingInterface() const override
144  {
145  return vrv_cast<const VisibilityDrawingInterface *>(this);
146  }
148 
153  bool IsOssia() const { return (m_isOssia); }
154  void SetOssia(bool isOssia) { m_isOssia = isOssia; }
155  int GetNForOssia() const;
156  int GetNFromOssia() const;
158 
163  void AttributesToExternal() override;
164  void AttributesToInternal() override;
166 
172  void SetDrawingRotation(double drawingRotation) { m_drawingRotation = drawingRotation; }
173  double GetDrawingRotation() const { return m_drawingRotation; }
174  bool HasDrawingRotation() const { return (m_drawingRotation != 0.0); }
175  int GetDrawingRotationOffsetFor(int x);
177 
182 
187  bool IsSupportedChild(ClassId classId) override;
189 
193  bool AddChildAdditionalCheck(Object *child) override;
194 
199  int GetDrawingX() const override;
200  int GetDrawingY() const override;
201  virtual double GetDrawingRotate() const;
203 
208 
213 
218  bool DrawingIsVisible() const;
219 
224  bool IsMensural() const;
225  bool IsNeume() const;
226  bool IsTablature() const;
227  bool IsTabGuitar() const { return m_drawingNotationType == NOTATIONTYPE_tab_guitar; }
228  bool IsTabLuteFrench() const { return m_drawingNotationType == NOTATIONTYPE_tab_lute_french; }
229  bool IsTabLuteGerman() const { return m_drawingNotationType == NOTATIONTYPE_tab_lute_german; }
230  bool IsTabLuteItalian() const { return m_drawingNotationType == NOTATIONTYPE_tab_lute_italian; }
231  bool IsTabWithStemsOutside() const;
233 
237  int GetStaffIdx() const { return Object::GetIdx(); }
238 
242  int CalcPitchPosYRel(const Doc *doc, int loc) const;
243 
248  StaffAlignment *GetAlignment() { return m_staffAlignment; }
249  const StaffAlignment *GetAlignment() const { return m_staffAlignment; }
250  void SetAlignment(StaffAlignment *alignment) { m_staffAlignment = alignment; }
252 
257  ArrayOfLedgerLines &GetLedgerLinesAbove() { return m_ledgerLinesAbove; }
258  const ArrayOfLedgerLines &GetLedgerLinesAbove() const { return m_ledgerLinesAbove; }
259  ArrayOfLedgerLines &GetLedgerLinesAboveCue() { return m_ledgerLinesAboveCue; }
260  const ArrayOfLedgerLines &GetLedgerLinesAboveCue() const { return m_ledgerLinesAboveCue; }
261  ArrayOfLedgerLines &GetLedgerLinesBelow() { return m_ledgerLinesBelow; }
262  const ArrayOfLedgerLines &GetLedgerLinesBelow() const { return m_ledgerLinesBelow; }
263  ArrayOfLedgerLines &GetLedgerLinesBelowCue() { return m_ledgerLinesBelowCue; }
264  const ArrayOfLedgerLines &GetLedgerLinesBelowCue() const { return m_ledgerLinesBelowCue; }
266 
272  void AddLedgerLineAbove(int count, int left, int right, int extension, bool cueSize, const Object *event);
273  void AddLedgerLineBelow(int count, int left, int right, int extension, bool cueSize, const Object *event);
275 
280  bool IsOnStaffLine(int y, const Doc *doc) const;
281 
286  int GetNearestInterStaffPosition(int y, const Doc *doc, data_STAFFREL place) const;
287 
293  void SetFromFacsimile(Doc *doc);
294 
298  int GetOssiaDrawingShift(const Measure *measure, Doc *doc) const;
299 
300  //----------//
301  // Functors //
302  //----------//
303 
308  FunctorCode Accept(Functor &functor) override;
309  FunctorCode Accept(ConstFunctor &functor) const override;
310  FunctorCode AcceptEnd(Functor &functor) override;
311  FunctorCode AcceptEnd(ConstFunctor &functor) const override;
313 
314 private:
318  void AddLedgerLines(ArrayOfLedgerLines &lines, int count, int left, int right, int extension, const Object *event);
319 
320 public:
325 
329  data_NOTATIONTYPE m_drawingNotationType;
330 
335 
339  std::vector<Object *> m_timeSpanningElements;
340 
346 
347  StaffDef *m_drawingStaffDef;
348 
349  Tuning *m_drawingTuning;
350 
351 private:
355  StaffAlignment *m_staffAlignment;
356 
361  ArrayOfLedgerLines m_ledgerLinesAbove;
362  ArrayOfLedgerLines m_ledgerLinesBelow;
363  ArrayOfLedgerLines m_ledgerLinesAboveCue;
364  ArrayOfLedgerLines m_ledgerLinesBelowCue;
366 
371  double m_drawingRotation;
372 
374  bool m_isOssia;
375 };
376 
377 } // namespace vrv
378 
379 #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:50
This is a class with no MEI equivalent for representing legder lines.
Definition: staff.h:37
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:86
This class represents a measure in a page-based score (Doc).
Definition: measure.h:46
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 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:110
std::vector< Object * > m_timeSpanningElements
A vector of all the spanning elements overlapping with the previous measure.
Definition: staff.h:339
void SetFromFacsimile(Doc *doc)
Set staff parameters based on facsimile information (if it exists).
ArrayOfLedgerLines & GetLedgerLinesAbove()
Return the ledger line arrays.
Definition: staff.h:257
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:345
data_NOTATIONTYPE m_drawingNotationType
Notation type (CMN, mensural, black mensural, etc.), from the staffDef.
Definition: staff.h:329
int GetDrawingStaffNotationSize() const
Return the drawing staff size for staff notation, including for tablature staves.
void ClearLedgerLines()
Delete all the legder line arrays.
bool AddChildAdditionalCheck(Object *child) override
Additional check when adding a child.
Object * Clone() const override
Method call for copying child classes.
Definition: staff.h:120
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:248
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:237
int m_drawingLines
Number of lines copied from the staffDef for fast access when drawing.
Definition: staff.h:324
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:334
int GetOssiaDrawingShift(const Measure *measure, Doc *doc) const
Get the drawing x if the staff is an ossia and has an ossia staffDef.
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
This class is an interface for MEI element that can be hidden during drawing.
Definition: drawinginterface.h:448