Verovio
Source code documentation
note.h
1 // Name: note.h
3 // Author: Laurent Pugin
4 // Created: 2011
5 // Copyright (c) Authors and others. All rights reserved.
7 
8 #ifndef __VRV_NOTE_H__
9 #define __VRV_NOTE_H__
10 
11 #include <cassert>
12 
13 //----------------------------------------------------------------------------
14 
15 #include "accid.h"
16 #include "altsyminterface.h"
17 #include "atts_analytical.h"
18 #include "atts_externalsymbols.h"
19 #include "atts_mensural.h"
20 #include "atts_midi.h"
21 #include "atts_shared.h"
22 #include "atts_stringtab.h"
23 #include "beam.h"
24 #include "chord.h"
25 #include "durationinterface.h"
26 #include "layerelement.h"
27 #include "offsetinterface.h"
28 #include "pitchinterface.h"
29 #include "transposition.h"
30 
31 namespace vrv {
32 
33 class Accid;
34 class Chord;
35 class Note;
36 class Slur;
37 class TabGrp;
38 class Tie;
39 class Verse;
40 
41 //----------------------------------------------------------------------------
42 // Note
43 //----------------------------------------------------------------------------
44 
48 class Note : public LayerElement,
50  public AltSymInterface,
51  public DurationInterface,
52  public OffsetInterface,
53  public PitchInterface,
54  public PositionInterface,
55  public AttColor,
56  public AttColoration,
57  public AttCue,
58  public AttExtSymAuth,
59  public AttExtSymNames,
60  public AttGraced,
61  public AttHarmonicFunction,
62  public AttMidiVelocity,
63  public AttNoteHeads,
64  public AttNoteVisMensural,
65  public AttStems,
66  public AttStemsCmn,
67  public AttStringtab,
68  public AttTiePresent,
69  public AttVisibility {
70 public:
76  Note();
77  virtual ~Note();
78  Object *Clone() const override { return new Note(*this); }
79  void Reset() override;
80  std::string GetClassName() const override { return "note"; }
82 
86  void CloneReset() override;
87 
92  AltSymInterface *GetAltSymInterface() override { return vrv_cast<AltSymInterface *>(this); }
93  const AltSymInterface *GetAltSymInterface() const override { return vrv_cast<const AltSymInterface *>(this); }
94  DurationInterface *GetDurationInterface() override { return vrv_cast<DurationInterface *>(this); }
95  const DurationInterface *GetDurationInterface() const override { return vrv_cast<const DurationInterface *>(this); }
96  OffsetInterface *GetOffsetInterface() override { return vrv_cast<OffsetInterface *>(this); }
97  const OffsetInterface *GetOffsetInterface() const override { return vrv_cast<const OffsetInterface *>(this); }
98  PitchInterface *GetPitchInterface() override { return vrv_cast<PitchInterface *>(this); }
99  const PitchInterface *GetPitchInterface() const override { return vrv_cast<const PitchInterface *>(this); }
100  PositionInterface *GetPositionInterface() override { return vrv_cast<PositionInterface *>(this); }
101  const PositionInterface *GetPositionInterface() const override { return vrv_cast<const PositionInterface *>(this); }
102  StemmedDrawingInterface *GetStemmedDrawingInterface() override { return vrv_cast<StemmedDrawingInterface *>(this); }
103  const StemmedDrawingInterface *GetStemmedDrawingInterface() const override
104  {
105  return vrv_cast<const StemmedDrawingInterface *>(this);
106  }
108 
113  bool HasToBeAligned() const override { return true; }
114 
119  bool IsSupportedChild(ClassId classId) override;
120 
124  bool AddChild(Object *object) override;
125 
129  bool AddChildAdditionalCheck(Object *child) override;
130 
134  void AlignDotsShift(const Note *otherNote);
135 
140  Accid *GetDrawingAccid();
141  const Accid *GetDrawingAccid() const;
143 
149  const Chord *IsChordTone() const;
150  data_DURATION GetDrawingDur() const;
151  bool IsNoteGroupExtreme() const; // used to find if it is the highest or lowest note in a note group
153 
159  const TabGrp *IsTabGrpNote() const;
161 
166  std::u32string GetTabFretString(data_NOTATIONTYPE notationType, int &overline, int &strike, int &underline) const;
168 
173  bool IsUnisonWith(const Note *note, bool ignoreAccid = false) const;
174 
179  void SetNoteGroup(ChordNoteGroup *noteGroup, int position);
180  ChordNoteGroup *GetNoteGroup() { return m_noteGroup; }
181  int GetNoteGroupPosition() const { return m_noteGroupPosition; }
183 
188  void SetFlippedNotehead(bool flippedNotehead) { m_flippedNotehead = flippedNotehead; }
189  bool GetFlippedNotehead() const { return m_flippedNotehead; }
191 
195  int GetDiatonicPitch() const;
196 
202  Point GetStemUpSE(const Doc *doc, int staffSize, bool isCueSize) const override;
203  Point GetStemDownNW(const Doc *doc, int staffSize, bool isCueSize) const override;
204  int CalcStemLenInThirdUnits(const Staff *staff, data_STEMDIRECTION stemDir) const override;
206 
210  char32_t GetMensuralNoteheadGlyph() const;
211 
215  char32_t GetNoteheadGlyph(const data_DURATION duration) const;
216 
220  bool IsEnharmonicWith(const Note *note) const;
221 
225  bool IsVisible() const;
226 
230  int GetMIDIPitch(int shift = 0, int octaveShift = 0) const;
231 
235  int GetPitchClass() const;
236 
241  bool HasStemSameasNote() const { return (m_stemSameas); }
242  Note *GetStemSameasNote() { return m_stemSameas; }
243  const Note *GetStemSameasNote() const { return m_stemSameas; }
244  void SetStemSameasNote(Note *stemSameas) { m_stemSameas = stemSameas; }
246 
251  StemSameasDrawingRole GetStemSameasRole() const { return m_stemSameasRole; }
252  void SetStemSameasRole(StemSameasDrawingRole stemSameasRole) { m_stemSameasRole = stemSameasRole; }
254 
261  data_STEMDIRECTION CalcStemDirForSameasNote(int verticalCenter);
262 
268  void CalcNoteHeadShiftForSameasNote(Note *stemSameas, data_STEMDIRECTION stemDir);
269 
273  virtual bool IsCursor() const { return false; }
274 
275 public:
276  //----------------//
277  // Static methods //
278  //----------------//
279 
284  static bool HandleLedgerLineStemCollision(const Doc *doc, const Staff *staff, const Note *note1, const Note *note2);
285 
289  static int PnameToPclass(data_PITCHNAME pitchName);
290 
296  void UpdateFromTransPitch(const TransPitch &tp, bool hasKeySig);
298 
299  //----------//
300  // Functors //
301  //----------//
302 
307  FunctorCode Accept(Functor &functor) override;
308  FunctorCode Accept(ConstFunctor &functor) const override;
309  FunctorCode AcceptEnd(Functor &functor) override;
310  FunctorCode AcceptEnd(ConstFunctor &functor) const override;
312 
313 protected:
317  MapOfNoteLocs CalcNoteLocations(NotePredicate predicate = NULL) const override;
318 
324  MapOfDotLocs CalcDotLocations(int layerCount, bool primary) const override;
325 
326 private:
330  int GetChromaticAlteration() const;
331 
332 public:
333  //
334 private:
338  bool m_flippedNotehead;
339 
343  ChordNoteGroup *m_noteGroup;
344 
348  int m_noteGroupPosition;
349 
355  Note *m_stemSameas;
356 
364  StemSameasDrawingRole m_stemSameasRole;
365 };
366 
367 //----------------------------------------------------------------------------
368 // DiatonicSort
369 //----------------------------------------------------------------------------
370 
375 
376 public:
377  DiatonicSort() {}
378 
379  bool operator()(const Object *first, const Object *second) const
380  {
381  const Note *n1 = dynamic_cast<const Note *>(first);
382  const Note *n2 = dynamic_cast<const Note *>(second);
383  assert(n1 && n2);
384  return (n1->GetDiatonicPitch() < n2->GetDiatonicPitch());
385  }
386 };
387 
388 //----------------------------------------------------------------------------
389 // TabCourseSort
390 //----------------------------------------------------------------------------
391 
396 
397 public:
398  TabCourseSort() {}
399 
400  bool operator()(const Object *first, const Object *second) const
401  {
402  const Note *n1 = dynamic_cast<const Note *>(first);
403  const Note *n2 = dynamic_cast<const Note *>(second);
404  assert(n1 && n2);
405  return (n1->GetTabCourse() > n2->GetTabCourse());
406  }
407 };
408 
409 } // namespace vrv
410 
411 #endif
This class models the MEI <accid> element.
Definition: accid.h:41
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 class represents a collection of notes in the same layer with the same onset time.
Definition: chord.h:44
This abstract class is the base class for all const functors.
Definition: functor.h:126
Unary predicate for sorting notes by diatonic pitch.
Definition: note.h:374
This class is a hold the data and corresponds to the model of a MVC design pattern.
Definition: doc.h:41
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 models the MEI <note> element.
Definition: note.h:69
MapOfDotLocs CalcDotLocations(int layerCount, bool primary) const override
The dot locations w.r.t.
int GetMIDIPitch(int shift=0, int octaveShift=0) const
MIDI pitch.
void CloneReset() override
Overriding CloneReset() method to be called after copy / assignment calls.
void AlignDotsShift(const Note *otherNote)
Align dots shift for two notes.
TabGrp * IsTabGrpNote()
Return the parent TabGrp is the note is part of one.
StemSameasDrawingRole GetStemSameasRole() const
Getter and setter for stem sameas role.
Definition: note.h:251
bool AddChild(Object *object) override
Overwritten method for note.
int GetDiatonicPitch() const
Returns a single integer representing pitch and octave.
static bool HandleLedgerLineStemCollision(const Doc *doc, const Staff *staff, const Note *note1, const Note *note2)
Assume that two notes from different layers are given occuring at the same time Returns true if one n...
TransPitch GetTransPitch() const
Get and set the pitch for transposition.
bool IsVisible() const
Check if a note or its parent chord are visible.
int GetPitchClass() const
Get pitch class of the current note.
char32_t GetNoteheadGlyph(const data_DURATION duration) const
Return a SMuFL code for the notehead.
bool IsSupportedChild(ClassId classId) override
Add an element (a verse or an accid) to a note.
bool IsUnisonWith(const Note *note, bool ignoreAccid=false) const
Return true if the note is a unison.
bool HasToBeAligned() const override
Override the method since alignment is required.
Definition: note.h:113
data_STEMDIRECTION CalcStemDirForSameasNote(int verticalCenter)
Calculate the stem direction of the pair of notes.
Object * Clone() const override
Method call for copying child classes.
Definition: note.h:78
Point GetStemUpSE(const Doc *doc, int staffSize, bool isCueSize) const override
Get the stem up / stem down attachment point.
bool AddChildAdditionalCheck(Object *child) override
Additional check when adding a child.
MapOfNoteLocs CalcNoteLocations(NotePredicate predicate=NULL) const override
The note locations w.r.t.
bool IsEnharmonicWith(const Note *note) const
Check whether current note is enharmonic with another.
Chord * IsChordTone()
Overriding functions to return information from chord parent if any.
void CalcNoteHeadShiftForSameasNote(Note *stemSameas, data_STEMDIRECTION stemDir)
Set the Note::m_flippedNotehead flag if one of the two notes needs to be placed on the side.
char32_t GetMensuralNoteheadGlyph() const
Return the SMuFL code for a mensural note looking at the staff notation type, the coloration and the ...
FunctorCode Accept(Functor &functor) override
Interface for class functor visitation.
static int PnameToPclass(data_PITCHNAME pitchName)
Get pitch class based on the pitch name.
void Reset() override
Virtual reset method.
virtual bool IsCursor() const
Flag indicator if or Cursor instance.
Definition: note.h:273
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 pitch, such as notes and neumes.
Definition: pitchinterface.h:28
Simple class for representing points.
Definition: devicecontextbase.h:203
This class is an interface for elements with a position on the staff, such as rests.
Definition: positioninterface.h:30
This class represents a staff in a laid-out score (Doc).
Definition: staff.h:110
This class is an interface for MEI stemmed element.
Definition: drawinginterface.h:379
Unary predicate for sorting notes by course number.
Definition: note.h:395
This class models the MEI <tabGrp> element.
Definition: tabgrp.h:24
Definition: transposition.h:35