MuseScore  3.4
Music composition and notation
staff.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 __STAFF_H__
14 #define __STAFF_H__
15 
21 #include "mscore.h"
22 #include "velo.h"
23 #include "pitch.h"
24 #include "cleflist.h"
25 #include "keylist.h"
26 #include "stafftypelist.h"
27 #include "groups.h"
28 #include "scoreElement.h"
29 
30 namespace Ms {
31 
32 class InstrumentTemplate;
33 class XmlWriter;
34 class Part;
35 class Score;
36 class KeyList;
37 class StaffType;
38 class Staff;
39 struct ClefTypeList;
40 class Segment;
41 class Clef;
42 class TimeSig;
43 class Ottava;
44 class BracketItem;
45 
46 enum class Key;
47 
48 //---------------------------------------------------------
49 // SwingParameters
50 //---------------------------------------------------------
51 
53  int swingUnit;
55  };
56 
57 //---------------------------------------------------------
58 // Staff
60 //---------------------------------------------------------
61 
62 class Staff final : public ScoreElement {
63  public:
64  enum class HideMode { AUTO, ALWAYS, NEVER, INSTRUMENT };
65 
66  private:
67  Part* _part { 0 };
68 
71 
73  std::map<int,TimeSig*> timesigs;
74 
75  QList <BracketItem*> _brackets;
76  int _barLineSpan { false };
77  int _barLineFrom { 0 };
78  int _barLineTo { 0 };
79 
80  bool _invisible { false };
81  bool _cutaway { false };
82  bool _showIfEmpty { false };
83  bool _hideSystemBarLine { false }; // no system barline if not preceded by staff with barline
84  HideMode _hideWhenEmpty { HideMode::AUTO }; // hide empty staves
85 
86  QColor _color { MScore::defaultColor };
87  qreal _userDist { 0.0 };
88 
90 
91  QMap<int,int> _channelList[VOICES];
92  QMap<int,SwingParameters> _swingList;
93  QMap<int,int> _capoList;
94  bool _playbackVoice[VOICES] { true, true, true, true };
95 
98 
99  void fillBrackets(int);
100  void cleanBrackets();
101 
102  public:
103  Staff(Score* score = 0);
104  void init(const InstrumentTemplate*, const StaffType *staffType, int);
105  void initFromStaffType(const StaffType* staffType);
106  void init(const Staff*);
107 
108  virtual ElementType type() const override { return ElementType::STAFF; }
109 
110  bool isTop() const;
111  QString partName() const;
112  int rstaff() const;
113  int idx() const;
114  void read(XmlReader&);
115  bool readProperties(XmlReader&);
116  void write(XmlWriter& xml) const;
117  Part* part() const { return _part; }
118  void setPart(Part* p) { _part = p; }
119 
120  BracketType bracketType(int idx) const;
121  int bracketSpan(int idx) const;
122  void setBracketType(int idx, BracketType val);
123  void setBracketSpan(int idx, int val);
124  void swapBracket(int oldIdx, int newIdx);
125  void changeBracketColumn(int oldColumn, int newColumn);
126  void addBracket(BracketItem*);
127  const QList<BracketItem*>& brackets() const { return _brackets; }
128  QList<BracketItem*>& brackets() { return _brackets; }
129  void cleanupBrackets();
130  int bracketLevels() const;
131 
132  ClefList& clefList() { return clefs; }
133  ClefTypeList clefType(const Fraction&) const;
134  ClefTypeList defaultClefType() const { return _defaultClefType; }
135  void setDefaultClefType(const ClefTypeList& l) { _defaultClefType = l; }
136  ClefType clef(const Fraction&) const;
137  Fraction nextClefTick(const Fraction&) const;
138  Fraction currentClefTick(const Fraction&) const;
139 
140  void setClef(Clef*);
141  void removeClef(const Clef*);
142 
143  void addTimeSig(TimeSig*);
144  void removeTimeSig(TimeSig*);
145  void clearTimeSig();
146  Fraction timeStretch(const Fraction&) const;
147  TimeSig* timeSig(const Fraction&) const;
148  TimeSig* nextTimeSig(const Fraction&) const;
149  Fraction currentTimeSigTick(const Fraction&) const;
150 
151  bool isLocalTimeSignature(const Fraction& tick) { return timeStretch(tick) != Fraction(1, 1); }
152 
153  const Groups& group(const Fraction&) const;
154 
155  KeyList* keyList() { return &_keys; }
156  Key key(const Fraction& tick) const { return keySigEvent(tick).key(); }
157  KeySigEvent keySigEvent(const Fraction&) const;
158  Fraction nextKeyTick(const Fraction&) const;
159  Fraction currentKeyTick(const Fraction&) const;
160  KeySigEvent prevKey(const Fraction&) const;
161  void setKey(const Fraction&, KeySigEvent);
162  void removeKey(const Fraction&);
163 
164  bool show() const;
165  bool stemless(const Fraction&) const;
166  bool invisible() const { return _invisible; }
167  void setInvisible(bool val) { _invisible = val; }
168  bool cutaway() const { return _cutaway; }
169  void setCutaway(bool val) { _cutaway = val; }
170  bool showIfEmpty() const { return _showIfEmpty; }
171  void setShowIfEmpty(bool val) { _showIfEmpty = val; }
172 
173  bool hideSystemBarLine() const { return _hideSystemBarLine; }
174  void setHideSystemBarLine(bool val) { _hideSystemBarLine = val; }
175  HideMode hideWhenEmpty() const { return _hideWhenEmpty; }
176  void setHideWhenEmpty(HideMode v) { _hideWhenEmpty = v; }
177 
178  int barLineSpan() const { return _barLineSpan; }
179  int barLineFrom() const { return _barLineFrom; }
180  int barLineTo() const { return _barLineTo; }
181  void setBarLineSpan(int val) { _barLineSpan = val; }
182  void setBarLineFrom(int val) { _barLineFrom = val; }
183  void setBarLineTo(int val) { _barLineTo = val; }
184  qreal height() const;
185 
186  int channel(const Fraction&, int voice) const;
187  void clearChannelList(int voice) { _channelList[voice].clear(); }
188  void insertIntoChannelList(int voice, const Fraction& tick, int channelId) { _channelList[voice].insert(tick.ticks(), channelId); }
189 
190  SwingParameters swing(const Fraction&) const;
191  void clearSwingList() { _swingList.clear(); }
192  void insertIntoSwingList(const Fraction& tick, SwingParameters sp) { _swingList.insert(tick.ticks(), sp); }
193 
194  int capo(const Fraction&) const;
195  void clearCapoList() { _capoList.clear(); }
196  void insertIntoCapoList(const Fraction& tick, int fretId) { _capoList.insert(tick.ticks(), fretId); }
197 
198  //==== staff type helper function
199  const StaffType* staffType(const Fraction&) const;
200  const StaffType* constStaffType(const Fraction&) const;
201  StaffType* staffType(const Fraction&);
202  StaffType* setStaffType(const Fraction&, const StaffType&);
203  void removeStaffType(const Fraction&);
204  void staffTypeListChanged(const Fraction&);
205 
206  bool isPitchedStaff(const Fraction&) const;
207  bool isTabStaff(const Fraction&) const;
208  bool isDrumStaff(const Fraction&) const;
209 
210  int lines(const Fraction&) const;
211  void setLines(const Fraction&, int lines);
212  qreal lineDistance(const Fraction&) const;
213 
214  void setSlashStyle(const Fraction&, bool val);
215  int middleLine(const Fraction&) const;
216  int bottomLine(const Fraction&) const;
217 
218  qreal userMag(const Fraction&) const;
219  void setUserMag(const Fraction&, qreal m);
220  qreal mag(const Fraction&) const;
221  bool small(const Fraction&) const;
222  void setSmall(const Fraction&, bool val);
223  qreal spatium(const Fraction&) const;
224  //===========
225 
226  VeloList& velocities() { return _velocities; }
227  PitchList& pitchOffsets() { return _pitchOffsets; }
228 
229  int pitchOffset(const Fraction& tick) { return _pitchOffsets.pitchOffset(tick.ticks()); }
230  void updateOttava();
231 
232  QList<Staff*> staffList() const;
233  bool primaryStaff() const;
234 
235  qreal userDist() const { return _userDist; }
236  void setUserDist(qreal val) { _userDist = val; }
237 
238  void spatiumChanged(qreal /*oldValue*/, qreal /*newValue*/);
239  void localSpatiumChanged(double oldVal, double newVal, Fraction tick);
240  bool genKeySig();
241  bool showLedgerLines(const Fraction&) const;
242 
243  QColor color() const { return _color; }
244  void setColor(const QColor& val) { _color = val; }
245  void undoSetColor(const QColor& val);
246  void insertTime(const Fraction&, const Fraction& len);
247 
248  virtual QVariant getProperty(Pid) const override;
249  virtual bool setProperty(Pid, const QVariant&) override;
250  virtual QVariant propertyDefault(Pid) const override;
251 
252  BracketType innerBracket() const;
253 
254  bool playbackVoice(int voice) const { return _playbackVoice[voice]; }
255  void setPlaybackVoice(int voice, bool val) { _playbackVoice[voice] = val; }
256 
257 #ifndef NDEBUG
258  void dumpClefs(const char* title) const;
259  void dumpKeys(const char* title) const;
260  void dumpTimeSigs(const char*) const;
261 #else
262  void dumpClefs(const char*) const {}
263  void dumpKeys(const char*) const {}
264  void dumpTimeSigs(const char*) const {}
265 #endif
266 
267  void triggerLayout();
268  void triggerLayout(const Fraction& tick);
269  };
270 
271 } // namespace Ms
272 #endif
273 
int swingUnit
Definition: staff.h:53
QList< BracketItem * > & brackets()
Definition: staff.h:128
int swingRatio
Definition: staff.h:54
Definition: bracketItem.h:25
virtual ElementType type() const override
Definition: staff.h:108
Global staff data not directly related to drawing.
Definition: staff.h:62
Definition: staff.h:52
ClefList clefs
Definition: staff.h:69
bool showIfEmpty() const
Definition: staff.h:170
VeloList List of note velocity changes.
Definition: velo.h:42
Pid
Definition: property.h:62
Key
Definition: key.h:28
This class represents a time signature.
Definition: timesig.h:41
Definition: xml.h:67
Part * part() const
Definition: staff.h:117
int barLineFrom() const
Definition: staff.h:179
Definition: cleflist.h:27
bool invisible() const
Definition: staff.h:166
const QList< BracketItem * > & brackets() const
Definition: staff.h:127
QMap< int, SwingParameters > _swingList
Definition: staff.h:92
void insertIntoSwingList(const Fraction &tick, SwingParameters sp)
Definition: staff.h:192
Definition: scoreElement.h:173
void setHideSystemBarLine(bool val)
Definition: staff.h:174
std::map< int, TimeSig * > timesigs
Definition: staff.h:73
int barLineTo() const
Definition: staff.h:180
qreal userDist() const
Definition: staff.h:235
Definition: stafftypelist.h:28
void insertIntoCapoList(const Fraction &tick, int fretId)
Definition: staff.h:196
ClefTypeList _defaultClefType
Definition: staff.h:70
Graphic representation of a clef.
Definition: clef.h:132
void setShowIfEmpty(bool val)
Definition: staff.h:171
Definition: clef.h:81
HideMode
Definition: staff.h:64
GroupNodes must be sorted by tick.
Definition: groups.h:48
PitchList & pitchOffsets()
Definition: staff.h:227
ClefList & clefList()
Definition: staff.h:132
Definition: score.h:391
Definition: keylist.h:28
QList< BracketItem * > _brackets
Definition: staff.h:75
static QColor defaultColor
Definition: mscore.h:328
int barLineSpan() const
Definition: staff.h:178
#define VOICES
Definition: mscore.h:72
bool playbackVoice(int voice) const
Definition: staff.h:254
void insertIntoChannelList(int voice, const Fraction &tick, int channelId)
Definition: staff.h:188
void clearSwingList()
Definition: staff.h:191
Definition: key.h:95
HideMode hideWhenEmpty() const
Definition: staff.h:175
int pitchOffset(int tick) const
Definition: pitch.cpp:22
void setPlaybackVoice(int voice, bool val)
Definition: staff.h:255
QMap< int, int > _capoList
Definition: staff.h:93
void setBarLineTo(int val)
Definition: staff.h:183
Definition: aeolus.cpp:26
StaffTypeList _staffTypeList
Definition: staff.h:89
void setUserDist(qreal val)
Definition: staff.h:236
Definition: stafftype.h:173
void setInvisible(bool val)
Definition: staff.h:167
VeloList & velocities()
Definition: staff.h:226
void setBarLineFrom(int val)
Definition: staff.h:182
Definition: xml.h:218
PitchList List of note pitch offsets.
Definition: pitch.h:23
KeyList _keys
Definition: staff.h:72
Definition: xmlwriter.h:26
void setBarLineSpan(int val)
Definition: staff.h:181
int ticks() const
Definition: fraction.h:228
void setHideWhenEmpty(HideMode v)
Definition: staff.h:176
BracketType
Definition: mscore.h:107
void clearChannelList(int voice)
Definition: staff.h:187
void setPart(Part *p)
Definition: staff.h:118
void clearCapoList()
Definition: staff.h:195
Definition of classes VeloList.
int pitchOffset(const Fraction &tick)
Definition: staff.h:229
Key key(const Fraction &tick) const
Definition: staff.h:156
PitchList _pitchOffsets
cached value
Definition: staff.h:97
ClefType
Definition: clef.h:37
Definition: fraction.h:46
ElementType
Definition: types.h:34
Definition: instrtemplate.h:48
void setDefaultClefType(const ClefTypeList &l)
Definition: staff.h:135
bool cutaway() const
Definition: staff.h:168
bool hideSystemBarLine() const
Definition: staff.h:173
void setCutaway(bool val)
Definition: staff.h:169
QColor color() const
Definition: staff.h:243
ClefTypeList defaultClefType() const
Definition: staff.h:134
bool isLocalTimeSignature(const Fraction &tick)
Definition: staff.h:151
Definition: part.h:47
void setColor(const QColor &val)
Definition: staff.h:244
VeloList _velocities
cached value
Definition: staff.h:96
KeyList * keyList()
Definition: staff.h:155