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 16 /** 17 \file 18 Definition of classes SysStaff and System 19 */ 20 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 44 /// One staff in a System. 45 //--------------------------------------------------------- 46 47 class SysStaff { 48 QRectF _bbox; // Bbox of StaffLines. 49 Skyline _skyline; 50 qreal _yOff { 0.0 }; // offset of top staff line within bbox 51 qreal _yPos { 0.0 }; // y position of bbox after System::layout2 52 qreal _height { 0.0 }; // height of bbox after System::layout2 53 qreal _continuousDist { -1.0 }; // distance for continuous mode 54 bool _show { true }; // derived from Staff or false if empty 55 // staff is hidden 56 public: 57 //int idx { 0 }; 58 QList<InstrumentName*> instrumentNames; 59 bbox()60 const QRectF& bbox() const { return _bbox; } bbox()61 QRectF& bbox() { return _bbox; } setbbox(const QRectF & r)62 void setbbox(const QRectF& r) { _bbox = r; } y()63 qreal y() const { return _bbox.y() + _yOff; } setYOff(qreal offset)64 void setYOff(qreal offset) { _yOff = offset; } yOffset()65 qreal yOffset() const { return _yOff; } 66 67 void saveLayout(); 68 void restoreLayout(); 69 continuousDist()70 qreal continuousDist() const { return _continuousDist; } setContinuousDist(qreal val)71 void setContinuousDist(qreal val) { _continuousDist = val; } 72 show()73 bool show() const { return _show; } setShow(bool v)74 void setShow(bool v) { _show = v; } 75 skyline()76 const Skyline& skyline() const { return _skyline; } skyline()77 Skyline& skyline() { return _skyline; } 78 SysStaff()79 SysStaff() {} 80 ~SysStaff(); 81 }; 82 83 //--------------------------------------------------------- 84 // System 85 /// One row of measures for all instruments; 86 /// a complete piece of the timeline. 87 //--------------------------------------------------------- 88 89 class System final : public Element { 90 SystemDivider* _systemDividerLeft { nullptr }; // to the next system 91 SystemDivider* _systemDividerRight { nullptr }; 92 93 std::vector<MeasureBase*> ml; 94 QList<SysStaff*> _staves; 95 QList<Bracket*> _brackets; 96 QList<SpannerSegment*> _spannerSegments; 97 98 qreal _leftMargin { 0.0 }; ///< left margin for instrument name, brackets etc. 99 mutable Spacer* fixedSpacer { nullptr }; 100 qreal _distance { 0.0 }; // temp. variable used during layout 101 qreal _systemHeight { 0.0 }; 102 103 int firstVisibleSysStaff() const; 104 int lastVisibleSysStaff() const; 105 106 int getBracketsColumnsCount(); 107 void setBracketsXPosition(const qreal xOffset); 108 Bracket* createBracket(Ms::BracketItem* bi, int column, int staffIdx, QList<Ms::Bracket *>& bl, Measure* measure); 109 110 public: 111 System(Score*); 112 ~System(); 113 clone()114 System* clone() const override { return new System(*this); } type()115 ElementType type() const override { return ElementType::SYSTEM; } 116 117 void add(Element*) override; 118 void remove(Element*) override; 119 void change(Element* o, Element* n) override; 120 void write(XmlWriter&) const override; 121 void read(XmlReader&) override; 122 123 void scanElements(void* data, void (*func)(void*, Element*), bool all=true) override; 124 125 void appendMeasure(MeasureBase*); 126 void removeMeasure(MeasureBase*); 127 void removeLastMeasure(); 128 page()129 Page* page() const { return (Page*)parent(); } 130 131 void layoutSystem(qreal, const bool isFirstSystem = false, bool firstSystemIndent = false); 132 void setMeasureHeight(qreal height); 133 void layoutBracketsVertical(); 134 void layoutInstrumentNames(); 135 136 void addBrackets(Measure* measure); 137 138 void layout2(); ///< Called after Measure layout. 139 void restoreLayout2(); 140 void clear(); ///< Clear measure list. 141 bboxStaff(int staff)142 QRectF bboxStaff(int staff) const { return _staves[staff]->bbox(); } staves()143 QList<SysStaff*>* staves() { return &_staves; } staves()144 const QList<SysStaff*>* staves() const { return &_staves; } 145 qreal staffYpage(int staffIdx) const; 146 qreal staffCanvasYpage(int staffIdx) const; staff(int staffIdx)147 SysStaff* staff(int staffIdx) const { return _staves[staffIdx]; } 148 149 bool pageBreak() const; 150 151 SysStaff* insertStaff(int); 152 void removeStaff(int); 153 void adjustStavesNumber(int); 154 155 int y2staff(qreal y) const; 156 int searchStaff(qreal y, int preferredStaff = -1, qreal spacingFactor = 0.5) const; 157 void setInstrumentNames(bool longName, Fraction tick = {0,1}); 158 Fraction snap(const Fraction& tick, const QPointF p) const; 159 Fraction snapNote(const Fraction& tick, const QPointF p, int staff) const; 160 measures()161 const std::vector<MeasureBase*>& measures() const { return ml; } 162 measure(int idx)163 MeasureBase* measure(int idx) { return ml[idx]; } 164 Measure* firstMeasure() const; 165 Measure* lastMeasure() const; 166 Fraction endTick() const; 167 168 MeasureBase* nextMeasure(const MeasureBase*) const; 169 leftMargin()170 qreal leftMargin() const { return _leftMargin; } 171 Box* vbox() const; 172 brackets()173 const QList<Bracket*>& brackets() const { return _brackets; } 174 spannerSegments()175 QList<SpannerSegment*>& spannerSegments() { return _spannerSegments; } spannerSegments()176 const QList<SpannerSegment*>& spannerSegments() const { return _spannerSegments; } 177 systemDividerLeft()178 SystemDivider* systemDividerLeft() const { return _systemDividerLeft; } systemDividerRight()179 SystemDivider* systemDividerRight() const { return _systemDividerRight; } 180 181 Element* nextSegmentElement() override; 182 Element* prevSegmentElement() override; 183 184 qreal minDistance(System*) const; 185 qreal topDistance(int staffIdx, const SkylineLine&) const; 186 qreal bottomDistance(int staffIdx, const SkylineLine&) const; 187 qreal minTop() const; 188 qreal minBottom() const; 189 qreal spacerDistance(bool up) const; 190 191 qreal firstNoteRestSegmentX(bool leading = false); 192 193 void moveBracket(int staffIdx, int srcCol, int dstCol); getFixedSpacer()194 Spacer* getFixedSpacer() const { return fixedSpacer; } 195 int firstVisibleStaff() const; 196 int nextVisibleStaff(int) const; distance()197 qreal distance() const { return _distance; } setDistance(qreal d)198 void setDistance(qreal d) { _distance = d; } 199 200 int firstSysStaffOfPart(const Part* part) const; 201 int firstVisibleSysStaffOfPart(const Part* part) const; 202 int lastSysStaffOfPart(const Part* part) const; 203 int lastVisibleSysStaffOfPart(const Part* part) const; 204 }; 205 206 typedef QList<System*>::iterator iSystem; 207 typedef QList<System*>::const_iterator ciSystem; 208 209 210 } // namespace Ms 211 #endif 212 213