File: chord.h

package info (click to toggle)
musescore3 3.2.3%2Bdfsg2-11
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 210,672 kB
  • sloc: cpp: 291,093; xml: 200,238; sh: 3,779; ansic: 1,447; python: 393; makefile: 240; perl: 82; pascal: 79
file content (238 lines) | stat: -rw-r--r-- 8,910 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
//=============================================================================
//  MuseScore
//  Music Composition & Notation
//
//  Copyright (C) 2002-2011 Werner Schweer
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License version 2
//  as published by the Free Software Foundation and appearing in
//  the file LICENCE.GPL
//=============================================================================

#ifndef __CHORD_H__
#define __CHORD_H__

/**
 \file
 Definition of classes Chord, HelpLine and NoteList.
*/

#include <functional>
#include "chordrest.h"

namespace Ms {

class Note;
class Hook;
class Arpeggio;
class Tremolo;
class Chord;
//class Glissando;
class Stem;
class Chord;
class StemSlash;
class LedgerLine;
class AccidentalState;

enum class TremoloChordType : char { TremoloSingle, TremoloFirstNote, TremoloSecondNote };
enum class PlayEventType : char    {
      Auto,       // Play events for all notes are calculated by MuseScore.
      User,       // Some play events are modified by user. The events must be written into the mscx file.
      InvalidUser // The user modified play events must be replaced by MuseScore generated ones on
                  // next recalculation. The actual play events must be saved on the undo stack.
      };

//---------------------------------------------------------
//   @@ Chord
///    Graphic representation of a chord.
///    Single notes are handled as degenerated chords.
//
//   @P beam          Beam          the beam of the chord, if any (read only)
//   @P graceNotes    array[Chord]  the list of grace note chords (read only)
//   @P hook          Hook          the hook of the chord, if any (read only)
//   @P lyrics        array[Lyrics] the list of lyrics (read only)
//   @P notes         array[Note]   the list of notes (read only)
//   @P stem          Stem          the stem of the chord, if any (read only)
//   @P stemSlash     StemSlash     the stem slash of the chord (acciaccatura), if any (read only)
//   @P stemDirection Direction     the stem direction of the chord: AUTO, UP, DOWN (read only)
//---------------------------------------------------------

class Chord final : public ChordRest {
      std::vector<Note*>   _notes;       // sorted to decreasing line step
      LedgerLine*          _ledgerLines; // single linked list

      Stem*               _stem;
      Hook*               _hook;
      StemSlash*          _stemSlash;    // for acciacatura

      Arpeggio*           _arpeggio;
      Tremolo*            _tremolo;
      bool                _endsGlissando;///< true if this chord is the ending point of a glissando (needed for layout)
      QVector<Chord*>     _graceNotes;
      int                 _graceIndex;   ///< if this is a grace note, index in parent list

      Direction          _stemDirection;
      NoteType           _noteType;      ///< mark grace notes: acciaccatura and appoggiatura
      bool               _noStem;
      PlayEventType      _playEventType; ///< play events were modified by user

      qreal _spaceLw;
      qreal _spaceRw;

      QVector<Articulation*> _articulations;

      virtual qreal upPos()   const;
      virtual qreal downPos() const;
      qreal centerX() const;
      void addLedgerLines();
      void processSiblings(std::function<void(Element*)> func) const;

      void layoutPitched();
      void layoutTablature();
      qreal noteHeadWidth() const;

   public:
      Chord(Score* s = 0);
      Chord(const Chord&, bool link = false);
      ~Chord();
      Chord &operator=(const Chord&) = delete;

      virtual Chord* clone() const       { return new Chord(*this, false); }
      virtual Element* linkedClone()     { return new Chord(*this, true); }
      virtual void undoUnlink() override;

      virtual void setScore(Score* s) override;
      virtual ElementType type() const         { return ElementType::CHORD; }
      virtual qreal mag() const;

      virtual void write(XmlWriter& xml) const override;
      virtual void read(XmlReader&) override;
      virtual bool readProperties(XmlReader&) override;
      virtual Element* drop(EditData&) override;

      void setStemDirection(Direction d) { _stemDirection = d; }
      Direction stemDirection() const    { return _stemDirection; }

