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 
87  AltSymInterface *GetAltSymInterface() override { return vrv_cast<AltSymInterface *>(this); }
88  const AltSymInterface *GetAltSymInterface() const override { return vrv_cast<const AltSymInterface *>(this); }
89  DurationInterface *GetDurationInterface() override { return vrv_cast<DurationInterface *>(this); }
90  const DurationInterface *GetDurationInterface() const override { return vrv_cast<const DurationInterface *>(this); }
91  OffsetInterface *GetOffsetInterface() override { return vrv_cast<OffsetInterface *>(this); }
92  const OffsetInterface *GetOffsetInterface() const override { return vrv_cast<const OffsetInterface *>(this); }
93  PitchInterface *GetPitchInterface() override { return vrv_cast<PitchInterface *>(this); }
94  const PitchInterface *GetPitchInterface() const override { return vrv_cast<const PitchInterface *>(this); }
95  PositionInterface *GetPositionInterface() override { return vrv_cast<PositionInterface *>(this); }
96  const PositionInterface *GetPositionInterface() const override { return vrv_cast<const PositionInterface *>(this); }
97  StemmedDrawingInterface *GetStemmedDrawingInterface() override { return vrv_cast<StemmedDrawingInterface *>(this); }
98  const StemmedDrawingInterface *GetStemmedDrawingInterface() const override
99  {
100  return vrv_cast<const StemmedDrawingInterface *>(this);
101  }
103 
108  bool HasToBeAligned() const override { return true; }
109 
114  bool IsSupportedChild(ClassId classId) override;
115 
119  bool AddChild(Object *object) override;
120 
124  bool AddChildAdditionalCheck(Object *child) override;
125 
129  void AlignDotsShift(const Note *otherNote);
130 
135  Accid *GetDrawingAccid();
136  const Accid *GetDrawingAccid() const;
138 
144  const Chord *IsChordTone() const;
145  data_DURATION GetDrawingDur() const;
146  bool IsNoteGroupExtreme() const; // used to find if it is the highest or lowest note in a note group
148 
154  const TabGrp *IsTabGrpNote() const;
156 
161  std::u32string GetTabFretString(data_NOTATIONTYPE notationType, int &overline, int &strike, int &underline) const;
163 
168  bool IsUnisonWith(const Note *note, bool ignoreAccid = false) const;
169 
174  void SetNoteGroup(ChordNoteGroup *noteGroup, int position);
175  ChordNoteGroup *GetNoteGroup() { return m_noteGroup; }
176  int GetNoteGroupPosition() const { return m_noteGroupPosition; }
178 
183  void SetFlippedNotehead(bool flippedNotehead) { m_flippedNotehead = flippedNotehead; }
184  bool GetFlippedNotehead() const { return m_flippedNotehead; }
186 
190  int GetDiatonicPitch() const;
191 
197  Point GetStemUpSE(const Doc *doc, int staffSize, bool isCueSize) const override;
198  Point GetStemDownNW(const Doc *doc, int staffSize, bool isCueSize) const override;
199  int CalcStemLenInThirdUnits(const Staff *staff, data_STEMDIRECTION stemDir) const override;
201 
205  char32_t GetMensuralNoteheadGlyph() const;
206 
210  char32_t GetNoteheadGlyph(const data_DURATION duration) const;
211 
215  bool IsEnharmonicWith(const Note *note) const;
216 
220  bool IsVisible() const;
221 
225  int GetMIDIPitch(int shift = 0, int octaveShift = 0) const;
226 
230  int GetPitchClass() const;
231 
236  bool HasStemSameasNote() const { return (m_stemSameas); }
237  Note *GetStemSameasNote() { return m_stemSameas; }
238  const Note *GetStemSameasNote() const { return m_stemSameas; }
239  void SetStemSameasNote(Note *stemSameas) { m_stemSameas = stemSameas; }
241 
246  StemSameasDrawingRole GetStemSameasRole() const { return m_stemSameasRole; }
247  void SetStemSameasRole(StemSameasDrawingRole stemSameasRole) { m_stemSameasRole = stemSameasRole; }
249 
256  data_STEMDIRECTION CalcStemDirForSameasNote(int verticalCenter);
257 
263  void CalcNoteHeadShiftForSameasNote(Note *stemSameas, data_STEMDIRECTION stemDir);
264 
265 public:
266  //----------------//
267  // Static methods //
268  //----------------//
269 
274  static bool HandleLedgerLineStemCollision(const Doc *doc, const Staff *staff, const Note *note1, const Note *note2);
275 
279  static int PnameToPclass(data_PITCHNAME pitchName);
280 
286  void UpdateFromTransPitch(const TransPitch &tp, bool hasKeySig);
288 
289  //----------//
290  // Functors //
291  //----------//
292 
297  FunctorCode Accept(Functor &functor) override;
298  FunctorCode Accept(ConstFunctor &functor) const override;
299  FunctorCode AcceptEnd(Functor &functor) override;
300  FunctorCode AcceptEnd(ConstFunctor &functor) const override;
302 
303 protected:
307  MapOfNoteLocs CalcNoteLocations(NotePredicate predicate = NULL) const override;
308 
314  MapOfDotLocs CalcDotLocations(int layerCount, bool primary) const override;
315 
316 private:
320  int GetChromaticAlteration() const;
321 
322 public:
323  //
324 private:
328  bool m_flippedNotehead;
329 
333  ChordNoteGroup *m_noteGroup;
334 
338  int m_noteGroupPosition;
339 
345  Note *m_stemSameas;
346 
354  StemSameasDrawingRole m_stemSameasRole;
355 };
356 
357 //----------------------------------------------------------------------------
358 // DiatonicSort
359 //----------------------------------------------------------------------------
360 
365 
366 public:
367  DiatonicSort() {}
368 
369  bool operator()(const Object *first, const Object *second) const
370  {
371  const Note *n1 = dynamic_cast<const Note *>(first);
372  const Note *n2 = dynamic_cast<const Note *>(second);
373  assert(n1 && n2);
374  return (n1->GetDiatonicPitch() < n2->GetDiatonicPitch());
375  }
376 };
377 
378 //----------------------------------------------------------------------------
379 // TabCourseSort
380 //----------------------------------------------------------------------------
381 
386 
387 public:
388  TabCourseSort() {}
389 
390  bool operator()(const Object *first, const Object *second) const
391  {
392  const Note *n1 = dynamic_cast<const Note *>(first);
393  const Note *n2 = dynamic_cast<const Note *>(second);
394  assert(n1 && n2);
395  return (n1->GetTabCourse() > n2->GetTabCourse());
396  }
397 };
398 
399 } // namespace vrv
400 
401 #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:364
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 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:246
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:108
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.
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 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:107
This class is an interface for MEI stemmed element.
Definition: drawinginterface.h:353
Unary predicate for sorting notes by course number.
Definition: note.h:385
This class models the MEI <tabGrp> element.
Definition: tabgrp.h:24
Definition: transposition.h:35