MuseScore  3.4
Music composition and notation
chord.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2002-2011 Werner Schweer
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2
9 // as published by the Free Software Foundation and appearing in
10 // the file LICENCE.GPL
11 //=============================================================================
12 
13 #ifndef __CHORD_H__
14 #define __CHORD_H__
15 
21 #include <functional>
22 #include "chordrest.h"
23 
24 namespace Ms {
25 
26 class Note;
27 class Hook;
28 class Arpeggio;
29 class Tremolo;
30 class Chord;
31 //class Glissando;
32 class Stem;
33 class Chord;
34 class StemSlash;
35 class LedgerLine;
36 class AccidentalState;
37 
39 
40 //---------------------------------------------------------
41 // @@ Chord
44 //
45 // @P beam Beam the beam of the chord, if any (read only)
46 // @P graceNotes array[Chord] the list of grace note chords (read only)
47 // @P hook Hook the hook of the chord, if any (read only)
48 // @P lyrics array[Lyrics] the list of lyrics (read only)
49 // @P notes array[Note] the list of notes (read only)
50 // @P stem Stem the stem of the chord, if any (read only)
51 // @P stemSlash StemSlash the stem slash of the chord (acciaccatura), if any (read only)
52 // @P stemDirection Direction the stem direction of the chord: AUTO, UP, DOWN (read only)
53 //---------------------------------------------------------
54 
55 class Chord final : public ChordRest {
56  std::vector<Note*> _notes; // sorted to decreasing line step
57  LedgerLine* _ledgerLines; // single linked list
58 
61  StemSlash* _stemSlash; // for acciacatura
62 
66  QVector<Chord*> _graceNotes;
68 
71  bool _noStem;
73 
74  qreal _spaceLw;
75  qreal _spaceRw;
76 
77  QVector<Articulation*> _articulations;
78 
79  virtual qreal upPos() const;
80  virtual qreal downPos() const;
81  qreal centerX() const;
82  void addLedgerLines();
83  void processSiblings(std::function<void(Element*)> func) const;
84 
85  void layoutPitched();
86  void layoutTablature();
87  qreal noteHeadWidth() const;
88 
89  public:
90  Chord(Score* s = 0);
91  Chord(const Chord&, bool link = false);
92  ~Chord();
93  Chord &operator=(const Chord&) = delete;
94 
95  virtual Chord* clone() const { return new Chord(*this, false); }
96  virtual Element* linkedClone() { return new Chord(*this, true); }
97  virtual void undoUnlink() override;
98 
99  virtual void setScore(Score* s) override;
100  virtual ElementType type() const { return ElementType::CHORD; }
101  virtual qreal mag() const;
102 
103  virtual void write(XmlWriter& xml) const override;
104  virtual void read(XmlReader&) override;
105  virtual bool readProperties(XmlReader&) override;
106  virtual Element* drop(EditData&) override;
107 
108  void setStemDirection(Direction d) { _stemDirection = d; }
109  Direction stemDirection() const { return _stemDirection; }
110 
111  LedgerLine* ledgerLines() { return _ledgerLines; }
112 
113  qreal defaultStemLength() const;
114  qreal minAbsStemLength() const;
115 
116  virtual void layoutStem1() override;
117  void layoutStem();
118  void layoutArpeggio2();
119 
120  std::vector<Note*>& notes() { return _notes; }
121  const std::vector<Note*>& notes() const { return _notes; }
122 
123  // Chord has at least one Note
124  Note* upNote() const;
125  Note* downNote() const;
126  virtual int upString() const;
127  virtual int downString() const;
128 
129  qreal maxHeadWidth() const;
130 
131  Note* findNote(int pitch, int skip = 0) const;
132 
133  Stem* stem() const { return _stem; }
134  Arpeggio* arpeggio() const { return _arpeggio; }
135  Tremolo* tremolo() const { return _tremolo; }
136  void setTremolo(Tremolo* t);
137  bool endsGlissando() const { return _endsGlissando; }
138  void setEndsGlissando (bool val) { _endsGlissando = val; }
139  void updateEndsGlissando();
140  StemSlash* stemSlash() const { return _stemSlash; }
141  bool slash();
142  void setSlash(bool flag, bool stemless);
143  virtual void removeMarkings(bool keepTremolo = false) override;
144 
145  const QVector<Chord*>& graceNotes() const { return _graceNotes; }
146  QVector<Chord*>& graceNotes() { return _graceNotes; }
147 
148  QVector<Chord*> graceNotesBefore() const;
149  QVector<Chord*> graceNotesAfter() const;
150 
151  int graceIndex() const { return _graceIndex; }
152  void setGraceIndex(int val) { _graceIndex = val; }
153 
154  virtual int upLine() const;
155  virtual int downLine() const;
156  virtual QPointF stemPos() const;
157  virtual QPointF stemPosBeam() const;
158  virtual qreal stemPosX() const;
159 
160  bool underBeam() const;
161  Hook* hook() const { return _hook; }
162 
163  //@ add an element to the Chord
164  Q_INVOKABLE virtual void add(Ms::Element*);
165  //@ remove the element from the Chord
166  Q_INVOKABLE virtual void remove(Ms::Element*);
167 
168  Note* selectedNote() const;
169  virtual void layout();
170  virtual QPointF pagePos() const override;
171  void layout2();
172  void cmdUpdateNotes(AccidentalState*);
173 
174  NoteType noteType() const { return _noteType; }
175  void setNoteType(NoteType t) { _noteType = t; }
176  bool isGrace() const { return _noteType != NoteType::NORMAL; }
177  void toGraceAfter();
178  virtual void scanElements(void* data, void (*func)(void*, Element*), bool all=true) override;
179 
180  virtual void setTrack(int val) override;
181 
182  virtual void computeUp() override;
183 
184  qreal dotPosX() const;
185 
186  bool noStem() const { return _noStem; }
187  void setNoStem(bool val) { _noStem = val; }
188 
189  PlayEventType playEventType() const { return _playEventType; }
190  void setPlayEventType(PlayEventType v) { _playEventType = v; }
191  QList<NoteEventList> getNoteEventLists();
192  void setNoteEventLists(QList<NoteEventList>& nel);
193 
194  TremoloChordType tremoloChordType() const;
195 
196  void layoutArticulations();
197  void layoutArticulations2();
198  void layoutArticulations3(Slur* s);
199 
200  QVector<Articulation*>& articulations() { return _articulations; }
201  const QVector<Articulation*>& articulations() const { return _articulations; }
202  Articulation* hasArticulation(const Articulation*);
203  bool hasSingleArticulation() const { return _articulations.size() == 1; }
204 
205  virtual void crossMeasureSetup(bool on);
206 
207  virtual void localSpatiumChanged(qreal oldValue, qreal newValue) override;
208  virtual QVariant getProperty(Pid propertyId) const override;
209  virtual bool setProperty(Pid propertyId, const QVariant&) override;
210  virtual QVariant propertyDefault(Pid) const override;
211 
212  virtual void reset();
213 
214  virtual Segment* segment() const;
215  virtual Measure* measure() const;
216 
217  void sortNotes();
218 
219  Chord* nextTiedChord(bool backwards = false, bool sameSize = true);
220 
221  virtual Element* nextElement() override;
222  virtual Element* prevElement() override;
223  virtual Element* nextSegmentElement() override;
224  virtual Element* lastElementBeforeSegment();
225  virtual Element* prevSegmentElement() override;
226  virtual QString accessibleExtraInfo() const override;
227 
228  virtual Shape shape() const override;
229  };
230 
231 
232 } // namespace Ms
233 #endif
234 
StemSlash * stemSlash() const
Definition: chord.h:140
bool noStem() const
Definition: chord.h:186
virtual Chord * clone() const
Definition: chord.h:95
QVector< Articulation * > _articulations
Definition: chord.h:77
Direction stemDirection() const
Definition: chord.h:109
Tremolo * _tremolo
Definition: chord.h:64
Pid
Definition: property.h:62
Definition: xml.h:67
void setPlayEventType(PlayEventType v)
Definition: chord.h:190
PlayEventType playEventType() const
Definition: chord.h:189
Graphic representation of a note stem.
Definition: stem.h:27
bool _endsGlissando
true if this chord is the ending point of a glissando (needed for layout)
Definition: chord.h:65
one measure in a system
Definition: measure.h:65
void setGraceIndex(int val)
Definition: chord.h:152
bool endsGlissando() const
Definition: chord.h:137
Definition: slur.h:55
Definition: tremolo.h:39
Arpeggio * arpeggio() const
Definition: chord.h:134
QVector< Chord * > _graceNotes
Definition: chord.h:66
std::vector< Note * > _notes
Definition: chord.h:56
NoteType noteType() const
Definition: chord.h:174
Base class of score layout elements.
Definition: element.h:158
Definition: key.h:134
PlayEventType _playEventType
play events were modified by user
Definition: chord.h:72
int graceIndex() const
Definition: chord.h:151
Stem * _stem
Definition: chord.h:59
Definition: score.h:391
PlayEventType
Determines whether oranaments are automatically generated when playing a score and whether the PlayEv...
Definition: types.h:489
Definition: arpeggio.h:30
QVector< Chord * > & graceNotes()
Definition: chord.h:146
const std::vector< Note * > & notes() const
Definition: chord.h:121
virtual Element * linkedClone()
Definition: chord.h:96
NoteType _noteType
mark grace notes: acciaccatura and appoggiatura
Definition: chord.h:70
Hook * _hook
Definition: chord.h:60
Hook * hook() const
Definition: chord.h:161
qreal _spaceLw
Definition: chord.h:74
bool _noStem
Definition: chord.h:71
virtual ElementType type() const
Definition: chord.h:100
bool isGrace() const
Definition: chord.h:176
articulation marks
Definition: articulation.h:57
void setNoStem(bool val)
Definition: chord.h:187
used for grace notes of type acciaccatura
Definition: stemslash.h:26
Arpeggio * _arpeggio
Definition: chord.h:63
Definition: segment.h:50
StemSlash * _stemSlash
Definition: chord.h:61
int _graceIndex
if this is a grace note, index in parent list
Definition: chord.h:67
Definition: aeolus.cpp:26
void setEndsGlissando(bool val)
Definition: chord.h:138
TremoloChordType
Definition: chord.h:38
Stem * stem() const
Definition: chord.h:133
Definition: xml.h:218
Definition: hook.h:26
NoteType
Definition: types.h:255
Tremolo * tremolo() const
Definition: chord.h:135
void setStemDirection(Direction d)
Definition: chord.h:108
Graphic representation of a chord.
Definition: chord.h:55
Direction _stemDirection
Definition: chord.h:69
Definition: chordrest.h:48
const QVector< Chord * > & graceNotes() const
Definition: chord.h:145
Direction
Definition: types.h:282
Definition: element.h:111
qreal _spaceRw
Definition: chord.h:75
QVector< Articulation * > & articulations()
Definition: chord.h:200
LedgerLine * _ledgerLines
Definition: chord.h:57
bool hasSingleArticulation() const
Definition: chord.h:203
LedgerLine * ledgerLines()
Definition: chord.h:111
Definition: shape.h:42
Graphic representation of a note.
Definition: note.h:212
Graphic representation of a ledger line.
Definition: ledgerline.h:31
ElementType
Definition: types.h:34
void setNoteType(NoteType t)
Definition: chord.h:175
Pid propertyId(const QStringRef &s)
Definition: property.cpp:347
const QVector< Articulation * > & articulations() const
Definition: chord.h:201
std::vector< Note * > & notes()
Definition: chord.h:120