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 "positioninterface.h"
16 
17 namespace vrv {
18 
19 class AlignmentReference;
20 class AccidFloatingObject;
21 
22 //----------------------------------------------------------------------------
23 // Accid
24 //----------------------------------------------------------------------------
25 
29 class Accid : public LayerElement,
30  public PositionInterface,
31  public AttAccidental,
32  public AttAccidentalGes,
33  public AttAccidLog,
34  public AttColor,
35  public AttEnclosingChars,
36  public AttExtSymAuth,
37  public AttExtSymNames,
38  public AttPlacementOnStaff,
39  public AttPlacementRelEvent {
40 public:
46  Accid();
47  virtual ~Accid();
48  Object *Clone() const override { return new Accid(*this); }
49  void Reset() override;
50  std::string GetClassName() const override { return "accid"; }
52 
55 
58 
60  AccidFloatingObject *GetFloatingObject() { return m_floatingObject; }
61 
63  bool IsRelativeToStaff() const override { return (this->HasLoc() || (this->HasOloc() && this->HasPloc())); }
64 
69  PositionInterface *GetPositionInterface() override { return vrv_cast<PositionInterface *>(this); }
70  const PositionInterface *GetPositionInterface() const override { return vrv_cast<const PositionInterface *>(this); }
72 
74  bool HasToBeAligned() const override { return true; }
75 
80  void SetDrawingUnisonAccid(Accid *drawingUnison) { m_drawingUnison = drawingUnison; }
81  Accid *GetDrawingUnisonAccid() { return m_drawingUnison; }
82  const Accid *GetDrawingUnisonAccid() const { return m_drawingUnison; }
84 
89  std::u32string GetSymbolStr(data_NOTATIONTYPE notationType) const;
90 
94  void AdjustX(LayerElement *element, const Doc *doc, int staffSize, std::vector<Accid *> &leftAccids,
95  std::set<Accid *> &adjustedAccids);
96 
100  void AdjustToLedgerLines(const Doc *doc, LayerElement *element, int staffSize);
101 
106  void IsAlignedWithSameLayer(bool alignWithSameLayer) { m_alignedWithSameLayer = alignWithSameLayer; }
107  bool IsAlignedWithSameLayer() const { return m_alignedWithSameLayer; }
109 
110  //----------------//
111  // Static methods //
112  //----------------//
113 
117  static char32_t GetAccidGlyph(data_ACCIDENTAL_WRITTEN accid);
118 
122  static std::u32string CreateSymbolStr(data_ACCIDENTAL_WRITTEN accid, data_ENCLOSURE enclosure = ENCLOSURE_NONE,
123  data_NOTATIONTYPE notationType = NOTATIONTYPE_NONE, const Resources *resources = NULL, data_HEXNUM glyphNum = 0,
124  std::string glyphName = "");
125 
126  //----------//
127  // Functors //
128  //----------//
129 
134  FunctorCode Accept(Functor &functor) override;
135  FunctorCode Accept(ConstFunctor &functor) const override;
136  FunctorCode AcceptEnd(Functor &functor) override;
137  FunctorCode AcceptEnd(ConstFunctor &functor) const override;
139 
140 private:
141  //
142 public:
143  //
144 private:
145  Accid *m_drawingUnison;
146  bool m_alignedWithSameLayer;
147 
149  AccidFloatingObject *m_floatingObject;
150 };
151 
152 //----------------------------------------------------------------------------
153 // AccidFloatingObject
154 //----------------------------------------------------------------------------
155 
160 public:
167  virtual ~AccidFloatingObject() {}
168  std::string GetClassName() const override { return "accid"; }
169  void Reset() override;
171 
172 private:
173  //
174 public:
175  //
176 private:
177  //
178 };
179 
180 //----------------------------------------------------------------------------
181 // AccidSpaceSort
182 //----------------------------------------------------------------------------
183 
188 
189 public:
190  AccidSpaceSort() = default;
191 
192  bool operator()(const Accid *first, const Accid *second) const
193  {
194  if (first->GetDrawingY() == second->GetDrawingY()) {
195  // with unissons, natural should always be the last accidental
196  return ((first->GetAccid() == ACCIDENTAL_WRITTEN_n) && (second->GetAccid() != ACCIDENTAL_WRITTEN_n));
197  }
198  else {
199  return (first->GetDrawingY() > second->GetDrawingY());
200  }
201  }
202 };
203 
204 //----------------------------------------------------------------------------
205 // AccidOctaveSort
206 //----------------------------------------------------------------------------
207 
212 
213 public:
214  AccidOctaveSort() = default;
215 
216  // Encodes parent ID + accid type + pitch
217  std::string GetOctaveID(const Accid *accid) const;
218 
219  bool operator()(const Accid *first, const Accid *second) const
220  {
221  return this->GetOctaveID(first) < this->GetOctaveID(second);
222  }
223 };
224 
225 } // namespace vrv
226 
227 #endif
This class is used for editorial accidentals to be laid out as floating objects.
Definition: accid.h:159
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:39
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:74
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:48
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:63
AccidFloatingObject * GetFloatingObject()
Return the floating object (NULL if not set)
Definition: accid.h:60
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:211
Sort Object by drawing Y value.
Definition: accid.h:187
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:62
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