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