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 "floatingobject.h"
14 #include "layerelement.h"
15 #include "offsetinterface.h"
16 #include "positioninterface.h"
17 
18 namespace vrv {
19 
20 class AlignmentReference;
21 class AccidFloatingObject;
22 
23 //----------------------------------------------------------------------------
24 // Accid
25 //----------------------------------------------------------------------------
26 
30 class Accid : public LayerElement,
31  public OffsetInterface,
32  public PositionInterface,
33  public AttAccidental,
34  public AttAccidentalGes,
35  public AttAccidLog,
36  public AttColor,
37  public AttEnclosingChars,
38  public AttExtSymAuth,
39  public AttExtSymNames,
40  public AttPlacementOnStaff,
41  public AttPlacementRelEvent {
42 public:
48  Accid();
49  virtual ~Accid();
50  Object *Clone() const override { return new Accid(*this); }
51  void Reset() override;
52  std::string GetClassName() const override { return "accid"; }
54 
59  bool IsSupportedChild(ClassId classId) override;
60 
63 
66 
69 
71  AccidFloatingObject *GetFloatingObject() { return m_floatingObject; }
72 
74  bool IsRelativeToStaff() const override { return (this->HasLoc() || (this->HasOloc() && this->HasPloc())); }
75 
80  OffsetInterface *GetOffsetInterface() override { return vrv_cast<OffsetInterface *>(this); }
81  const OffsetInterface *GetOffsetInterface() const override { return vrv_cast<const OffsetInterface *>(this); }
82  PositionInterface *GetPositionInterface() override { return vrv_cast<PositionInterface *>(this); }
83  const PositionInterface *GetPositionInterface() const override { return vrv_cast<const PositionInterface *>(this); }
85 
87  bool HasToBeAligned() const override { return true; }
88 
93  void SetDrawingUnisonAccid(Accid *drawingUnison) { m_drawingUnison = drawingUnison; }
94  Accid *GetDrawingUnisonAccid() { return m_drawingUnison; }
95  const Accid *GetDrawingUnisonAccid() const { return m_drawingUnison; }
97 
102  std::u32string GetSymbolStr(data_NOTATIONTYPE notationType) const;
103 
107  void AdjustX(LayerElement *element, const Doc *doc, int staffSize, std::vector<Accid *> &leftAccids,
108  std::set<Accid *> &adjustedAccids);
109 
113  void AdjustToLedgerLines(const Doc *doc, LayerElement *element, int staffSize);
114 
119  void IsAlignedWithSameLayer(bool alignWithSameLayer) { m_alignedWithSameLayer = alignWithSameLayer; }
120  bool IsAlignedWithSameLayer() const { return m_alignedWithSameLayer; }
122 
123  //----------------//
124  // Static methods //
125  //----------------//
126 
130  static char32_t GetAccidGlyph(data_ACCIDENTAL_WRITTEN accid);
131 
135  static std::u32string CreateSymbolStr(data_ACCIDENTAL_WRITTEN accid, data_ENCLOSURE enclosure = ENCLOSURE_NONE,
136  data_NOTATIONTYPE notationType = NOTATIONTYPE_NONE, const Resources *resources = NULL, data_HEXNUM glyphNum = 0,
137  std::string glyphName = "");
138 
139  //----------//
140  // Functors //
141  //----------//
142 
147  FunctorCode Accept(Functor &functor) override;
148  FunctorCode Accept(ConstFunctor &functor) const override;
149  FunctorCode AcceptEnd(Functor &functor) override;
150  FunctorCode AcceptEnd(ConstFunctor &functor) const override;
152 
153 private:
154  //
155 public:
156  //
157 private:
158  Accid *m_drawingUnison;
159  bool m_alignedWithSameLayer;
160 
162  AccidFloatingObject *m_floatingObject;
163 };
164 
165 //----------------------------------------------------------------------------
166 // AccidFloatingObject
167 //----------------------------------------------------------------------------
168 
173 public:
180  virtual ~AccidFloatingObject() {}
181  std::string GetClassName() const override { return "accid"; }
182  void Reset() override;
184 
185 private:
186  //
187 public:
188  //
189 private:
190  //
191 };
192 
193 //----------------------------------------------------------------------------
194 // AccidSpaceSort
195 //----------------------------------------------------------------------------
196 
201 
202 public:
203  AccidSpaceSort() = default;
204 
205  bool operator()(const Accid *first, const Accid *second) const
206  {
207  if (first->GetDrawingY() == second->GetDrawingY()) {
208  // with unissons, natural should always be the last accidental
209  return ((first->GetAccid() == ACCIDENTAL_WRITTEN_n) && (second->GetAccid() != ACCIDENTAL_WRITTEN_n));
210  }
211  else {
212  return (first->GetDrawingY() > second->GetDrawingY());
213  }
214  }
215 };
216 
217 //----------------------------------------------------------------------------
218 // AccidOctaveSort
219 //----------------------------------------------------------------------------
220 
225 
226 public:
227  AccidOctaveSort() = default;
228 
229  // Encodes parent ID + accid type + pitch
230  std::string GetOctaveID(const Accid *accid) const;
231 
232  bool operator()(const Accid *first, const Accid *second) const
233  {
234  return this->GetOctaveID(first) < this->GetOctaveID(second);
235  }
236 };
237 
238 } // namespace vrv
239 
240 #endif
This class is used for editorial accidentals to be laid out as floating objects.
Definition: accid.h:172
void Reset() override
Reset the object, that is 1) removing all children and 2) resetting all attributes.
This class models the MEI <accid> element.
Definition: accid.h:41
bool IsSupportedChild(ClassId classId) override
Add an element (accid) to a accid.
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.
void InitFloatingObject()
Init the accid floating object for editorial accidentals.
bool HasToBeAligned() const override
Override the method since alignment is required.
Definition: accid.h:87
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:50
FunctorCode Accept(Functor &functor) override
Interface for class functor visitation.
void InitShowAccidGes()
Init the display of accid.ges when the option is set.
bool IsRelativeToStaff() const override
Override the method since it is align to the staff.
Definition: accid.h:74
AccidFloatingObject * GetFloatingObject()
Return the floating object (NULL if not set)
Definition: accid.h:71
void ClearFloatingObject()
Delete the floating object (editorial accidental) on reset or deletion.
std::u32string GetSymbolStr(data_NOTATIONTYPE notationType) const
Retrieve SMuFL string for the accidental.
Equivalence of accidentals that are an octave apart.
Definition: accid.h:224
Sort Object by drawing Y value.
Definition: accid.h:200
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 elements appearing within a measure.
Definition: floatingobject.h:28
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:66
This class is an interface for elements having a single visual offset, such as arpeg,...
Definition: offsetinterface.h:28
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