1 //=============================================================================
2 //  MuseScore
3 //  Music Composition & Notation
4 //
5 //  Copyright (C) 2002-2014 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 __SCOREORDER_H__
14 #define __SCOREORDER_H__
15 
16 #include "mscore.h"
17 #include "part.h"
18 
19 namespace Ms {
20 
21 class InstrumentTemplate;
22 
23 //---------------------------------------------------------
24 //   ScoreGroup
25 //---------------------------------------------------------
26 
27 class ScoreGroup final {
28       int static counter;
29       QString _id;
30       QString _section;
31       bool _soloists;
32       QString _unsorted;  // isNull()   : not an unsorted group
33                           // isEmpty()  : equal to <unsorted/>
34                           // !isEmpty() : equal to <unsorted group="_unsorted"/>
35       int _index;
36 
37    public:
38       bool bracket;
39       bool showSystemMarkings;
40       bool barLineSpan;
41       bool thinBracket;
42 
43       ScoreGroup(const QString id, const QString section, const QString unsorted=QString(), bool soloists=false);
44       ~ScoreGroup();
45       ScoreGroup* clone();
46 
47       void write(XmlWriter& xml) const;
48 
49       const QString& id() const;
50       const QString& section() const;
51       bool isSoloists() const;
52       bool isUnsorted(const QString& group=QString()) const;
53       int index() const;
54 
55       virtual void dump() const;
56       };
57 
58 //---------------------------------------------------------
59 //   InstrumentOverwrite
60 //---------------------------------------------------------
61 
62 class InstrumentOverwrite {
63    public:
64       QString id;
65       QString name;
66 
67       InstrumentOverwrite(const QString id=QString(), const QString name=QString());
68 };
69 
70 //---------------------------------------------------------
71 //   ScoreOrder
72 //---------------------------------------------------------
73 
74 class ScoreOrder {
75       QString _id { "" };
76       QString _name { "" };
77       ScoreGroup* _soloists;
78       ScoreGroup* _unsorted;
79       int _groupMultiplier;
80       bool _customized { false };
81 
82    protected:
83       QMap<QString, InstrumentOverwrite> instrumentMap;
84 
85       void init();
86       bool readBoolAttribute(XmlReader& e, const char* name, bool defValue);
87       void readName(XmlReader& e);
88       void readInstrument(XmlReader& e);
89       void readSoloists(XmlReader& e, const QString section);
90       void readUnsorted(XmlReader& e, const QString section, bool br, bool ssm, bool bls, bool tbr);
91       void readFamily(XmlReader& e, const QString section, bool br, bool ssm, bool bls, bool tbr);
92       void readSection(XmlReader& e);
93       QString getFamilyName(const InstrumentTemplate *instrTemplate, bool soloist) const;
94       void createUnsortedGroup();
95 
96 
97    public:
98       QList<ScoreGroup*> groups;
99 
100       ScoreOrder(const QString id, const QString name=QString());
101       ~ScoreOrder();
102       ScoreOrder* clone();
103 
104       QString getId() const;
105       QString getName() const;
106       QString getFullName() const;
107       bool isCustom() const;
108       void setOwner(Score *score);
109       Score* getOwner() const;
110       bool isCustomized() const;
111       void setCustomized();
112 
113       ScoreGroup* getGroup(const QString family, const QString instrumentGroup) const;
114       ScoreGroup* getGroup(const QString instrumentId, bool soloist) const;
115 
116       void read(XmlReader& e);
117       void write(XmlWriter& xml) const;
118 
119       int instrumentIndex(const QString id, bool soloist) const;
120       bool instrumentInUnsortedSection(const QString id, bool soloist) const;
121 
122       void updateInstruments(const Score* score);
123       void setBracketsAndBarlines(Score* score);
124       bool isScoreOrder(const QList<int>& indices) const;
125       bool isScoreOrder(const Score* score) const;
126 
127       void dump() const;
128 
129       friend class ScoreOrderList;
130       };
131 
132 //---------------------------------------------------------
133 //   ScoreOrderList
134 //---------------------------------------------------------
135 
136 class ScoreOrderList {
137    protected:
138       QList<ScoreOrder*> _orders;
139 
140       void append(ScoreOrder* order);
141 
142    public:
143       ScoreOrderList();
144       ~ScoreOrderList();
145 
146       ScoreOrder* findById(const QString& orderId) const;
147       ScoreOrder* getById(const QString& orderId);
148       ScoreOrder* findByName(const QString& orderName, bool customized=false);
149       ScoreOrder* customScoreOrder() const;
150       int getScoreOrderIndex(const ScoreOrder* order) const;
151       QList<ScoreOrder*> searchScoreOrders(const QList<int>& indices) const;
152       QList<ScoreOrder*> searchScoreOrders(const Score* score) const;
153       void addScoreOrder(ScoreOrder* order);
154       void removeScoreOrder(ScoreOrder* order);
155 
156       void read(XmlReader& e);
157       void write(XmlWriter& xml) const;
158 
159       int size() const;
160 
161       ScoreOrder* operator[](const int) const;
162 
163       void dump() const;
164       };
165 
166 extern ScoreOrderList scoreOrders;
167 
168 extern bool loadScoreOrders(const QString& scoreOrderFileName);
169 extern bool saveScoreOrders(const QString& scoreOrderFileName);
170 
171 } // namespace Ms
172 
173 #endif
174