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) 2025 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 "transaction/undoablecommand.h"
26 :
27 : #include "../compat/midi/midipatch.h"
28 : #include "../dom/drumset.h"
29 : #include "../dom/instrument.h"
30 : #include "../dom/part.h"
31 : #include "../dom/score.h"
32 :
33 : namespace mu::engraving {
34 : class InsertPart : public UndoableCommand
35 : {
36 27 : OBJECT_ALLOCATOR(engraving, InsertPart)
37 :
38 : Part* m_part = nullptr;
39 : size_t m_targetPartIdx = 0;
40 :
41 : public:
42 : InsertPart(Part* p, size_t targetPartIdx);
43 : void undo() override;
44 : void redo() override;
45 : void cleanup(bool) override;
46 :
47 19 : UNDO_TYPE(CommandType::InsertPart)
48 0 : UNDO_NAME("InsertPart")
49 57 : UNDO_CHANGED_OBJECTS({ m_part })
50 : };
51 :
52 : class RemovePart : public UndoableCommand
53 : {
54 13 : OBJECT_ALLOCATOR(engraving, RemovePart)
55 :
56 : Part* m_part = nullptr;
57 : size_t m_partIdx = muse::nidx;
58 :
59 : public:
60 : RemovePart(Part*, size_t partIdx);
61 : void undo() override;
62 : void redo() override;
63 : void cleanup(bool) override;
64 :
65 9 : UNDO_TYPE(CommandType::RemovePart)
66 0 : UNDO_NAME("RemovePart")
67 27 : UNDO_CHANGED_OBJECTS({ m_part })
68 : };
69 :
70 : class SetSoloist : public UndoableCommand
71 : {
72 0 : OBJECT_ALLOCATOR(engraving, SetSoloist)
73 :
74 : Part* part = nullptr;
75 : bool soloist = false;
76 :
77 : public:
78 : SetSoloist(Part* p, bool b);
79 : void undo() override;
80 : void redo() override;
81 :
82 0 : UNDO_TYPE(CommandType::SetSoloist)
83 0 : UNDO_NAME("SetSoloist")
84 0 : UNDO_CHANGED_OBJECTS({ part })
85 : };
86 :
87 : class ChangePart : public UndoableCommand
88 : {
89 8 : OBJECT_ALLOCATOR(engraving, ChangePart)
90 :
91 : Part* part = nullptr;
92 : Instrument* instrument = nullptr;
93 :
94 : void flip() override;
95 :
96 : public:
97 : ChangePart(Part*, Instrument*);
98 : void cleanup(bool) override;
99 :
100 6 : UNDO_TYPE(CommandType::ChangePart)
101 0 : UNDO_NAME("ChangePart")
102 18 : UNDO_CHANGED_OBJECTS({ part })
103 : };
104 :
105 : class ChangeInstrumentLong : public UndoableCommand
106 : {
107 4 : OBJECT_ALLOCATOR(engraving, ChangeInstrumentLong)
108 :
109 : Part* part = nullptr;
110 : Fraction tick;
111 : String longName;
112 :
113 : void flip() override;
114 :
115 : public:
116 : ChangeInstrumentLong(const Fraction&, Part*, const String&);
117 :
118 2 : UNDO_TYPE(CommandType::ChangeInstrumentLong)
119 0 : UNDO_NAME("ChangeInstrumentLong")
120 6 : UNDO_CHANGED_OBJECTS({ part })
121 : };
122 :
123 : class ChangeInstrumentShort : public UndoableCommand
124 : {
125 2 : OBJECT_ALLOCATOR(engraving, ChangeInstrumentShort)
126 :
127 : Part* part = nullptr;
128 : Fraction tick;
129 : String shortName;
130 :
131 : void flip() override;
132 :
133 : public:
134 : ChangeInstrumentShort(const Fraction&, Part*, const String&);
135 :
136 2 : UNDO_TYPE(CommandType::ChangeInstrumentShort)
137 0 : UNDO_NAME("ChangeInstrumentShort")
138 6 : UNDO_CHANGED_OBJECTS({ part })
139 : };
140 :
141 : class ChangeInstrumentGroupOptions : public UndoableCommand
142 : {
143 0 : OBJECT_ALLOCATOR(engraving, ChangeInstrumentGroupOptions)
144 :
145 : Part* part = nullptr;
146 : Fraction tick;
147 : bool useCustom;
148 : String longName;
149 : String shortName;
150 :
151 : void flip() override;
152 :
153 : public:
154 : ChangeInstrumentGroupOptions(const Fraction&, Part*, bool, const String&, const String&);
155 :
156 0 : UNDO_TYPE(CommandType::ChangeInstrumentGroupOptions)
157 0 : UNDO_NAME("ChangeInstrumentGroupOptions")
158 0 : UNDO_CHANGED_OBJECTS({ part })
159 : };
160 :
161 : class ChangeInstrumentNumber : public UndoableCommand
162 : {
163 0 : OBJECT_ALLOCATOR(engraving, ChangeInstrumentNumber)
164 :
165 : Part* part = nullptr;
166 : Fraction tick;
167 : int number;
168 :
169 : void flip() override;
170 :
171 : public:
172 : ChangeInstrumentNumber(const Fraction&, Part*, int v);
173 :
174 0 : UNDO_TYPE(CommandType::ChangeInstrumentNumber)
175 0 : UNDO_NAME("ChangeInstrumentNumber")
176 0 : UNDO_CHANGED_OBJECTS({ part })
177 : };
178 :
179 : class ChangeDrumset : public UndoableCommand
180 : {
181 4 : OBJECT_ALLOCATOR(engraving, ChangeDrumset)
182 :
183 : Instrument* instrument = nullptr;
184 : Drumset drumset;
185 : Part* part = nullptr;
186 :
187 : void flip() override;
188 :
189 : public:
190 2 : ChangeDrumset(Instrument* i, const Drumset& d, Part* p)
191 2 : : instrument(i), drumset(d), part(p) {}
192 :
193 2 : UNDO_TYPE(CommandType::ChangeDrumset)
194 0 : UNDO_NAME("ChangeDrumset")
195 : };
196 :
197 : class ChangeStringData : public UndoableCommand
198 : {
199 : Instrument* m_instrument = nullptr;
200 : StringTunings* m_stringTunings = nullptr;
201 : StringData m_stringData;
202 :
203 : public:
204 0 : ChangeStringData(StringTunings* stringTunings, const StringData& stringData)
205 0 : : m_stringTunings(stringTunings), m_stringData(stringData) {}
206 0 : ChangeStringData(Instrument* instrument, const StringData& stringData)
207 0 : : m_instrument(instrument), m_stringData(stringData) {}
208 :
209 : void flip() override;
210 0 : UNDO_NAME("ChangeStringData")
211 : };
212 :
213 : class ChangePatch : public UndoableCommand
214 : {
215 2 : OBJECT_ALLOCATOR(engraving, ChangePatch)
216 :
217 : Score* score = nullptr;
218 : InstrChannel* channel = nullptr;
219 : MidiPatch patch;
220 :
221 : void flip() override;
222 :
223 : public:
224 1 : ChangePatch(Score* s, InstrChannel* c, const MidiPatch& pt)
225 1 : : score(s), channel(c), patch(pt) {}
226 0 : UNDO_NAME("ChangePatch")
227 3 : UNDO_CHANGED_OBJECTS({ score })
228 : };
229 :
230 : class SetUserBankController : public UndoableCommand
231 : {
232 0 : OBJECT_ALLOCATOR(engraving, SetUserBankController)
233 :
234 : InstrChannel* channel = nullptr;
235 : bool val = false;
236 :
237 : void flip() override;
238 :
239 : public:
240 0 : SetUserBankController(InstrChannel* c, bool v)
241 0 : : channel(c), val(v) {}
242 0 : UNDO_NAME("SetUserBankController")
243 : };
244 :
245 : class InstrumentTemplate;
246 : struct ScoreOrder;
247 : class Staff;
248 : class StaffType;
249 : enum class PreferSharpFlat : char;
250 : enum class StaffTypes : signed char;
251 :
252 : class EditPart
253 : {
254 : public:
255 : static void replacePartInstrument(Score* score, Part* part, const Instrument& newInstrument, const StaffType* newStaffType = nullptr);
256 :
257 : static bool replaceInstrumentAtTick(Score* score, Part* part, const Fraction& tick, const Instrument& newInstrument);
258 :
259 : static void setPartVisible(Score* score, Part* part, bool visible);
260 : static void setStaffVisible(Score* score, Staff* staff, bool visible);
261 : static void setPartSharpFlat(Score* score, Part* part, PreferSharpFlat sharpFlat);
262 : static void setInstrumentName(Score* score, Part* part, const Fraction& tick, const String& name);
263 : static void setInstrumentAbbreviature(Score* score, Part* part, const Fraction& tick, const String& abbreviature);
264 : static void setInstrumentGroupNameOptions(Score* score, Part* part, const Fraction& tick, bool useCustom, const String& longName,
265 : const String& shortName);
266 : static void setInstrumentCustomGroupAbbreviature(Score* score, Part* part, const Fraction& tick, const String& abbreviature);
267 : static void setStaffType(Score* score, Staff* staff, StaffTypes typeId);
268 :
269 : static void removeParts(Score* score, const std::vector<Part*>& parts);
270 : static void removeStaves(Score* score, const std::vector<Staff*>& staves);
271 : static void moveParts(Score* score, const std::vector<Part*>& sourceParts, Part* destinationPart, bool insertAfter);
272 : static void moveStaves(Score* score, const std::vector<Staff*>& sourceStaves, Staff* destinationStaff, bool insertAfter);
273 :
274 : static void addSystemObjects(Score* score, const std::vector<Staff*>& staves);
275 : static void removeSystemObjects(Score* score, const std::vector<Staff*>& staves);
276 : static void moveSystemObjects(Score* score, Staff* sourceStaff, Staff* destinationStaff);
277 :
278 : static Staff* appendStaff(Score* score, Part* destinationPart);
279 : static Staff* appendLinkedStaff(Score* score, Staff* sourceStaff, Part* destinationPart);
280 :
281 : static bool setVoiceVisible(Score* score, Staff* staff, int voiceIndex, bool visible);
282 :
283 : static void replaceDrumset(Score* score, Part* part, const Fraction& tick, const Drumset& newDrumset);
284 :
285 : static void insertPart(Score* score, const InstrumentTemplate* templ, size_t index);
286 : static void replacePart(Score* score, Part* oldPart, const InstrumentTemplate* templ);
287 :
288 : static void setScoreOrder(Score* score, const ScoreOrder& order);
289 :
290 : private:
291 : static void doAppendStaff(Score* score, Staff* staff, Part* destinationPart, bool createRests = true);
292 : };
293 : }
|