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 __PART_H__
14 #define __PART_H__
15 
16 #include "mscore.h"
17 #include "instrument.h"
18 #include "text.h"
19 
20 namespace Ms {
21 
22 class XmlWriter;
23 class Staff;
24 class Score;
25 class InstrumentTemplate;
26 
27 //---------------------------------------------------------
28 //   PreferSharpFlat
29 //---------------------------------------------------------
30 
31 enum class PreferSharpFlat : char {
32       DEFAULT, SHARPS, FLATS
33       };
34 
35 //---------------------------------------------------------
36 //   @@ Part
37 //   @P endTrack        int         (read only)
38 //   @P harmonyCount    int         (read only)
39 //   @P hasDrumStaff    bool        (read only)
40 //   @P hasPitchedStaff bool        (read only)
41 //   @P hasTabStaff     bool        (read only)
42 //   @P instrumentId    string      (read only)
43 //   @P longName        string
44 //   @P lyricCount      int         (read only)
45 //   @P midiChannel     int         (read only)
46 //   @P midiProgram     int         (read only)
47 //   @P mute            bool
48 //   @P partName        string      name of the part, used in the mixer
49 //   @P shortName       string
50 //   @P show            bool        check/set whether or not a part is shown
51 //   @P startTrack      int         (read only)
52 //   @P volume          int
53 //---------------------------------------------------------
54 
55 class Part final : public ScoreElement {
56       QString _partName;            ///< used in tracklist (mixer)
57       InstrumentList _instruments;
58       QList<Staff*> _staves;
59       QString _id;                  ///< used for MusicXml import
60       bool _show;                   ///< show part in partitur if true
61       bool _soloist;                ///< used in score ordering
62 
63       static const int DEFAULT_COLOR = 0x3399ff;
64       int _color;                   ///User specified color for helping to label parts
65 
66       PreferSharpFlat _preferSharpFlat;
67 
68    public:
69       Part(Score* = 0);
70       void initFromInstrTemplate(const InstrumentTemplate*);
71 
type()72       ElementType type() const override { return ElementType::PART; }
73 
74       void read(XmlReader&);
75       bool readProperties(XmlReader&);
76       void write(XmlWriter& xml) const;
77 
nstaves()78       int nstaves() const                       { return _staves.size(); }
staves()79       QList<Staff*>* staves()                   { return &_staves; }
staves()80       const QList<Staff*>* staves() const       { return &_staves; }
81       Staff* staff(int idx) const;
setId(const QString & s)82       void setId(const QString& s)              { _id = s; }
id()83       QString id() const                        { return _id; }
84 
85       int startTrack() const;
86       int endTrack() const;
87 
88       QString longName(const Fraction& tick = { -1, 1 } ) const;
89       QString shortName(const Fraction& tick = { -1, 1 } ) const;
90       QString instrumentName(const Fraction& tick = { -1, 1 } ) const;
91       QString instrumentId(const Fraction& tick = { -1, 1 } ) const;
92 
93       const QList<StaffName>& longNames(const  Fraction& tick = { -1, 1 } ) const { return instrument(tick)->longNames();  }
94       const QList<StaffName>& shortNames(const Fraction& tick = { -1, 1 } ) const { return instrument(tick)->shortNames(); }
95 
96       void setLongNames(QList<StaffName>& s,  const Fraction& tick = { -1, 1 } );
97       void setShortNames(QList<StaffName>& s, const Fraction& tick = { -1, 1 } );
98 
99       void setLongName(const QString& s);
100       void setShortName(const QString& s);
101 
102       void setPlainLongName(const QString& s);
103       void setPlainShortName(const QString& s);
104 
105       void setStaves(int);
106 
107       int midiProgram() const;
108       void setMidiProgram(int, int bank = 0);
109 
110       int midiChannel() const;
111       int midiPort() const;
112       void setMidiChannel(int ch, int port = -1, const Fraction& tick = {-1,1});  // tick != -1 for InstrumentChange
113 
114       void insertStaff(Staff*, int idx);
115       void removeStaff(Staff*);
show()116       bool show() const                        { return _show;     }
setShow(bool val)117       void setShow(bool val)                   { _show = val;      }
soloist()118       bool soloist() const                     { return _soloist;  }
setSoloist(bool val)119       void setSoloist(bool val)                { _soloist = val;   }
120 
121       Instrument* instrument(Fraction = { -1, 1 } );
122       const Instrument* instrument(Fraction = { -1, 1 }) const;
123       void setInstrument(Instrument*, Fraction = { -1, 1} );       // transfer ownership
124       void setInstrument(const Instrument&&, Fraction = { -1, 1 });
125       void setInstrument(const Instrument&, Fraction = { -1, 1 });
126       void removeInstrument(const Fraction&);
127       const InstrumentList* instruments() const;
128 
129       void insertTime(const Fraction& tick, const Fraction& len);
130 
partName()131       QString partName() const                 { return _partName; }
setPartName(const QString & s)132       void setPartName(const QString& s)       { _partName = s; }
color()133       int color() const { return _color; }
setColor(int value)134       void setColor(int value) { _color = value; }
135 
136       QVariant getProperty(Pid) const override;
137       bool setProperty(Pid, const QVariant&) override;
138 
139       int lyricCount() const;
140       int harmonyCount() const;
141       bool hasPitchedStaff() const;
142       bool hasTabStaff() const;
143       bool hasDrumStaff() const;
144 
145       void updateHarmonyChannels(bool isDoOnInstrumentChanged, bool checkRemoval = false);
146       const Channel* harmonyChannel() const;
147 
148       const Part* masterPart() const;
149       Part* masterPart();
150 
preferSharpFlat()151       PreferSharpFlat preferSharpFlat() const     { return _preferSharpFlat; }
setPreferSharpFlat(PreferSharpFlat v)152       void setPreferSharpFlat(PreferSharpFlat v)  { _preferSharpFlat = v;    }
153 
154       // Allows not reading the same instrument twice on importing 2.X scores.
155       // TODO: do we need instruments info in parts at all?
156       friend void readPart206(Part*, XmlReader&);
157       };
158 
159 }     // namespace Ms
160 #endif
161 
162