Verovio
Source code documentation
rest.h
1 // Name: rest.h
3 // Author: Laurent Pugin
4 // Created: 2011
5 // Copyright (c) Authors and others. All rights reserved.
7 
8 #ifndef __VRV_REST_H__
9 #define __VRV_REST_H__
10 
11 #include "altsyminterface.h"
12 #include "atts_externalsymbols.h"
13 #include "atts_mensural.h"
14 #include "atts_visual.h"
15 #include "durationinterface.h"
16 #include "layerelement.h"
17 #include "offsetinterface.h"
18 #include "positioninterface.h"
19 
20 namespace vrv {
21 
22 class TransPitch;
23 
24 enum RestLayer { RL_UNSET = -1, RL_sameLayer, RL_otherLayer };
25 
26 enum RestAccidental { RA_UNSET = -1, RA_none, RA_s, RA_f, RA_x, RA_n };
27 
28 enum RestLayerPlace { RLP_UNSET = -1, RLP_restOnTopLayer, RLP_restOnBottomLayer };
29 
30 enum RestNotePlace { RNP_UNSET = -1, RNP_noteInSpace, RNP_noteOnLine };
31 
32 //----------------------------------------------------------------------------
33 // Rest
34 //----------------------------------------------------------------------------
35 
39 class Rest : public LayerElement,
40  public AltSymInterface,
41  public DurationInterface,
42  public OffsetInterface,
43  public PositionInterface,
44  public AttColor,
45  public AttCue,
46  public AttEnclosingChars,
47  public AttExtSymAuth,
48  public AttExtSymNames,
49  public AttRestVisMensural {
50 public:
56  Rest();
57  virtual ~Rest();
58  Object *Clone() const override { return new Rest(*this); }
59  void Reset() override;
60  std::string GetClassName() const override { return "rest"; }
62 
67  bool IsSupportedChild(ClassId classId) override;
68 
72  bool AddChild(Object *object) override;
73 
78  AltSymInterface *GetAltSymInterface() override { return vrv_cast<AltSymInterface *>(this); }
79  const AltSymInterface *GetAltSymInterface() const override { return vrv_cast<const AltSymInterface *>(this); }
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); }
84  DurationInterface *GetDurationInterface() override { return vrv_cast<DurationInterface *>(this); }
85  const DurationInterface *GetDurationInterface() const override { return vrv_cast<const DurationInterface *>(this); }
87 
89  bool HasToBeAligned() const override { return true; }
90 
96  char32_t GetRestGlyph() const;
97  char32_t GetRestGlyph(const data_DURATION duration) const;
99 
103  int GetOptimalLayerLocation(const Staff *staff, const Layer *layer, int defaultLocation) const;
104 
109 
113  std::pair<char32_t, char32_t> GetEnclosingGlyphs() const;
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:
133  std::pair<int, RestAccidental> GetLocationRelativeToOtherLayers(
134  const Layer *currentLayer, bool isTopLayer, bool &restOverlap) const;
135 
139  int GetLocationRelativeToCurrentLayer(const Staff *currentStaff, const Layer *currentLayer, bool isTopLayer) const;
140 
144  int GetFirstRelativeElementLocation(
145  const Staff *currentStaff, const Layer *currentLayer, bool isPrevious, bool isTopLayer) const;
146 
151  int GetMarginLayerLocation(bool isTopLayer, bool restOverlap) const;
152 
156  std::pair<int, RestAccidental> GetElementLocation(const Object *object, const Layer *layer, bool isTopLayer) const;
157 
161  int GetRestOffsetFromOptions(
162  RestLayer layer, const std::pair<int, RestAccidental> &location, bool isTopLayer) const;
163 
168  bool DetermineRestPosition(const Staff *staff, const Layer *layer, bool &isTopLayer) const;
169 
170 public:
171  //
172 private:
173 };
174 
175 } // namespace vrv
176 
177 #endif
This class is an interface for elements having a @altsym It is not an abstract class but should not b...
Definition: altsyminterface.h:30
This abstract class is the base class for all const functors.
Definition: functor.h:126
This class is an interface for elements with duration, such as notes and rests.
Definition: durationinterface.h:39
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 layer in a laid-out score (Doc).
Definition: layer.h:39
This class represents a basic object.
Definition: object.h:64
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 models the MEI <rest> element.
Definition: rest.h:49
char32_t GetRestGlyph() const
Get the SMuFL glyph or a rest considering its actual duration.
std::pair< char32_t, char32_t > GetEnclosingGlyphs() const
Retrieve parentheses / brackets from the enclose attribute.
void UpdateFromTransLoc(const TransPitch &tp)
Update the rest location based on the input TransPitch.
bool AddChild(Object *object) override
Overwritten method for rest.
FunctorCode Accept(Functor &functor) override
Interface for class functor visitation.
void Reset() override
Virtual reset method.
bool HasToBeAligned() const override
Override the method since alignment is required.
Definition: rest.h:89
Object * Clone() const override
Method call for copying child classes.
Definition: rest.h:58
bool IsSupportedChild(ClassId classId) override
Add an element to a rest.
int GetOptimalLayerLocation(const Staff *staff, const Layer *layer, int defaultLocation) const
Get the vertical location for the rests that are located on other layers.
This class represents a staff in a laid-out score (Doc).
Definition: staff.h:107
Definition: transposition.h:35