MuseScore  3.4
Music composition and notation
system.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 __SYSTEM_H__
14 #define __SYSTEM_H__
15 
21 #include "element.h"
22 #include "spatium.h"
23 #include "symbol.h"
24 #include "skyline.h"
25 
26 namespace Ms {
27 
28 class Staff;
29 class StaffLines;
30 class Clef;
31 class Page;
32 class Bracket;
33 class Lyrics;
34 class Segment;
35 class MeasureBase;
36 class Text;
37 class InstrumentName;
38 class SpannerSegment;
39 class VBox;
40 class BarLine;
41 
42 //---------------------------------------------------------
43 // SysStaff
45 //---------------------------------------------------------
46 
47 class SysStaff {
48  QRectF _bbox; // Bbox of StaffLines.
50  qreal _yOff { 0 }; // offset of top staff line within bbox
51  bool _show { true }; // derived from Staff or false if empty
52  // staff is hidden
53  public:
54  //int idx { 0 };
55  QList<InstrumentName*> instrumentNames;
56 
57  const QRectF& bbox() const { return _bbox; }
58  QRectF& bbox() { return _bbox; }
59  void setbbox(const QRectF& r) { _bbox = r; }
60  qreal y() const { return _bbox.y() + _yOff; }
61  void setYOff(qreal offset) { _yOff = offset; }
62 
63  bool show() const { return _show; }
64  void setShow(bool v) { _show = v; }
65 
66  const Skyline& skyline() const { return _skyline; }
67  Skyline& skyline() { return _skyline; }
68 
69  SysStaff() {}
70  ~SysStaff();
71  };
72 
73 //---------------------------------------------------------
74 // System
77 //---------------------------------------------------------
78 
79 class System final : public Element {
80  SystemDivider* _systemDividerLeft { 0 }; // to the next system
81  SystemDivider* _systemDividerRight { 0 };
82 
83  std::vector<MeasureBase*> ml;
84  QList<SysStaff*> _staves;
85  QList<Bracket*> _brackets;
86  QList<SpannerSegment*> _spannerSegments;
87 
88  qreal _leftMargin { 0.0 };
89  mutable bool fixedDownDistance { false };
90  qreal _distance; // temp. variable used during layout
91 
92  int firstVisibleSysStaff() const;
93  int lastVisibleSysStaff() const;
94 
95  int getBracketsColumnsCount();
96  void setBracketsXPosition(const qreal xOffset);
97  Bracket* createBracket(Ms::BracketItem* bi, int column, int staffIdx, QList<Ms::Bracket *>& bl, Measure* measure);
98 
99 public:
100  System(Score*);
101  ~System();
102  virtual System* clone() const override { return new System(*this); }
103  virtual ElementType type() const override { return ElementType::SYSTEM; }
104 
105  virtual void add(Element*) override;
106  virtual void remove(Element*) override;
107  virtual void change(Element* o, Element* n) override;
108  virtual void write(XmlWriter&) const override;
109  virtual void read(XmlReader&) override;
110 
111  virtual void scanElements(void* data, void (*func)(void*, Element*), bool all=true) override;
112 
113  void appendMeasure(MeasureBase*);
114  void removeMeasure(MeasureBase*);
115  void removeLastMeasure();
116 
117  Page* page() const { return (Page*)parent(); }
118 
119  void layoutSystem(qreal);
120 
121  void addBrackets(Measure* measure);
122 
123  void layout2();
124  void clear();
125 
126  QRectF bboxStaff(int staff) const { return _staves[staff]->bbox(); }
127  QList<SysStaff*>* staves() { return &_staves; }
128  const QList<SysStaff*>* staves() const { return &_staves; }
129  qreal staffYpage(int staffIdx) const;
130  qreal staffCanvasYpage(int staffIdx) const;
131  SysStaff* staff(int staffIdx) const { return _staves[staffIdx]; }
132 
133  bool pageBreak() const;
134 
135  SysStaff* insertStaff(int);
136  void removeStaff(int);
137  void adjustStavesNumber(int);
138 
139  int y2staff(qreal y) const;
140  void setInstrumentNames(bool longName, Fraction tick = {0,1});
141  Fraction snap(const Fraction& tick, const QPointF p) const;
142  Fraction snapNote(const Fraction& tick, const QPointF p, int staff) const;
143 
144  const std::vector<MeasureBase*>& measures() const { return ml; }
145 
146  MeasureBase* measure(int idx) { return ml[idx]; }
147  Measure* firstMeasure() const;
148  Measure* lastMeasure() const;
149  Fraction endTick() const;
150 
151  MeasureBase* nextMeasure(const MeasureBase*) const;
152 
153  qreal leftMargin() const { return _leftMargin; }
154  Box* vbox() const;
155 
156  const QList<Bracket*>& brackets() const { return _brackets; }
157 
158  QList<SpannerSegment*>& spannerSegments() { return _spannerSegments; }
159  const QList<SpannerSegment*>& spannerSegments() const { return _spannerSegments; }
160 
161  SystemDivider* systemDividerLeft() const { return _systemDividerLeft; }
162  SystemDivider* systemDividerRight() const { return _systemDividerRight; }
163 
164  virtual Element* nextSegmentElement() override;
165  virtual Element* prevSegmentElement() override;
166 
167  qreal minDistance(System*) const;
168  qreal topDistance(int staffIdx, const SkylineLine&) const;
169  qreal bottomDistance(int staffIdx, const SkylineLine&) const;
170  qreal minTop() const;
171  qreal minBottom() const;
172  qreal spacerDistance(bool up) const;
173 
174  void moveBracket(int staffIdx, int srcCol, int dstCol);
175  bool hasFixedDownDistance() const { return fixedDownDistance; }
176  int firstVisibleStaff() const;
177  int nextVisibleStaff(int) const;
178  qreal distance() const { return _distance; }
179  void setDistance(qreal d) { _distance = d; }
180  };
181 
182 typedef QList<System*>::iterator iSystem;
183 typedef QList<System*>::const_iterator ciSystem;
184 
185 
186 } // namespace Ms
187 #endif
188 
SysStaff()
Definition: system.h:69
QRectF _bbox
Definition: system.h:48
virtual System * clone() const override
Definition: system.h:102
virtual base class for frames "boxes"
Definition: box.h:33
Definition: bracketItem.h:25
Virtual base class for Measure, HBox and VBox.
Definition: measurebase.h:61
QList< SpannerSegment * > _spannerSegments
Definition: system.h:86
qreal distance() const
Definition: system.h:178
Definition: xml.h:67
QRectF bboxStaff(int staff) const
Definition: system.h:126
qreal _yOff
Definition: system.h:50
one measure in a system
Definition: measure.h:65
virtual ElementType type() const override
Definition: system.h:103
const QList< Bracket * > & brackets() const
Definition: system.h:156
const QList< SpannerSegment * > & spannerSegments() const
Definition: system.h:159
Base class of score layout elements.
Definition: element.h:158
const QRectF & bbox() const
Definition: system.h:57
bool _show
Definition: system.h:51
const Skyline & skyline() const
Definition: system.h:66
Definition: score.h:391
void setYOff(qreal offset)
Definition: system.h:61
One staff in a System.
Definition: system.h:47
Definition: skyline.h:41
void setDistance(qreal d)
Definition: system.h:179
Definition: bracket.h:29
Page * page() const
Definition: system.h:117
void setbbox(const QRectF &r)
Definition: system.h:59
SystemDivider * systemDividerLeft() const
Definition: system.h:161
QList< InstrumentName * > instrumentNames
Definition: system.h:55
QList< System * >::const_iterator ciSystem
Definition: system.h:183
Skyline _skyline
Definition: system.h:49
std::vector< MeasureBase * > ml
Definition: system.h:83
void setShow(bool v)
Definition: system.h:64
QList< SysStaff * > * staves()
Definition: system.h:127
qreal y() const
Definition: system.h:60
SystemDivider * systemDividerRight() const
Definition: system.h:162
SysStaff * staff(int staffIdx) const
Definition: system.h:131
Definition: aeolus.cpp:26
const std::vector< MeasureBase * > & measures() const
Definition: system.h:144
Definition: skyline.h:75
qreal _distance
Definition: system.h:90
qreal leftMargin() const
Definition: system.h:153
Definition: xml.h:218
bool show() const
Definition: system.h:63
const QList< SysStaff * > * staves() const
Definition: system.h:128
Definition: systemdivider.h:25
QList< System * >::iterator iSystem
Definition: system.h:182
One row of measures for all instruments; a complete piece of the timeline.
Definition: system.h:79
bool hasFixedDownDistance() const
Definition: system.h:175
Skyline & skyline()
Definition: system.h:67
Definition: fraction.h:46
QRectF & bbox()
Definition: system.h:58
ElementType
Definition: types.h:34
QList< SpannerSegment * > & spannerSegments()
Definition: system.h:158
QList< Bracket * > _brackets
Definition: system.h:85
QList< SysStaff * > _staves
Definition: system.h:84
~SysStaff()
Definition: system.cpp:54
Definition: page.h:34
MeasureBase * measure(int idx)
Definition: system.h:146