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) 2026 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 <optional>
26 : #include <vector>
27 :
28 : #include "engraving/types/types.h"
29 :
30 : namespace mu::engraving {
31 : class EngravingItem;
32 : class EngravingObject;
33 :
34 : enum class CommandType : signed char {
35 : Unknown = -1,
36 :
37 : // Parts
38 : InsertPart,
39 : RemovePart,
40 : AddPartToExcerpt,
41 : SetSoloist,
42 : ChangePart,
43 : ConnectSharedPart,
44 : DisconnectSharedPart,
45 :
46 : // Staves
47 : InsertStaff,
48 : RemoveStaff,
49 : AddSystemObjectStaff,
50 : RemoveSystemObjectStaff,
51 : SortStaves,
52 : ChangeStaff,
53 : ChangeStaffType,
54 : AddStaveSharingChange,
55 : ChangeStaveSharingState,
56 : ChangeStaveSharingIsReset,
57 : RemoveStaveSharingChange,
58 :
59 : // MStaves
60 : InsertMStaff,
61 : RemoveMStaff,
62 : InsertStaves,
63 : RemoveStaves,
64 : ChangeMStaffProperties,
65 : ChangeMStaffHideIfEmpty,
66 :
67 : // Instruments
68 : ChangeInstrumentShort,
69 : ChangeInstrumentLong,
70 : ChangeInstrumentGroupOptions,
71 : ChangeInstrumentNumber,
72 : ChangeInstrument,
73 : ChangeDrumset,
74 :
75 : // Measures
76 : RemoveMeasures,
77 : InsertMeasures,
78 : ChangeMeasureLen,
79 : ChangeMMRest,
80 : ChangeMeasureRepeatCount,
81 :
82 : // Elements
83 : AddElement,
84 : RemoveElement,
85 : Unlink,
86 : Link,
87 : ChangeElement,
88 : ChangeParent,
89 :
90 : // Notes
91 : ChangePitch,
92 : ChangeFretting,
93 : ChangeVelocity,
94 :
95 : // ChordRest
96 : ChangeChordStaffMove,
97 : SwapCR,
98 : AddNoteParenthesesInfo,
99 : RemoveNoteParenthesesInfo,
100 : RemoveSingleNoteParentheses,
101 :
102 : // Brackets
103 : RemoveBracket,
104 : AddBracket,
105 :
106 : // Fret
107 : FretDataChange,
108 : FretDot,
109 : FretMarker,
110 : FretBarre,
111 : FretClear,
112 : AddFretDiagramToFretBox,
113 : RemoveFretDiagramFromFretBox,
114 :
115 : // Harmony
116 : TransposeHarmony,
117 :
118 : // KeySig
119 : ChangeKeySig,
120 :
121 : // Clef
122 : ChangeClefType,
123 :
124 : // Tremolo
125 : MoveTremolo,
126 :
127 : // Spanners
128 : ChangeSpannerElements,
129 : InsertTimeUnmanagedSpanner,
130 : ChangeStartEndSpanner,
131 :
132 : // Ties
133 : ChangeTieEndPointActive,
134 :
135 : // Style
136 : ChangeStyle,
137 : ChangeStyleValues,
138 :
139 : // Property
140 : ChangeProperty,
141 :
142 : // Voices
143 : ExchangeVoice,
144 :
145 : // Excerpts
146 : AddExcerpt,
147 : RemoveExcerpt,
148 : SwapExcerpt,
149 : ChangeExcerptTitle,
150 :
151 : // Meta info
152 : ChangeMetaInfo,
153 :
154 : // Text
155 : TextEdit,
156 :
157 : // Automation
158 : EditAutomationPoints,
159 :
160 : // Other
161 : InsertTime,
162 : ChangeScoreOrder,
163 : };
164 :
165 : enum class UndoableCommandFilter : unsigned char {
166 : TextEdit,
167 : AddElement,
168 : AddElementLinked,
169 : Link,
170 : RemoveElement,
171 : RemoveElementLinked,
172 : ChangePropertyLinked,
173 : };
174 :
175 : #define UNDO_TYPE(t) CommandType type() const override { return t; }
176 : #define UNDO_NAME(a) const char* name() const override { return a; }
177 : #define UNDO_CHANGED_OBJECTS(...) std::vector<EngravingObject*> objectItems() const override { return __VA_ARGS__; }
178 :
179 : struct ChangedRange {
180 : Fraction tickFrom;
181 : Fraction tickTo;
182 : staff_idx_t staffIdxFrom = muse::nidx;
183 : staff_idx_t staffIdxTo = muse::nidx;
184 : };
185 :
186 : class UndoableCommand
187 : {
188 : public:
189 40866 : virtual ~UndoableCommand() = default;
190 :
191 : virtual void undo();
192 : virtual void redo();
193 :
194 5505 : virtual void cleanup(bool /*wasDone*/) {}
195 :
196 1440 : virtual std::vector<EngravingObject*> objectItems() const { return {}; }
197 0 : virtual const char* name() const { return "UndoableCommand"; }
198 301 : virtual CommandType type() const { return CommandType::Unknown; }
199 :
200 27243 : virtual std::optional<ChangedRange> changedRange() const { return std::nullopt; }
201 :
202 0 : virtual bool matchesFilter(UndoableCommandFilter, const EngravingItem* /* target */) const { return false; }
203 :
204 : protected:
205 0 : virtual void flip() {}
206 : };
207 :
208 : std::vector<EngravingObject*> compoundObjects(EngravingObject* object);
209 : }
|