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 "pitchinterface.h"
28 #include "transposition.h"
29 
30 namespace vrv {
31 
32 class Accid;
33 class Chord;
34 class Note;
35 class Slur;
36 class TabGrp;
37 class Tie;
38 class Verse;
39 
40 //----------------------------------------------------------------------------
41 // Note
42 //----------------------------------------------------------------------------
43 
47 class Note : public LayerElement,
49  public AltSymInterface,
50  public DurationInterface,
51  public PitchInterface,
52  public PositionInterface,
53  public AttColor,
54  public AttColoration,
55  public AttCue,
56  public AttExtSymAuth,
57  public AttExtSymNames,
58  public AttGraced,
59  public AttHarmonicFunction,
60  public AttMidiVelocity,
61  public AttNoteHeads,
62  public AttNoteVisMensural,
63  public AttStems,
64  public AttStemsCmn,
65  public AttStringtab,
66  public AttTiePresent,
67  public AttVisibility {
68 public:
74  Note();
75  virtual ~Note();
76  Object *Clone() const override { return new Note(*this); }
77  void Reset() override;
78  std::string GetClassName() const override { return "note"; }
80 
85  AltSymInterface *GetAltSymInterface() override { return vrv_cast<AltSymInterface *>(this); }
86  const AltSymInterface *GetAltSymInterface() const override { return vrv_cast<const AltSymInterface *>(this); }
87  DurationInterface *GetDurationInterface() override { return vrv_cast<DurationInterface *>(this); }
88  const DurationInterface *GetDurationInterface() const override { return vrv_cast<const DurationInterface *>(this); }
89  PitchInterface *GetPitchInterface() override { return vrv_cast<PitchInterface *>(this); }
90  const PitchInterface *GetPitchInterface() const override { return vrv_cast<const PitchInterface *>(this); }
91  PositionInterface *GetPositionInterface() override { return vrv_cast<PositionInterface *>(this); }
92  const PositionInterface *GetPositionInterface() const override { return vrv_cast<const PositionInterface *>(this); }
93  StemmedDrawingInterface *GetStemmedDrawingInterface() override { return vrv_cast<StemmedDrawingInterface *>(this); }
94  const StemmedDrawingInterface *GetStemmedDrawingInterface() const override
95  {
96  return vrv_cast<const StemmedDrawingInterface *>(this);
97  }
99 
104  bool HasToBeAligned() const override { return true; }
105 
110  bool IsSupportedChild(ClassId classId) override;
111 
115  void AddChild(Object *object) override;
116 
120  bool AddChildAdditionalCheck(Object *child) override;
121 
125  void AlignDotsShift(const Note *otherNote);
126 
131  Accid *GetDrawingAccid();
132  const Accid *GetDrawingAccid() const;
134 
140  const Chord *IsChordTone() const;
141  data_DURATION GetDrawingDur() const;
142  bool IsNoteGroupExtreme() const; // used to find if it is the highest or lowest note in a note group
144 
150  const TabGrp *IsTabGrpNote() const;
152 
157  std::u32string GetTabFretString(data_NOTATIONTYPE notationType, int &overline, int &strike, int &underline) const;
159 
164  bool IsUnisonWith(const Note *note, bool ignoreAccid = false) const;
165 
170  void SetNoteGroup(ChordNoteGroup *noteGroup, int position);
171  ChordNoteGroup *GetNoteGroup() { return m_noteGroup; }
172  int GetNoteGroupPosition() const { return m_noteGroupPosition; }
174 
179  void SetFlippedNotehead(bool flippedNotehead) { m_flippedNotehead = flippedNotehead; }
180  bool GetFlippedNotehead() const { return m_flippedNotehead; }
182 
186  int GetDiatonicPitch() const;
187 
193  Point GetStemUpSE(const Doc *doc, int staffSize, bool isCueSize) const override;
194  Point GetStemDownNW(const Doc *doc, int staffSize, bool isCueSize) const override;
195  int CalcStemLenInThirdUnits(const Staff *staff, data_STEMDIRECTION stemDir) const override;
197 
201  char32_t GetMensuralNoteheadGlyph() const;
202 
206  char32_t GetNoteheadGlyph(const data_DURATION duration) const;
207 
211  bool IsEnharmonicWith(const Note *note) const;
212 
216  bool IsVisible() const;
217 
221  int GetMIDIPitch(int shift = 0, int octaveShift = 0) const;
222 
226  int GetPitchClass() const;
227 
232  bool HasStemSameasNote() const { return (m_stemSameas); }
233  Note *GetStemSameasNote() { return m_stemSameas; }
234  const Note *GetStemSameasNote() const { return m_stemSameas; }
235  void SetStemSameasNote(Note *stemSameas) { m_stemSameas = stemSameas; }
237 
242  StemSameasDrawingRole GetStemSameasRole() const { return m_stemSameasRole; }
243  void SetStemSameasRole(StemSameasDrawingRole stemSameasRole) { m_stemSameasRole = stemSameasRole; }
245 
252  data_STEMDIRECTION CalcStemDirForSameasNote(int verticalCenter);
253 
259  void CalcNoteHeadShiftForSameasNote(Note *stemSameas, data_STEMDIRECTION stemDir);
260 
261 public:
262  //----------------//
263  // Static methods //
264  //----------------//
265 
270  static bool HandleLedgerLineStemCollision(const Doc *doc, const Staff *staff, const Note *note1, const Note *note2);
271 
275  static int PnameToPclass(data_PITCHNAME pitchName);
276 
282  void UpdateFromTransPitch(const TransPitch &tp, bool hasKeySig);
284 
285  //----------//
286  // Functors //
287  //----------//
288 
293  FunctorCode Accept(Functor &functor) override;
294  FunctorCode Accept(ConstFunctor &functor) const override;
295  FunctorCode AcceptEnd(Functor &functor) override;
296  FunctorCode AcceptEnd(ConstFunctor &functor) const override;
298 
299 protected:
303  MapOfNoteLocs CalcNoteLocations(NotePredicate predicate = NULL) const override;
304 
310  MapOfDotLocs CalcDotLocations(int layerCount, bool primary) const override;
311 
312 private:
316  int GetChromaticAlteration() const;
317 
318 public:
319  //
320 private:
324  bool m_flippedNotehead;
325 
329  ChordNoteGroup *m_noteGroup;
330 
334  int m_noteGroupPosition;
335 
341  Note *m_stemSameas;
342 
350  StemSameasDrawingRole m_stemSameasRole;
351 };
352 
353 //----------------------------------------------------------------------------
354 // DiatonicSort
355 //----------------------------------------------------------------------------
356 
361 
362 public:
363  DiatonicSort() {}
364 
365  bool operator()(const Object *first, const Object *second) const
366  {
367  const Note *n1 = dynamic_cast<const Note *>(first);
368  const Note *n2 = dynamic_cast<const Note *>(second);
369  assert(n1 && n2);
370  return (n1->GetDiatonicPitch() < n2->GetDiatonicPitch());
371  }
372 };
373 
374 //----------------------------------------------------------------------------
375 // TabCourseSort
376 //----------------------------------------------------------------------------
377 
382 
383 public:
384  TabCourseSort() {}
385 
386  bool operator()(const Object *first, const Object *second) const
387  {
388  const Note *n1 = dynamic_cast<const Note *>(first);
389  const Note *n2 = dynamic_cast<const Note *>(second);
390  assert(n1 && n2);
391  return (n1->GetTabCourse() > n2->GetTabCourse());
392  }
393 };
394 
395 } // namespace vrv
396 
397 #endif
This class models the MEI <accid> element.
Definition: accid.h:37
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:360
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:67
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:242
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:104
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:76
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.
void AddChild(Object *object) override
Overwritten method for note.
This class represents a basic object.
Definition: object.h:61
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:381
This class models the MEI <tabGrp> element.
Definition: tabgrp.h:23
Definition: transposition.h:35