MuseScore  3.4
Music composition and notation
part.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 __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 // @@ Part
29 // @P endTrack int (read only)
30 // @P harmonyCount int (read only)
31 // @P hasDrumStaff bool (read only)
32 // @P hasPitchedStaff bool (read only)
33 // @P hasTabStaff bool (read only)
34 // @P instrumentId string (read only)
35 // @P longName string
36 // @P lyricCount int (read only)
37 // @P midiChannel int (read only)
38 // @P midiProgram int (read only)
39 // @P mute bool
40 // @P partName string name of the part, used in the mixer
41 // @P shortName string
42 // @P show bool check/set whether or not a part is shown
43 // @P startTrack int (read only)
44 // @P volume int
45 //---------------------------------------------------------
46 
47 class Part final : public ScoreElement {
48  QString _partName;
50  QList<Staff*> _staves;
51  QString _id;
52  bool _show;
53 
54  static const int DEFAULT_COLOR = 0x3399ff;
55  int _color;
56 
57  public:
58  Part(Score* = 0);
60  virtual ElementType type() const override { return ElementType::PART; }
61 
62  void read(XmlReader&);
64  void write(XmlWriter& xml) const;
65 
66  int nstaves() const { return _staves.size(); }
67  QList<Staff*>* staves() { return &_staves; }
68  const QList<Staff*>* staves() const { return &_staves; }
69  Staff* staff(int idx) const;
70  void setId(const QString& s) { _id = s; }
71  QString id() const { return _id; }
72 
73  int startTrack() const;
74  int endTrack() const;
75 
76  QString longName(const Fraction& tick = { -1, 1 } ) const;
77  QString shortName(const Fraction& tick = { -1, 1 } ) const;
78  QString instrumentName(const Fraction& tick = { -1, 1 } ) const;
79  QString instrumentId(const Fraction& tick = { -1, 1 } ) const;
80 
81  const QList<StaffName>& longNames(const Fraction& tick = { -1, 1 } ) const { return instrument(tick)->longNames(); }
82  const QList<StaffName>& shortNames(const Fraction& tick = { -1, 1 } ) const { return instrument(tick)->shortNames(); }
83 
84  void setLongNames(QList<StaffName>& s, const Fraction& tick = { -1, 1 } );
85  void setShortNames(QList<StaffName>& s, const Fraction& tick = { -1, 1 } );
86 
87  void setLongName(const QString& s);
88  void setShortName(const QString& s);
89 
90  void setPlainLongName(const QString& s);
91  void setPlainShortName(const QString& s);
92 
93  void setStaves(int);
94 
95  int midiProgram() const;
96  void setMidiProgram(int, int bank = 0);
97 
98  int midiChannel() const;
99  int midiPort() const;
100  void setMidiChannel(int ch, int port = -1, const Fraction& tick = {-1,1}); // tick != -1 for InstrumentChange
101 
102  void insertStaff(Staff*, int idx);
103  void removeStaff(Staff*);
104  bool show() const { return _show; }
105  void setShow(bool val) { _show = val; }
106 
107  Instrument* instrument(Fraction = { -1, 1 } );
108  const Instrument* instrument(Fraction = { -1, 1 }) const;
109  void setInstrument(Instrument*, Fraction = { -1, 1} ); // transfer ownership
110  void setInstrument(const Instrument&&, Fraction = { -1, 1 });
111  void setInstrument(const Instrument&, Fraction = { -1, 1 });
112  void removeInstrument(const Fraction&);
113  const InstrumentList* instruments() const;
114 
115  void insertTime(const Fraction& tick, const Fraction& len);
116 
117  QString partName() const { return _partName; }
118  void setPartName(const QString& s) { _partName = s; }
119  int color() const { return _color; }
120  void setColor(int value) { _color = value; }
121 
122  QVariant getProperty(Pid) const override;
123  bool setProperty(Pid, const QVariant&) override;
124 
125  int lyricCount() const;
126  int harmonyCount() const;
127  bool hasPitchedStaff() const;
128  bool hasTabStaff() const;
129  bool hasDrumStaff() const;
130 
131  const Part* masterPart() const;
132  Part* masterPart();
133 
134  // Allows not reading the same instrument twice on importing 2.X scores.
135  // TODO: do we need instruments info in parts at all?
136  friend void readPart206(Part*, XmlReader&);
137  };
138 
139 } // namespace Ms
140 #endif
141 
const QList< StaffName > & longNames() const
Definition: instrument.cpp:1383
InstrumentList _instruments
Definition: part.h:49
void removeInstrument(const Fraction &)
Definition: part.cpp:307
Part(Score *=0)
User specified color for helping to label parts.
Definition: part.cpp:34
Global staff data not directly related to drawing.
Definition: staff.h:62
void setShow(bool val)
Definition: part.h:105
Pid
Definition: property.h:62
Definition: xml.h:67
QList< Staff * > _staves
Definition: part.h:50
void setMidiChannel(int ch, int port=-1, const Fraction &tick={-1, 1})
Definition: part.cpp:275
bool _show
show part in partitur if true
Definition: part.h:52
void removeStaff(Staff *)
Definition: part.cpp:217
QString shortName(const Fraction &tick={ -1, 1 }) const
Definition: part.cpp:376
int midiChannel() const
Definition: part.cpp:251
Definition: scoreElement.h:173
QString instrumentName(const Fraction &tick={ -1, 1 }) const
Definition: part.cpp:367
QString longName(const Fraction &tick={ -1, 1 }) const
Definition: part.cpp:357
void setColor(int value)
Definition: part.h:120
Definition: instrument.h:250
QList< Staff * > * staves()
Definition: part.h:67
QString partName() const
Definition: part.h:117
void setLongNames(QList< StaffName > &s, const Fraction &tick={ -1, 1 })
Definition: part.cpp:165
void write(XmlWriter &xml) const
Definition: part.cpp:147
int lyricCount() const
Definition: part.cpp:507
void setLongName(const QString &s)
Definition: part.cpp:386
friend void readPart206(Part *, XmlReader &)
Definition: read206.cpp:1088
Definition: score.h:391
bool readProperties(XmlReader &)
Definition: part.cpp:99
bool hasPitchedStaff() const
Definition: part.cpp:546
QString id() const
Definition: part.h:71
void initFromInstrTemplate(const InstrumentTemplate *)
Definition: part.cpp:46
virtual ElementType type() const override
Definition: part.h:60
int color() const
Definition: part.h:119
QString instrumentId(const Fraction &tick={ -1, 1 }) const
Definition: part.cpp:348
void insertStaff(Staff *, int idx)
Definition: part.cpp:205
int endTrack() const
Definition: part.cpp:468
QString _partName
used in tracklist (mixer)
Definition: part.h:48
int harmonyCount() const
Definition: part.cpp:527
Instrument * instrument(Fraction={ -1, 1 })
Definition: part.cpp:321
Definition: aeolus.cpp:26
void insertTime(const Fraction &tick, const Fraction &len)
Definition: part.cpp:477
int nstaves() const
Definition: part.h:66
const QList< Staff * > * staves() const
Definition: part.h:68
Definition: xml.h:218
const InstrumentList * instruments() const
Definition: part.cpp:339
int midiProgram() const
Definition: part.cpp:242
void setId(const QString &s)
Definition: part.h:70
Definition: xmlwriter.h:26
int _color
Definition: part.h:55
int midiPort() const
Definition: part.cpp:260
void setInstrument(Instrument *, Fraction={ -1, 1})
Definition: part.cpp:288
void setPlainShortName(const QString &s)
Definition: part.cpp:413
QString _id
used for MusicXml import
Definition: part.h:51
const QList< StaffName > & shortNames(const Fraction &tick={ -1, 1 }) const
Definition: part.h:82
void setPlainLongName(const QString &s)
Definition: part.cpp:404
QVariant getProperty(Pid) const override
Definition: part.cpp:422
void read(XmlReader &)
Definition: part.cpp:133
bool hasDrumStaff() const
Definition: part.cpp:576
static const int DEFAULT_COLOR
Definition: part.h:54
bool hasTabStaff() const
Definition: part.cpp:561
int startTrack() const
Definition: part.cpp:459
void setShortName(const QString &s)
Definition: part.cpp:395
bool show() const
Definition: part.h:104
Definition: fraction.h:46
Staff * staff(int idx) const
Definition: part.cpp:56
ElementType
Definition: types.h:34
Definition: instrtemplate.h:48
Definition: instrument.h:353
const QList< StaffName > & longNames(const Fraction &tick={ -1, 1 }) const
Definition: part.h:81
const QList< StaffName > & shortNames() const
Definition: instrument.cpp:1392
const Part * masterPart() const
Definition: part.cpp:65
bool setProperty(Pid, const QVariant &) override
Definition: part.cpp:438
Definition: part.h:47
void setPartName(const QString &s)
Definition: part.h:118
void setShortNames(QList< StaffName > &s, const Fraction &tick={ -1, 1 })
Definition: part.cpp:170
void setStaves(int)
Definition: part.cpp:179
void setMidiProgram(int, int bank=0)
Definition: part.cpp:230