MuseScore  3.4
Music composition and notation
measure.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 __MEASURE_H__
14 #define __MEASURE_H__
15 
21 #include "measurebase.h"
22 #include "fraction.h"
23 #include "segmentlist.h"
24 
25 namespace Ms {
26 
27 class XmlWriter;
28 class Beam;
29 class Tuplet;
30 class Staff;
31 class Chord;
32 class MeasureNumber;
33 class ChordRest;
34 class Score;
35 class MuseScoreView;
36 class System;
37 class Note;
38 class Spacer;
39 class TieMap;
40 class AccidentalState;
41 class Spanner;
42 class Part;
43 class RepeatMeasure;
44 
45 class MStaff;
46 
47 //---------------------------------------------------------
48 // MeasureNumberMode
49 //---------------------------------------------------------
50 
51 enum class MeasureNumberMode : char {
52  AUTO, // show measure number depending on style
53  SHOW, // always show measure number
54  HIDE // don’t show measure number
55  };
56 
57 //---------------------------------------------------------
58 // @@ Measure
60 //
61 // @P firstSegment Segment the first segment of the measure (read-only)
62 // @P lastSegment Segment the last segment of the measure (read-only)
63 //---------------------------------------------------------
64 
65 class Measure final : public MeasureBase {
66  std::vector<MStaff*> _mstaves;
68  Measure* _mmRest; // multi measure rest which replaces a measure range
69 
70  qreal _userStretch;
71 
73 
74  int _mmRestCount; // > 0 if this is a multi measure rest
75  // 0 if this is the start of a mm rest (_mmRest != 0)
76  // < 0 if this measure is covered by a mm rest
77 
78  int _playbackCount; // temp. value used in RepeatList
79  // counts how many times this measure was already played
80 
82 
85 
86  void push_back(Segment* e);
87  void push_front(Segment* e);
88 
89  void fillGap(const Fraction& pos, const Fraction& len, int track, const Fraction& stretch);
90  void computeMinWidth(Segment* s, qreal x, bool isSystemHeader);
91 
92  void readVoice(XmlReader& e, int staffIdx, bool irregular);
93 
94  public:
95  Measure(Score* = 0);
96  Measure(const Measure&);
97  ~Measure();
98  virtual Measure* clone() const override { return new Measure(*this); }
99  virtual ElementType type() const override { return ElementType::MEASURE; }
100  virtual void setScore(Score* s) override;
101  Measure* cloneMeasure(Score*, const Fraction& tick, TieMap*);
102 
103  void read(XmlReader&, int idx);
104  void read(XmlReader& d) { read(d, 0); }
105  virtual void readAddConnector(ConnectorInfoReader* info, bool pasteMode) override;
106  virtual void write(XmlWriter& xml) const override { Element::write(xml); }
107  void write(XmlWriter&, int, bool writeSystemElements, bool forceTimeSig) const;
108  void writeBox(XmlWriter&) const;
109  void readBox(XmlReader&);
110  virtual bool isEditable() const override { return false; }
111  void checkMeasure(int idx);
112 
113  virtual void add(Element*) override;
114  virtual void remove(Element*) override;
115  virtual void change(Element* o, Element* n) override;
116  virtual void spatiumChanged(qreal oldValue, qreal newValue) override;
117 
118  System* system() const { return (System*)parent(); }
119  bool hasVoices(int staffIdx) const;
120  void setHasVoices(int staffIdx, bool v);
121 
122  StaffLines* staffLines(int staffIdx);
123  Spacer* vspacerDown(int staffIdx) const;
124  Spacer* vspacerUp(int staffIdx) const;
125  void setStaffVisible(int staffIdx, bool visible);
126  void setStaffStemless(int staffIdx, bool stemless);
127  bool corrupted(int staffIdx) const;
128  void setCorrupted(int staffIdx, bool val);
129  void setNoText(int staffIdx, MeasureNumber*);
130  MeasureNumber* noText(int staffIdx) const;
131 
132  void createStaves(int);
133 
134  MeasureNumberMode measureNumberMode() const { return _noMode; }
135  void setMeasureNumberMode(MeasureNumberMode v) { _noMode = v; }
136 
137  Fraction timesig() const { return _timesig; }
138  void setTimesig(const Fraction& f) { _timesig = f; }
139 
140  Fraction stretchedLen(Staff*) const;
141  bool isIrregular() const { return _timesig != _len; }
142 
143  int size() const { return _segments.size(); }
144  Ms::Segment* first() const { return _segments.first(); }
145  Segment* first(SegmentType t) const { return _segments.first(t); }
146  Segment* firstEnabled() const { return _segments.first(ElementFlag::ENABLED); }
147 
148  Ms::Segment* last() const { return _segments.last(); }
149  SegmentList& segments() { return _segments; }
150  const SegmentList& segments() const { return _segments; }
151 
152  qreal userStretch() const;
153  void setUserStretch(qreal v) { _userStretch = v; }
154 
155  void stretchMeasure(qreal stretch);
156  Fraction computeTicks();
157  void layout2();
158  void layoutMeasureNumber();
159 
160  Chord* findChord(Fraction tick, int track);
161  ChordRest* findChordRest(Fraction tick, int track);
162  Fraction snap(const Fraction& tick, const QPointF p) const;
163  Fraction snapNote(const Fraction& tick, const QPointF p, int staff) const;
164 
165  void insertStaff(Staff*, int staff);
166  void insertMStaff(MStaff* staff, int idx);
167  void removeMStaff(MStaff* staff, int idx);
168 
169  virtual void moveTicks(const Fraction& diff) override;
170 
171  void cmdRemoveStaves(int s, int e);
172  void cmdAddStaves(int s, int e, bool createRest);
173  void removeStaves(int s, int e);
174  void insertStaves(int s, int e);
175 
176  qreal tick2pos(Fraction) const;
177  Segment* tick2segment(const Fraction& tick, SegmentType st = SegmentType::ChordRest);
178 
179  void sortStaves(QList<int>& dst);
180 
181  virtual bool acceptDrop(EditData&) const override;
182  virtual Element* drop(EditData&) override;
183 
184  int repeatCount() const { return _repeatCount; }
185  void setRepeatCount(int val) { _repeatCount = val; }
186 
187  Segment* findSegmentR(SegmentType st, const Fraction&) const;
188  Segment* undoGetSegmentR(SegmentType st, const Fraction& f);
189  Segment* getSegmentR(SegmentType st, const Fraction& f);
190  Segment* findFirstR(SegmentType st, const Fraction& rtick) const;
191 
192  // segment routines with absolute tick values
193  Segment* findSegment(SegmentType st, const Fraction& f) const { return findSegmentR(st, f - tick()); }
194  Segment* undoGetSegment(SegmentType st, const Fraction& f) { return undoGetSegmentR(st, f - tick()); }
195  Segment* getSegment(SegmentType st, const Fraction& f) { return getSegmentR(st, f - tick()); }
196 
197  void connectTremolo();
198 
199  qreal createEndBarLines(bool);
200  void barLinesSetSpan(Segment*);
201  void setEndBarLineType(BarLineType val, int track, bool visible = true, QColor color = QColor());
202 
203  RepeatMeasure* cmdInsertRepeatMeasure(int staffIdx);
204 
205  virtual void scanElements(void* data, void (*func)(void*, Element*), bool all=true) override;
206  void createVoice(int track);
207  void adjustToLen(Fraction, bool appendRestsIfNecessary = true);
208 
209  AccidentalVal findAccidental(Note*) const;
210  AccidentalVal findAccidental(Segment* s, int staffIdx, int line, bool &error) const;
211  void exchangeVoice(int voice1, int voice2, int staffIdx);
212  void checkMultiVoices(int staffIdx);
213  bool hasVoice(int track) const;
214  bool isEmpty(int staffIdx) const;
215  bool isFullMeasureRest() const;
216  bool isRepeatMeasure(const Staff* staff) const;
217  bool visible(int staffIdx) const;
218  bool stemless(int staffIdx) const;
219  bool isFinalMeasureOfSection() const;
220  bool isAnacrusis() const;
221 
222  bool breakMultiMeasureRest() const { return _breakMultiMeasureRest; }
223  void setBreakMultiMeasureRest(bool val) { _breakMultiMeasureRest = val; }
224 
225  bool empty() const;
226  bool isOnlyRests(int track) const;
227  bool isOnlyDeletedRests(int track) const;
228  bool isOnlyDeletedRests(int track, const Fraction& stick, const Fraction& etick) const;
229 
230  int playbackCount() const { return _playbackCount; }
231  void setPlaybackCount(int val) { _playbackCount = val; }
232  QRectF staffabbox(int staffIdx) const;
233 
234  virtual QVariant getProperty(Pid propertyId) const override;
235  virtual bool setProperty(Pid propertyId, const QVariant&) override;
236  virtual QVariant propertyDefault(Pid) const override;
237 
238  bool hasMMRest() const { return _mmRest != 0; }
239  bool isMMRest() const { return _mmRestCount > 0; }
240  Measure* mmRest() const { return _mmRest; }
241  const Measure* mmRest1() const;
242  void setMMRest(Measure* m) { _mmRest = m; }
243  int mmRestCount() const { return _mmRestCount; } // number of measures _mmRest spans
244  void setMMRestCount(int n) { _mmRestCount = n; }
245  Measure* mmRestFirst() const;
246  Measure* mmRestLast() const;
247 
248  Element* nextElementStaff(int staff);
249  Element* prevElementStaff(int staff);
250  virtual QString accessibleInfo() const override;
251 
252  void addSystemHeader(bool firstSystem);
253  void addSystemTrailer(Measure* nm);
254  void removeSystemHeader();
255  void removeSystemTrailer();
256 
257  const BarLine* endBarLine() const;
258  BarLineType endBarLineType() const;
259  bool endBarLineVisible() const;
260  virtual void triggerLayout() const override;
261  qreal basicStretch() const;
262  qreal basicWidth() const;
263  int layoutWeight(int maxMMRestLength = 0) const;
264  virtual void computeMinWidth();
265  void checkHeader();
266  void checkTrailer();
267  void setStretchedWidth(qreal);
268  void layoutStaffLines();
269  };
270 
271 } // namespace Ms
272 #endif
273 
Definition: segmentlist.h:26
Ms::Segment * first() const
Definition: measure.h:144
Helper class for reading beams, tuplets and spanners.
Definition: connector.h:96
Global staff data not directly related to drawing.
Definition: staff.h:62
AccidentalVal
Definition: mscore.h:147
Pid
Definition: property.h:62
Virtual base class for Measure, HBox and VBox.
Definition: measurebase.h:61
Definition: xml.h:67
const SegmentList & segments() const
Definition: measure.h:150
Definition of MeasureBase class.
qreal _userStretch
Definition: measure.h:70
Per staff values of measure.
Definition: measure.cpp:90
int repeatCount() const
Definition: measure.h:184
Ms::Segment * last() const
Definition: measure.h:148
bool isIrregular() const
Definition: measure.h:141
Definition: measurenumber.h:24
one measure in a system
Definition: measure.h:65
MeasureNumberMode _noMode
Definition: measure.h:83
Segment * undoGetSegment(SegmentType st, const Fraction &f)
Definition: measure.h:194
Segment * first() const
Definition: segmentlist.h:42
MeasureNumberMode measureNumberMode() const
Definition: measure.h:134
std::pair< ElementType, ReducedFraction > findChordRest(const Segment *seg, int strack)
Definition: importmidi_clef.cpp:221
Base class of score layout elements.
Definition: element.h:158
Segment * first(SegmentType t) const
Definition: measure.h:145
int _repeatCount
end repeat marker und repeat count
Definition: measure.h:81
std::vector< MStaff * > _mstaves
Definition: measure.h:66
Segment * getSegment(SegmentType st, const Fraction &f)
Definition: measure.h:195
virtual bool isEditable() const override
Definition: measure.h:110
int size() const
Definition: measure.h:143
int playbackCount() const
Definition: measure.h:230
virtual void write(XmlWriter &) const
Definition: element.cpp:732
Segment * last() const
Definition: segmentlist.h:46
void setMMRest(Measure *m)
Definition: measure.h:242
Definition: score.h:391
void setPlaybackCount(int val)
Definition: measure.h:231
System * system() const
Definition: measure.h:118
bool breakMultiMeasureRest() const
Definition: measure.h:222
void setBreakMultiMeasureRest(bool val)
Definition: measure.h:223
void setMMRestCount(int n)
Definition: measure.h:244
void setRepeatCount(int val)
Definition: measure.h:185
The StaffLines class is the graphic representation of a staff, it draws the horizontal staff lines...
Definition: stafflines.h:23
Vertical spacer element to adjust the distance of staves.
Definition: spacer.h:33
Measure * mmRest() const
Definition: measure.h:240
SegmentType
Definition: types.h:333
void setTimesig(const Fraction &f)
Definition: measure.h:138
bool _breakMultiMeasureRest
Definition: measure.h:84
Measure * _mmRest
Definition: measure.h:68
virtual void write(XmlWriter &xml) const override
Definition: measure.h:106
Fraction _timesig
Definition: measure.h:72
Definition: segment.h:50
void setMeasureNumberMode(MeasureNumberMode v)
Definition: measure.h:135
Segment * findSegment(SegmentType st, const Fraction &f) const
Definition: measure.h:193
Definition: aeolus.cpp:26
MeasureNumberMode
Definition: measure.h:51
int _mmRestCount
Definition: measure.h:74
Definition: xml.h:218
bool isMMRest() const
Definition: measure.h:239
Definition: xmlwriter.h:26
Graphic representation of a chord.
Definition: chord.h:55
Definition: chordrest.h:48
Segment * firstEnabled() const
Definition: measure.h:146
Definition: element.h:111
int _playbackCount
Definition: measure.h:78
virtual Measure * clone() const override
Definition: measure.h:98
int mmRestCount() const
Definition: measure.h:243
SegmentList _segments
Definition: measure.h:67
One row of measures for all instruments; a complete piece of the timeline.
Definition: system.h:79
Graphic representation of a note.
Definition: note.h:212
Definition: fraction.h:46
void setUserStretch(qreal v)
Definition: measure.h:153
ElementType
Definition: types.h:34
int size() const
Definition: segmentlist.h:40
Definition: barline.h:57
virtual ElementType type() const override
Definition: measure.h:99
Definition: repeat.h:28
Pid propertyId(const QStringRef &s)
Definition: property.cpp:347
Definition: tiemap.h:26
bool hasMMRest() const
Definition: measure.h:238
SegmentList & segments()
Definition: measure.h:149
BarLineType
Definition: mscore.h:199
Fraction timesig() const
Definition: measure.h:137
void read(XmlReader &d)
Definition: measure.h:104