Verovio
Source code documentation
accid.h
1 // Name: accid.h
3 // Author: Laurent Pugin
4 // Created: 201X
5 // Copyright (c) Authors and others. All rights reserved.
7 
8 #ifndef __VRV_ACCID_H__
9 #define __VRV_ACCID_H__
10 
11 #include "atts_externalsymbols.h"
12 #include "atts_gestural.h"
13 #include "layerelement.h"
14 #include "positioninterface.h"
15 
16 namespace vrv {
17 
18 class AlignmentReference;
19 
20 //----------------------------------------------------------------------------
21 // Accid
22 //----------------------------------------------------------------------------
23 
27 class Accid : public LayerElement,
28  public PositionInterface,
29  public AttAccidental,
30  public AttAccidentalGes,
31  public AttAccidLog,
32  public AttColor,
33  public AttEnclosingChars,
34  public AttExtSymAuth,
35  public AttExtSymNames,
36  public AttPlacementOnStaff,
37  public AttPlacementRelEvent {
38 public:
44  Accid();
45  virtual ~Accid();
46  Object *Clone() const override { return new Accid(*this); }
47  void Reset() override;
48  std::string GetClassName() const override { return "accid"; }
50 
52  bool IsRelativeToStaff() const override { return (this->HasLoc() || (this->HasOloc() && this->HasPloc())); }
53 
58  PositionInterface *GetPositionInterface() override { return vrv_cast<PositionInterface *>(this); }
59  const PositionInterface *GetPositionInterface() const override { return vrv_cast<const PositionInterface *>(this); }
61 
63  bool HasToBeAligned() const override { return true; }
64 
69  void SetDrawingUnisonAccid(Accid *drawingUnison) { m_drawingUnison = drawingUnison; }
70  Accid *GetDrawingUnisonAccid() { return m_drawingUnison; }
71  const Accid *GetDrawingUnisonAccid() const { return m_drawingUnison; }
73 
78  std::u32string GetSymbolStr(data_NOTATIONTYPE notationType) const;
79 
83  void AdjustX(LayerElement *element, const Doc *doc, int staffSize, std::vector<Accid *> &leftAccids,
84  std::set<Accid *> &adjustedAccids);
85 
89  void AdjustToLedgerLines(const Doc *doc, LayerElement *element, int staffSize);
90 
95  void IsAlignedWithSameLayer(bool alignWithSameLayer) { m_alignedWithSameLayer = alignWithSameLayer; }
96  bool IsAlignedWithSameLayer() const { return m_alignedWithSameLayer; }
98 
99  //----------------//
100  // Static methods //
101  //----------------//
102 
106  static char32_t GetAccidGlyph(data_ACCIDENTAL_WRITTEN accid);
107 
111  static std::u32string CreateSymbolStr(data_ACCIDENTAL_WRITTEN accid, data_ENCLOSURE enclosure = ENCLOSURE_NONE,
112  data_NOTATIONTYPE notationType = NOTATIONTYPE_NONE, const Resources *resources = NULL, data_HEXNUM glyphNum = 0,
113  std::string glyphName = "");
114 
115  //----------//
116  // Functors //
117  //----------//
118 
123  FunctorCode Accept(Functor &functor) override;
124  FunctorCode Accept(ConstFunctor &functor) const override;
125  FunctorCode AcceptEnd(Functor &functor) override;
126  FunctorCode AcceptEnd(ConstFunctor &functor) const override;
128 
129 private:
130  //
131 public:
132  //
133 private:
134  Accid *m_drawingUnison;
135  bool m_alignedWithSameLayer;
136 };
137 
138 //----------------------------------------------------------------------------
139 // AccidSpaceSort
140 //----------------------------------------------------------------------------
141 
146 
147 public:
148  AccidSpaceSort() = default;
149 
150  bool operator()(const Accid *first, const Accid *second) const
151  {
152  if (first->GetDrawingY() == second->GetDrawingY()) {
153  // with unissons, natural should always be the last accidental
154  return ((first->GetAccid() == ACCIDENTAL_WRITTEN_n) && (second->GetAccid() != ACCIDENTAL_WRITTEN_n));
155  }
156  else {
157  return (first->GetDrawingY() > second->GetDrawingY());
158  }
159  }
160 };
161 
162 //----------------------------------------------------------------------------
163 // AccidOctaveSort
164 //----------------------------------------------------------------------------
165 
170 
171 public:
172  AccidOctaveSort() = default;
173 
174  // Encodes parent ID + accid type + pitch
175  std::string GetOctaveID(const Accid *accid) const;
176 
177  bool operator()(const Accid *first, const Accid *second) const
178  {
179  return this->GetOctaveID(first) < this->GetOctaveID(second);
180  }
181 };
182 
183 } // namespace vrv
184 
185 #endif
This class models the MEI <accid> element.
Definition: accid.h:37
void AdjustToLedgerLines(const Doc *doc, LayerElement *element, int staffSize)
Adjust accid position if it's placed above/below staff so that it does not overlap with ledger lines.
bool HasToBeAligned() const override
Override the method since alignment is required.
Definition: accid.h:63
void AdjustX(LayerElement *element, const Doc *doc, int staffSize, std::vector< Accid * > &leftAccids, std::set< Accid * > &adjustedAccids)
Adjust X position of accid in relation to other element.
void Reset() override
Virtual reset method.
static std::u32string CreateSymbolStr(data_ACCIDENTAL_WRITTEN accid, data_ENCLOSURE enclosure=ENCLOSURE_NONE, data_NOTATIONTYPE notationType=NOTATIONTYPE_NONE, const Resources *resources=NULL, data_HEXNUM glyphNum=0, std::string glyphName="")
Create the SMuFL string based on various properties.
Object * Clone() const override
Method call for copying child classes.
Definition: accid.h:46
FunctorCode Accept(Functor &functor) override
Interface for class functor visitation.
bool IsRelativeToStaff() const override
Override the method since it is align to the staff.
Definition: accid.h:52
std::u32string GetSymbolStr(data_NOTATIONTYPE notationType) const
Retrieve SMuFL string for the accidental.
Equivalence of accidentals that are an octave apart.
Definition: accid.h:169
Sort Object by drawing Y value.
Definition: accid.h:145
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 abstract class is the base class for all mutable functors.
Definition: functor.h:101
This class is a base class for the Layer (<layer>) content.
Definition: layerelement.h:51
This class represents a basic object.
Definition: object.h:61
This class is an interface for elements with a position on the staff, such as rests.
Definition: positioninterface.h:30
This class provides resource values.
Definition: resources.h:30