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
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 : #include "reset.h"
24 :
25 : #include <vector>
26 :
27 : #include "global/containers.h"
28 :
29 : #include "../dom/engravingitem.h"
30 : #include "../dom/layoutbreak.h"
31 : #include "../dom/measure.h"
32 : #include "../dom/score.h"
33 : #include "../dom/segment.h"
34 : #include "../dom/select.h"
35 : #include "../dom/spacer.h"
36 :
37 : #include "editsystemlocks.h"
38 :
39 : #include "log.h"
40 :
41 : using namespace mu;
42 : using namespace muse;
43 : using namespace mu::engraving;
44 :
45 : //---------------------------------------------------------
46 : // For use with Score::scanElements.
47 : // Reset positions and autoplacement for the given
48 : // element.
49 : //---------------------------------------------------------
50 :
51 375 : static void resetElementPosition(EngravingItem* e)
52 : {
53 375 : if (e->generated()) {
54 142 : return;
55 : }
56 :
57 233 : e->undoResetProperty(Pid::AUTOPLACE);
58 233 : e->undoResetProperty(Pid::OFFSET);
59 233 : e->undoResetProperty(Pid::LEADING_SPACE);
60 233 : if (e->isSpanner()) {
61 0 : e->undoResetProperty(Pid::OFFSET2);
62 : }
63 : }
64 :
65 0 : static void resetTextProperties(EngravingItem* e)
66 : {
67 0 : if (e->generated() || !e->isTextBase()) {
68 0 : return;
69 : }
70 :
71 : static const std::vector<Pid> TEXT_STYLE_TO_RESET {
72 : Pid::FONT_FACE,
73 : Pid::FONT_SIZE,
74 : Pid::FONT_STYLE,
75 : Pid::SIZE_SPATIUM_DEPENDENT,
76 : Pid::FRAME_TYPE,
77 : Pid::TEXT_LINE_SPACING,
78 : Pid::FRAME_FG_COLOR,
79 : Pid::FRAME_BG_COLOR,
80 : Pid::FRAME_WIDTH,
81 : Pid::FRAME_PADDING,
82 : Pid::FRAME_ROUND,
83 : Pid::ALIGN
84 0 : };
85 :
86 0 : for (Pid pid : TEXT_STYLE_TO_RESET) {
87 : // TODO: use undoResetProperty: https://github.com/musescore/MuseScore/issues/16516
88 : // But for now, we'll use resetPropety since undoResetProperty leads to various problems
89 0 : e->resetProperty(pid);
90 : }
91 : }
92 :
93 0 : void Reset::resetToDefaultLayout(Transaction& tx, Score* score)
94 : {
95 0 : TRACEFUNC;
96 :
97 : StyleIdSet dontResetTheseStyles {
98 : Sid::lyricsPlacement,
99 : Sid::repeatBarTips,
100 : Sid::startBarlineSingle,
101 : Sid::startBarlineMultiple,
102 : Sid::dividerLeft,
103 : Sid::dividerRightY,
104 : Sid::useStraightNoteFlags,
105 : Sid::mrNumberSeries,
106 : Sid::mrNumberEveryXMeasures,
107 : Sid::mrNumberSeriesWithParentheses,
108 : Sid::oneMeasureRepeatShow1,
109 : Sid::fourMeasureRepeatShowExtenders,
110 : Sid::useWideBeams,
111 : Sid::hairpinPlacement,
112 : Sid::pedalPlacement,
113 : Sid::trillPlacement,
114 : Sid::vibratoPlacement,
115 : Sid::harmonyPlacement,
116 : Sid::romanNumeralPlacement,
117 : Sid::nashvilleNumberPlacement,
118 : Sid::harmonyVoiceLiteral,
119 : Sid::harmonyVoicing,
120 : Sid::harmonyDuration,
121 : Sid::capoPosition,
122 : Sid::fretNumPos,
123 : Sid::fretPlacement,
124 : Sid::fretStrings,
125 : Sid::fretFrets,
126 : Sid::fretNut,
127 : Sid::fretOrientation,
128 : Sid::showPageNumber,
129 : Sid::showPageNumberOne,
130 : Sid::pageNumberOddEven,
131 : Sid::showMeasureNumber,
132 : Sid::showMeasureNumberOne,
133 : Sid::measureNumberInterval,
134 : Sid::measureNumberSystem,
135 : Sid::measureNumberPlacementMode,
136 : Sid::genClef,
137 : Sid::hideTabClefAfterFirst,
138 : Sid::genKeysig,
139 : Sid::genCourtesyTimesig,
140 : Sid::genCourtesyKeysig,
141 : Sid::genCourtesyClef,
142 : Sid::swingRatio,
143 : Sid::swingUnit,
144 : Sid::chordSymbolSpelling,
145 : Sid::automaticCapitalization,
146 : Sid::lowerCaseMinorChords,
147 : Sid::lowerCaseBassNotes,
148 : Sid::allCapsNoteNames,
149 : Sid::chordStyle,
150 : Sid::chordsXmlFile,
151 : Sid::chordDescriptionFile,
152 : Sid::concertPitch,
153 : Sid::createMultiMeasureRests,
154 : Sid::minEmptyMeasures,
155 : Sid::hideEmptyStaves,
156 : Sid::dontHideStavesInFirstSystem,
157 : Sid::enableIndentationOnFirstSystem,
158 : Sid::firstSystemIndentationValue,
159 : Sid::hideInstrumentNameIfOneInstrument,
160 : Sid::gateTime,
161 : Sid::tenutoGateTime,
162 : Sid::staccatoGateTime,
163 : Sid::slurGateTime,
164 : Sid::sectionPause,
165 : Sid::showHeader,
166 : Sid::headerFirstPage,
167 : Sid::headerOddEven,
168 : Sid::evenHeaderL,
169 : Sid::evenHeaderC,
170 : Sid::evenHeaderR,
171 : Sid::oddHeaderL,
172 : Sid::oddHeaderC,
173 : Sid::oddHeaderR,
174 : Sid::showFooter,
175 : Sid::footerFirstPage,
176 : Sid::footerOddEven,
177 : Sid::evenFooterL,
178 : Sid::evenFooterC,
179 : Sid::evenFooterR,
180 : Sid::oddFooterL,
181 : Sid::oddFooterC,
182 : Sid::oddFooterR,
183 : Sid::tupletOutOfStaff,
184 : Sid::tupletDirection,
185 : Sid::tupletBracketType,
186 : Sid::dynamicsPlacement,
187 : Sid::textLinePlacement,
188 : Sid::harpPedalDiagramPlacement,
189 : Sid::harpPedalTextDiagramPlacement,
190 : Sid::expressionPlacement,
191 : Sid::tupletNumberType,
192 : Sid::mmRestShowMeasureNumberRange,
193 : Sid::mmRestRangeBracketType,
194 : Sid::mmRestRangeVPlacement,
195 : Sid::staffTextPlacement,
196 : Sid::repeatLeftPlacement,
197 : Sid::repeatRightPlacement,
198 : Sid::instrumentChangePlacement,
199 : Sid::stickingPlacement,
200 : Sid::letRingPlacement,
201 : Sid::palmMutePlacement,
202 : Sid::pageWidth,
203 : Sid::pageHeight,
204 : Sid::pagePrintableWidth,
205 : Sid::pageEvenTopMargin,
206 : Sid::pageEvenBottomMargin,
207 : Sid::pageEvenLeftMargin,
208 : Sid::pageOddTopMargin,
209 : Sid::pageOddBottomMargin,
210 : Sid::pageOddLeftMargin,
211 : Sid::pageTwosided,
212 : Sid::spatium,
213 : Sid::concertPitch,
214 : Sid::createMultiMeasureRests
215 0 : };
216 :
217 0 : auto resetPositionAndTextProperties = [](EngravingItem* e) {
218 0 : resetElementPosition(e);
219 0 : resetTextProperties(e);
220 0 : };
221 :
222 0 : resetMeasuresLayout(tx, score);
223 0 : score->scanElements(resetPositionAndTextProperties);
224 0 : resetAllStyles(tx, score, dontResetTheseStyles);
225 0 : EditSystemLocks::undoRemoveAllLocks(tx, score);
226 0 : }
227 :
228 0 : void Reset::resetTextStyleOverrides(Score* score)
229 : {
230 0 : TRACEFUNC;
231 :
232 0 : score->scanElements(resetTextProperties);
233 0 : }
234 :
235 0 : void Reset::resetAllStyles(Transaction&, Score* score, const StyleIdSet& exceptTheseOnes)
236 : {
237 0 : TRACEFUNC;
238 :
239 0 : int beginIdx = int(Sid::NOSTYLE) + 1;
240 0 : int endIdx = int(Sid::STYLES);
241 :
242 0 : StyleIdSet stylesToReset;
243 :
244 0 : for (int idx = beginIdx; idx < endIdx; idx++) {
245 0 : Sid styleId = Sid(idx);
246 0 : if (!muse::contains(exceptTheseOnes, styleId)) {
247 0 : stylesToReset.insert(styleId);
248 : }
249 : }
250 :
251 0 : score->resetStyleValues(stylesToReset);
252 0 : }
253 :
254 : //---------------------------------------------------------
255 : // resetMeasuresLayout
256 : // Removes system/page breaks and spacers
257 : //---------------------------------------------------------
258 :
259 0 : void Reset::resetMeasuresLayout(Transaction&, Score* score)
260 : {
261 0 : TRACEFUNC;
262 :
263 0 : std::vector<EngravingItem*> itemsToRemove;
264 :
265 0 : for (MeasureBase* mb = score->first(); mb; mb = mb->next()) {
266 0 : if (mb->isMeasure()) {
267 0 : mb->undoResetProperty(Pid::USER_STRETCH);
268 :
269 0 : for (const MStaff* staff : toMeasure(mb)->mstaves()) {
270 0 : if (Spacer* spacer = staff->vspacerDown()) {
271 0 : itemsToRemove.push_back(spacer);
272 : }
273 :
274 0 : if (Spacer* spacer = staff->vspacerUp()) {
275 0 : itemsToRemove.push_back(spacer);
276 : }
277 : }
278 : }
279 :
280 0 : if (!mb->lineBreak() && !mb->pageBreak()) {
281 0 : continue;
282 : }
283 :
284 0 : for (EngravingItem* item : mb->el()) {
285 0 : if (item->isLayoutBreak() && !toLayoutBreak(item)->isSectionBreak()) {
286 0 : itemsToRemove.push_back(item);
287 : }
288 : }
289 : }
290 :
291 0 : for (EngravingItem* item : itemsToRemove) {
292 0 : score->undoRemoveElement(item);
293 : }
294 0 : }
295 :
296 3 : void Reset::resetAllPositions(Transaction&, Score* score)
297 : {
298 4 : TRACEFUNC;
299 :
300 3 : score->scanElements(resetElementPosition);
301 3 : }
|