      LedgerLine* ledgerLines()                  { return _ledgerLines; }

      qreal defaultStemLength() const;
      qreal minAbsStemLength() const;

      virtual void layoutStem1() override;
      void layoutStem();
      void layoutArpeggio2();

      std::vector<Note*>& notes()                 { return _notes; }
      const std::vector<Note*>& notes() const     { return _notes; }

      // Chord has at least one Note
      Note* upNote() const;
      Note* downNote() const;
      virtual int upString() const;
      virtual int downString() const;

      qreal maxHeadWidth() const;

      Note* findNote(int pitch) const;

      Stem* stem() const                     { return _stem; }
      Arpeggio* arpeggio() const             { return _arpeggio;  }
      Tremolo* tremolo() const               { return _tremolo;   }
      void setTremolo(Tremolo* t);
      bool endsGlissando() const             { return _endsGlissando; }
      void setEndsGlissando (bool val)       { _endsGlissando = val; }
      void updateEndsGlissando();
      StemSlash* stemSlash() const           { return _stemSlash; }
      bool slash();
      void setSlash(bool flag, bool stemless);
      virtual void removeMarkings(bool keepTremolo = false) override;

      const QVector<Chord*>& graceNotes() const { return _graceNotes; }
      QVector<Chord*>& graceNotes()             { return _graceNotes; }

      QVector<Chord*> graceNotesBefore() const;
      QVector<Chord*> graceNotesAfter() const;

      int graceIndex() const                        { return _graceIndex; }
      void setGraceIndex(int val)                   { _graceIndex = val;  }

      virtual int upLine() const;
      virtual int downLine() const;
      virtual QPointF stemPos() const;          ///< page coordinates
      virtual QPointF stemPosBeam() const;      ///< page coordinates
      virtual qreal stemPosX() const;

      bool underBeam() const;
      Hook* hook() const                     { return _hook; }

      //@ add an element to the Chord
      Q_INVOKABLE virtual void add(Ms::Element*);
      //@ remove the element from the Chord
      Q_INVOKABLE virtual void remove(Ms::Element*);

      Note* selectedNote() const;
      virtual void layout();
      virtual QPointF pagePos() const override;      ///< position in page coordinates
      void layout2();
      void cmdUpdateNotes(AccidentalState*);

      NoteType noteType() const       { return _noteType; }
      void setNoteType(NoteType t)    { _noteType = t; }
      bool isGrace() const            { return _noteType != NoteType::NORMAL; }
      void toGraceAfter();
      virtual void scanElements(void* data, void (*func)(void*, Element*), bool all=true) override;

      virtual void setTrack(int val) override;

      virtual void computeUp() override;

      qreal dotPosX() const;

      bool noStem() const                           { return _noStem;  }
      void setNoStem(bool val)                      { _noStem = val;   }

      PlayEventType playEventType() const           { return _playEventType; }
      void setPlayEventType(PlayEventType v)        { _playEventType = v;    }

      TremoloChordType tremoloChordType() const;

      void layoutArticulations();
      void layoutArticulations2();
      void layoutArticulations3(Slur* s);

      QVector<Articulation*>& articulations()             { return _articulations; }
      const QVector<Articulation*>& articulations() const { return _articulations; }
      Articulation* hasArticulation(const Articulation*);
      bool hasSingleArticulation() const                  { return _articulations.size() == 1; }

      virtual void crossMeasureSetup(bool on);

      virtual void localSpatiumChanged(qreal oldValue, qreal newValue) override;
      virtual QVariant getProperty(Pid propertyId) const override;
      virtual bool setProperty(Pid propertyId, const QVariant&) override;
      virtual QVariant propertyDefault(Pid) const override;

      virtual void reset();

      virtual Segment* segment() const;
      virtual Measure* measure() const;

      void sortNotes();

      Chord* nextTiedChord(bool backwards = false, bool sameSize = true);

      virtual Element* nextElement() override;
      virtual Element* prevElement() override;
      virtual Element* nextSegmentElement() override;
      virtual Element* lastElementBeforeSegment();
      virtual Element* prevSegmentElement() override;
      virtual QString accessibleExtraInfo() const override;

      virtual Shape shape() const override;
      };


}     // namespace Ms
#endif