Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-Studio-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2021 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 :
23 : #pragma once
24 :
25 : #include <vector>
26 :
27 : #include "instrument.h"
28 : #include "../types/types.h"
29 :
30 : namespace mu::engraving {
31 : class Staff;
32 : class Score;
33 : class SharedPart;
34 : class InstrumentTemplate;
35 :
36 : struct TrackRange {
37 : track_idx_t startTrack = muse::nidx;
38 : track_idx_t endTrack = muse::nidx;
39 : };
40 :
41 : //---------------------------------------------------------
42 : // @@ Part
43 : // @P endTrack int (read only)
44 : // @P harmonyCount int (read only)
45 : // @P hasDrumStaff bool (read only)
46 : // @P hasPitchedStaff bool (read only)
47 : // @P hasTabStaff bool (read only)
48 : // @P instrumentId string (read only)
49 : // @P longName string
50 : // @P lyricCount int (read only)
51 : // @P midiChannel int (read only)
52 : // @P midiProgram int (read only)
53 : // @P mute bool
54 : // @P partName string name of the part, used in the mixer
55 : // @P shortName string
56 : // @P show bool check/set whether or not a part is shown
57 : // @P startTrack int (read only)
58 : // @P volume int
59 : //---------------------------------------------------------
60 :
61 : class Part : public EngravingObject
62 : {
63 5813 : OBJECT_ALLOCATOR(engraving, Part)
64 : DECLARE_CLASSOF(ElementType::PART)
65 :
66 : public:
67 : static const Fraction MAIN_INSTRUMENT_TICK;
68 :
69 : Part(Score* score = nullptr, ElementType type = ElementType::PART);
70 : void initFromInstrTemplate(const InstrumentTemplate*);
71 :
72 : const muse::ID& id() const;
73 : void setId(const muse::ID& id);
74 :
75 : Part* clone() const;
76 :
77 : size_t nstaves() const;
78 : size_t visibleStavesCount() const;
79 : const std::vector<Staff*>& staves() const;
80 : std::set<staff_idx_t> staveIdxList() const;
81 : void appendStaff(Staff* staff);
82 : void clearStaves();
83 :
84 : Staff* staff(staff_idx_t idx) const;
85 : String familyId() const;
86 :
87 : TrackRange trackRange() const;
88 :
89 : InstrumentTrackIdList instrumentTrackIdList() const;
90 : InstrumentTrackIdSet instrumentTrackIdSet() const;
91 :
92 : String longName(const Fraction& tick = { -1, 1 }) const;
93 : String shortName(const Fraction& tick = { -1, 1 }) const;
94 : String instrumentName(const Fraction& tick = { -1, 1 }) const;
95 : String instrumentId(const Fraction& tick = { -1, 1 }) const;
96 :
97 : void setLongName(const String& s, const Fraction& tick = { -1, 1 });
98 : void setShortName(const String& s, const Fraction& tick = { -1, 1 });
99 : void setLongNameAll(const String& s); // For all instruments in _instruments
100 : void setShortNameAll(const String& s); // For all instruments in _instruments
101 :
102 : int number(const Fraction& tick = { -1, 1 }) const;
103 : void setNumber(int v, const Fraction& tick = { -1, 1 });
104 :
105 : String transposition(const Fraction& tick = { -1, 1 }) const;
106 : void setTransposition(const String& s, const Fraction& tick = { -1, 1 });
107 :
108 : void setPlainLongName(const String& s);
109 : void setPlainShortName(const String& s);
110 : void setPlainLongNameAll(const String& s);
111 : void setPlainShortNameAll(const String& s);
112 :
113 : void setStaves(int);
114 :
115 : int midiProgram() const;
116 : void setMidiProgram(int, int bank = 0);
117 :
118 : int midiChannel() const;
119 : int midiPort() const;
120 : void setMidiChannel(int ch, int port = -1, const Fraction& tick = { -1, 1 }); // tick != -1 for InstrumentChange
121 :
122 : void insertStaff(Staff*, staff_idx_t idx);
123 : void removeStaff(Staff*);
124 : virtual bool show() const;
125 484 : void setShow(bool val) { m_show = val; }
126 1830 : bool soloist() const { return m_soloist; }
127 1 : void setSoloist(bool val) { m_soloist = val; }
128 :
129 : Instrument* instrument(Fraction = { -1, 1 });
130 : const Instrument* instrument(Fraction = { -1, 1 }) const;
131 : const Instrument* instrumentById(const String& id) const;
132 : void setInstrument(Instrument*, Fraction = { -1, 1 }); // transfer ownership
133 : void setInstrument(Instrument*, int tick);
134 : void setInstrument(const Instrument&&, Fraction = { -1, 1 });
135 : void setInstrument(const Instrument&, Fraction = { -1, 1 });
136 : void setInstruments(const InstrumentList& instruments);
137 : void removeInstrument(Instrument*, const Fraction&);
138 : void removeNonPrimaryInstruments();
139 : const InstrumentList& instruments() const;
140 :
141 : const std::map<int, StringTunings*>& stringTunings() const { return m_stringTunings; }
142 : const StringData* stringData(const Fraction& tick, staff_idx_t staffIdx) const;
143 : void addStringTunings(StringTunings* stringTunings);
144 : void removeStringTunings(StringTunings* stringTunings);
145 : StringTunings* nextStringTuning(const Fraction& tick) const;
146 :
147 : void insertTime(const Fraction& tick, const Fraction& len);
148 :
149 18 : const std::map<int, HarpPedalDiagram*>& harpDiagrams() const { return m_harpDiagrams; }
150 : void addHarpDiagram(HarpPedalDiagram*);
151 : void removeHarpDiagram(HarpPedalDiagram*);
152 : void clearHarpDiagrams();
153 : HarpPedalDiagram* currentHarpDiagram(const Fraction&) const;
154 : HarpPedalDiagram* nextHarpDiagram(const Fraction&) const;
155 : HarpPedalDiagram* prevHarpDiagram(const Fraction&) const;
156 : Fraction currentHarpDiagramTick(const Fraction&) const;
157 :
158 : virtual String partName() const;
159 :
160 : bool isVisible() const;
161 :
162 : PropertyValue getProperty(Pid) const override;
163 : bool setProperty(Pid, const PropertyValue&) override;
164 :
165 : int lyricCount() const;
166 : int harmonyCount() const;
167 : bool hasPitchedStaff() const;
168 : bool hasTabStaff() const;
169 : bool hasDrumStaff() const;
170 :
171 : void updateHarmonyChannels(bool isDoOnInstrumentChanged, bool checkRemoval = false);
172 : const InstrChannel* harmonyChannel() const;
173 : bool hasChordSymbol() const;
174 :
175 : const Part* masterPart() const;
176 : Part* masterPart();
177 :
178 7398 : AutoOnOff hideWhenEmpty() const { return m_hideWhenEmpty; }
179 4 : void setHideWhenEmpty(AutoOnOff v) { m_hideWhenEmpty = v; }
180 :
181 1804 : bool hideStavesWhenIndividuallyEmpty() const { return m_hideStavesWhenIndividuallyEmpty; }
182 6 : void setHideStavesWhenIndividuallyEmpty(bool v) { m_hideStavesWhenIndividuallyEmpty = v; }
183 :
184 5905 : PreferSharpFlat preferSharpFlat() const { return m_preferSharpFlat; }
185 107 : void setPreferSharpFlat(PreferSharpFlat v) { m_preferSharpFlat = v; }
186 :
187 : virtual const Part* originPart(track_idx_t track, const Fraction& tick) const;
188 : Part* originPart(track_idx_t track, const Fraction& tick);
189 :
190 3585409 : SharedPart* sharedPart() const { return m_sharedPart; }
191 38 : void setSharedPart(SharedPart* p) { m_sharedPart = p; }
192 :
193 : private:
194 : friend class SharedPart;
195 :
196 : InstrumentList m_instruments;
197 : std::vector<Staff*> m_staves;
198 : muse::ID m_id = INVALID_ID; ///< used for MusicXML import
199 : bool m_show = false; ///< show part in partitur if true
200 : bool m_soloist = false; ///< used in score ordering
201 :
202 : /// Hide staves in this part when empty
203 : AutoOnOff m_hideWhenEmpty = AutoOnOff::AUTO;
204 :
205 : /// Hide staves when they are individually empty, rather than only if all this part's staves are empty
206 : bool m_hideStavesWhenIndividuallyEmpty = false;
207 :
208 : PreferSharpFlat m_preferSharpFlat = PreferSharpFlat::AUTO;
209 :
210 : std::map<int, HarpPedalDiagram*> m_harpDiagrams;
211 : std::map<int, StringTunings*> m_stringTunings;
212 :
213 : SharedPart* m_sharedPart = nullptr;
214 : };
215 : }
|