MuseScore  3.4
Music composition and notation
chordrest.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 __CHORDREST_H__
14 #define __CHORDREST_H__
15 
16 #include <functional>
17 #include "symbol.h"
18 #include "duration.h"
19 #include "beam.h"
20 #include "shape.h"
21 
22 namespace Ms {
23 
24 enum class CrossMeasure : signed char {
25  UNKNOWN = -1,
26  NONE = 0,
27  FIRST,
28  SECOND
29  };
30 
31 class Score;
32 class Measure;
33 class Tuplet;
34 class Segment;
35 class Slur;
36 class Articulation;
37 class Lyrics;
38 class TabDurationSymbol;
39 class Spanner;
40 enum class SegmentType;
41 
42 //-------------------------------------------------------------------
43 // ChordRest
44 // Virtual base class. Chords and rests can be part of a beam
45 //
46 //-------------------------------------------------------------------
47 
48 class ChordRest : public DurationElement {
51  int _staffMove; // -1, 0, +1, used for crossbeaming
52 
53  void processSiblings(std::function<void(Element*)> func);
54 
55  protected:
56  std::vector<Lyrics*> _lyrics;
57  TabDurationSymbol* _tabDur; // stores a duration symbol in tablature staves
58 
61  bool _up; // actual stem direction
62  bool _small;
63 
64  // CrossMeasure: combine 2 tied notes if across a bar line and can be combined in a single duration
67 
68  public:
69  ChordRest(Score*);
70  ChordRest(const ChordRest&, bool link = false);
71  ChordRest &operator=(const ChordRest&) = delete;
72  ~ChordRest();
73 
74  virtual ElementType type() const = 0;
75 
76  virtual Element* drop(EditData&) override;
77  virtual void undoUnlink() override;
78 
79  virtual Segment* segment() const { return (Segment*)parent(); }
80  virtual Measure* measure() const = 0;
81 
82  virtual void writeProperties(XmlWriter& xml) const;
83  virtual bool readProperties(XmlReader&);
84  virtual void readAddConnector(ConnectorInfoReader* info, bool pasteMode) override;
85  virtual void scanElements(void* data, void (*func)(void*, Element*), bool all=true) override;
86 
87  void setBeamMode(Beam::Mode m) { _beamMode = m; }
88  void undoSetBeamMode(Beam::Mode m);
89  Beam::Mode beamMode() const { return _beamMode; }
90 
91  void setBeam(Beam* b);
92  virtual Beam* beam() const final { return _beam; }
93  int beams() const { return _durationType.hooks(); }
94  virtual qreal upPos() const = 0;
95  virtual qreal downPos() const = 0;
96 
97  int line(bool up) const { return up ? upLine() : downLine(); }
98  int line() const { return _up ? upLine() : downLine(); }
99  virtual int upLine() const = 0;
100  virtual int downLine() const = 0;
101  virtual QPointF stemPos() const = 0;
102  virtual qreal stemPosX() const = 0;
103  virtual QPointF stemPosBeam() const = 0;
104 
105  bool up() const { return _up; }
106  void setUp(bool val) { _up = val; }
107 
108 
109  bool small() const { return _small; }
110  void setSmall(bool val);
111  void undoSetSmall(bool val);
112 
113  int staffMove() const { return _staffMove; }
114  void setStaffMove(int val) { _staffMove = val; }
115  virtual int vStaffIdx() const override { return staffIdx() + _staffMove; }
116 
117  const TDuration durationType() const { return _crossMeasure == CrossMeasure::FIRST ?
118  _crossMeasureTDur : _durationType; }
119 
120  const TDuration actualDurationType() const { return _durationType; }
121  void setDurationType(TDuration::DurationType t);
122  void setDurationType(const QString& s);
123  void setDurationType(const Fraction& ticks);
124  void setDurationType(TDuration v);
125  void setDots(int n) { _durationType.setDots(n); }
126  int dots() const { return _crossMeasure == CrossMeasure::FIRST ? _crossMeasureTDur.dots()
127  : (_crossMeasure == CrossMeasure::SECOND ? 0 : _durationType.dots()); }
128  int actualDots() const { return _durationType.dots(); }
129  Fraction durationTypeTicks() { return _crossMeasure == CrossMeasure::FIRST ? _crossMeasureTDur.ticks() : _durationType.ticks(); }
130  QString durationUserName() const;
131 
132  virtual void setTrack(int val) override;
133 
134  const std::vector<Lyrics*>& lyrics() const { return _lyrics; }
135  std::vector<Lyrics*>& lyrics() { return _lyrics; }
136  Lyrics* lyrics(int verse, Placement) const;
137  int lastVerse(Placement) const;
138 
139  virtual void add(Element*);
140  virtual void remove(Element*);
141  void removeDeleteBeam(bool beamed);
142 
143  ElementList& el() { return _el; }
144  const ElementList& el() const { return _el; }
145 
146  CrossMeasure crossMeasure() const { return _crossMeasure; }
147  void setCrossMeasure(CrossMeasure val) { _crossMeasure = val; }
148  virtual void crossMeasureSetup(bool /*on*/) { }
149  // the following two functions should not be used, unless absolutely necessary;
150  // the cross-measure duration is best managed through setDuration() and crossMeasureSetup()
151  TDuration crossMeasureDurationType() const { return _crossMeasureTDur; }
152  void setCrossMeasureDurationType(TDuration v) { _crossMeasureTDur = v; }
153 
154  virtual void localSpatiumChanged(qreal oldValue, qreal newValue) override;
155  virtual QVariant getProperty(Pid propertyId) const override;
156  virtual bool setProperty(Pid propertyId, const QVariant&) override;
157  virtual QVariant propertyDefault(Pid) const override;
158  bool isGrace() const;
159  bool isGraceBefore() const;
160  bool isGraceAfter() const;
161  void writeBeam(XmlWriter& xml) const;
162  Segment* nextSegmentAfterCR(SegmentType types) const;
163 
164  virtual void setScore(Score* s) override;
165  Element* nextArticulationOrLyric(Element* e);
166  Element* prevArticulationOrLyric(Element* e);
167  virtual Element* nextElement() override;
168  virtual Element* prevElement() override;
169  Element* lastElementBeforeSegment();
170  virtual Element* nextSegmentElement() override;
171  virtual Element* prevSegmentElement() override;
172  virtual QString accessibleExtraInfo() const override;
173  virtual Shape shape() const override;
174  virtual void layoutStem1() {};
175  virtual void computeUp() { _up = true; };
176 
177  bool isFullMeasureRest() const { return _durationType == TDuration::DurationType::V_MEASURE; }
178  virtual void removeMarkings(bool keepTremolo = false);
179 
180  bool isBefore(const ChordRest*) const;
181 
182  void undoAddAnnotation(Element*);
183  };
184 
185 
186 } // namespace Ms
187 #endif
188 
Helper class for reading beams, tuplets and spanners.
Definition: connector.h:96
Definition: durationtype.h:28
int line(bool up) const
Definition: chordrest.h:97
bool up() const
Definition: chordrest.h:105
void setUp(bool val)
Definition: chordrest.h:106
const ElementList & el() const
Definition: chordrest.h:144
Definition: beam.h:37
Pid
Definition: property.h:62
const std::vector< Lyrics * > & lyrics() const
Definition: chordrest.h:134
Definition: xml.h:67
std::vector< Lyrics * > & lyrics()
Definition: chordrest.h:135
Virtual base class for slurs, ties, lines etc.
Definition: spanner.h:136
one measure in a system
Definition: measure.h:65
Definition: slur.h:55
virtual Segment * segment() const
Definition: chordrest.h:79
DurationType
Definition: durationtype.h:30
TDuration _crossMeasureTDur
the total Duration type of the combined notes
Definition: chordrest.h:66
const TDuration durationType() const
Definition: chordrest.h:117
ElementList & el()
Definition: chordrest.h:143
TabDurationSymbol * _tabDur
Definition: chordrest.h:57
Base class of score layout elements.
Definition: element.h:158
Definition: stafftype.h:420
int line() const
Definition: chordrest.h:98
int actualDots() const
Definition: chordrest.h:128
Definition: element.h:517
Beam::Mode _beamMode
Definition: chordrest.h:60
int _staffMove
Definition: chordrest.h:51
bool _up
Definition: chordrest.h:61
virtual int vStaffIdx() const override
Definition: chordrest.h:115
void setCrossMeasureDurationType(TDuration v)
Definition: chordrest.h:152
Fraction durationTypeTicks()
Definition: chordrest.h:129
Definition: score.h:391
int dots() const
Definition: durationtype.h:80
Example of 1/8 triplet: _baseLen = 1/8 _actualNotes = 3 _normalNotes = 2 (3 notes played in the time ...
Definition: tuplet.h:37
int beams() const
Definition: chordrest.h:93
Placement
Definition: types.h:312
void setDots(int v)
Definition: durationtype.cpp:55
int dots() const
Definition: chordrest.h:126
bool isFullMeasureRest() const
Definition: chordrest.h:177
Beam * _beam
Definition: chordrest.h:59
TDuration crossMeasureDurationType() const
Definition: chordrest.h:151
SegmentType
Definition: types.h:333
int staffMove() const
Definition: chordrest.h:113
virtual void crossMeasureSetup(bool)
Definition: chordrest.h:148
articulation marks
Definition: articulation.h:57
Definition: segment.h:50
Mode
Definition: beam.h:73
Definition: aeolus.cpp:26
CrossMeasure crossMeasure() const
Definition: chordrest.h:146
TDuration _durationType
Definition: chordrest.h:50
const TDuration actualDurationType() const
Definition: chordrest.h:120
CrossMeasure _crossMeasure
0: no cross-measure modification; 1: 1st note of a mod.; -1: 2nd note
Definition: chordrest.h:65
virtual void layoutStem1()
Definition: chordrest.h:174
bool _small
Definition: chordrest.h:62
Definition: xml.h:218
Virtual base class for Chord, Rest and Tuplet.
Definition: duration.h:34
virtual void computeUp()
Definition: chordrest.h:175
Fraction ticks() const
Definition: durationtype.cpp:97
CrossMeasure
Definition: chordrest.h:24
void setStaffMove(int val)
Definition: chordrest.h:114
std::vector< Lyrics * > _lyrics
Definition: chordrest.h:56
int hooks() const
Definition: durationtype.cpp:203
Definition: chordrest.h:48
void setBeamMode(Beam::Mode m)
Definition: chordrest.h:87
Definition: element.h:111
Beam::Mode beamMode() const
Definition: chordrest.h:89
Definition: shape.h:42
ElementList _el
Definition: chordrest.h:49
Definition: fraction.h:46
ElementType
Definition: types.h:34
bool small() const
Definition: chordrest.h:109
void setCrossMeasure(CrossMeasure val)
Definition: chordrest.h:147
virtual Beam * beam() const final
Definition: chordrest.h:92
Definition: lyrics.h:27
Pid propertyId(const QStringRef &s)
Definition: property.cpp:347
void setDots(int n)
Definition: chordrest.h:125