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 : #include "twrite.h"
23 :
24 : #include <set>
25 :
26 : #include "../../iengravingconfiguration.h" // IWYU pragma: keep
27 : #include "../../iengravingfont.h"
28 : #include "../../types/typesconv.h"
29 : #include "../../types/symnames.h"
30 : #include "../../style/textstyle.h"
31 : #include "../../infrastructure/rtti.h"
32 :
33 : #include "dom/measure.h"
34 : #include "dom/score.h"
35 : #include "dom/masterscore.h"
36 : #include "dom/factory.h"
37 : #include "dom/linkedobjects.h"
38 : #include "dom/mscore.h"
39 : #include "dom/staff.h"
40 : #include "dom/part.h"
41 : #include "dom/utils.h"
42 :
43 : #include "dom/accidental.h"
44 : #include "dom/actionicon.h"
45 : #include "dom/ambitus.h"
46 : #include "dom/arpeggio.h"
47 : #include "dom/articulation.h"
48 :
49 : #include "dom/bagpembell.h"
50 : #include "dom/barline.h"
51 : #include "dom/beam.h"
52 : #include "dom/bend.h"
53 : #include "dom/box.h"
54 : #include "dom/bracket.h"
55 : #include "dom/breath.h"
56 :
57 : #include "dom/chord.h"
58 : #include "dom/chordbracket.h"
59 : #include "dom/chordline.h"
60 : #include "dom/chordrest.h"
61 : #include "dom/clef.h"
62 : #include "dom/capo.h"
63 :
64 : #include "dom/drumset.h"
65 : #include "dom/dynamic.h"
66 : #include "dom/expression.h"
67 : #include "dom/fermata.h"
68 : #include "dom/figuredbass.h"
69 : #include "dom/fingering.h"
70 : #include "dom/fret.h"
71 :
72 : #include "dom/glissando.h"
73 : #include "dom/gradualtempochange.h"
74 : #include "dom/groups.h"
75 : #include "dom/guitarbend.h"
76 :
77 : #include "dom/hairpin.h"
78 : #include "dom/hammeronpulloff.h"
79 : #include "dom/harmony.h"
80 : #include "dom/harmonicmark.h"
81 : #include "dom/harppedaldiagram.h"
82 : #include "dom/hook.h"
83 :
84 : #include "dom/image.h"
85 : #include "dom/imageStore.h"
86 : #include "dom/instrument.h"
87 : #include "dom/instrchange.h"
88 :
89 : #include "dom/jump.h"
90 :
91 : #include "dom/keysig.h"
92 :
93 : #include "dom/laissezvib.h"
94 : #include "dom/layoutbreak.h"
95 : #include "dom/ledgerline.h"
96 : #include "dom/letring.h"
97 : #include "dom/location.h"
98 : #include "dom/lyrics.h"
99 :
100 : #include "dom/marker.h"
101 : #include "dom/measurenumber.h"
102 : #include "dom/measurerepeat.h"
103 : #include "dom/mmrest.h"
104 : #include "dom/mmrestrange.h"
105 :
106 : #include "dom/note.h"
107 : #include "dom/notedot.h"
108 : #include "dom/noteline.h"
109 : #include "dom/ornament.h"
110 : #include "dom/ottava.h"
111 :
112 : #include "dom/page.h"
113 : #include "dom/palmmute.h"
114 : #include "dom/parenthesis.h"
115 : #include "dom/part.h"
116 : #include "dom/partialtie.h"
117 : #include "dom/pedal.h"
118 : #include "dom/pickscrape.h"
119 : #include "dom/playcounttext.h"
120 : #include "dom/playtechannotation.h"
121 :
122 : #include "dom/rasgueado.h"
123 : #include "dom/rehearsalmark.h"
124 : #include "dom/rest.h"
125 :
126 : #include "dom/sig.h"
127 : #include "dom/segment.h"
128 : #include "dom/sharedpart.h"
129 : #include "dom/slur.h"
130 : #include "dom/spacer.h"
131 : #include "dom/staffstate.h"
132 : #include "dom/stafftext.h"
133 : #include "dom/stafftype.h"
134 : #include "dom/stafftypechange.h"
135 : #include "dom/stavesharinglabel.h"
136 : #include "dom/stem.h"
137 : #include "dom/stemslash.h"
138 : #include "dom/sticking.h"
139 : #include "dom/stringdata.h"
140 : #include "dom/stringtunings.h"
141 : #include "dom/symbol.h"
142 : #include "dom/bsymbol.h"
143 : #include "dom/system.h"
144 : #include "dom/systemdivider.h"
145 : #include "dom/systemtext.h"
146 : #include "dom/soundflag.h"
147 :
148 : #include "dom/tapping.h"
149 : #include "dom/tempotext.h"
150 : #include "dom/text.h"
151 : #include "dom/textbase.h"
152 : #include "dom/textline.h"
153 : #include "dom/textlinebase.h"
154 : #include "dom/tie.h"
155 : #include "dom/timesig.h"
156 : #include "dom/tremolosinglechord.h"
157 : #include "dom/tremolotwochord.h"
158 : #include "dom/tremolobar.h"
159 : #include "dom/trill.h"
160 : #include "dom/tuplet.h"
161 :
162 : #include "dom/vibrato.h"
163 : #include "dom/volta.h"
164 :
165 : #include "dom/whammybar.h"
166 :
167 : #include "editing/transpose.h"
168 :
169 : #include "../xmlwriter.h"
170 : #include "types/types.h"
171 : #include "writecontext.h"
172 : #include "connectorinfowriter.h"
173 :
174 : #include "log.h"
175 :
176 : using namespace muse;
177 : using namespace mu::engraving;
178 : using namespace mu::engraving::write;
179 :
180 47628 : void TWrite::writeItem(const EngravingItem* item, XmlWriter& xml, WriteContext& ctx)
181 : {
182 47628 : switch (item->type()) {
183 0 : case ElementType::ACCIDENTAL: write(item_cast<const Accidental*>(item), xml, ctx);
184 0 : break;
185 0 : case ElementType::ACTION_ICON: write(item_cast<const ActionIcon*>(item), xml, ctx);
186 0 : break;
187 2 : case ElementType::AMBITUS: write(item_cast<const Ambitus*>(item), xml, ctx);
188 2 : break;
189 117 : case ElementType::ARPEGGIO: write(item_cast<const Arpeggio*>(item), xml, ctx);
190 117 : break;
191 614 : case ElementType::ARTICULATION: write(item_cast<const Articulation*>(item), xml, ctx);
192 614 : break;
193 0 : case ElementType::BAGPIPE_EMBELLISHMENT: write(item_cast<const BagpipeEmbellishment*>(item), xml, ctx);
194 0 : break;
195 1488 : case ElementType::BAR_LINE: write(item_cast<const BarLine*>(item), xml, ctx);
196 1488 : break;
197 0 : case ElementType::BEAM: write(item_cast<const Beam*>(item), xml, ctx);
198 0 : break;
199 4 : case ElementType::BEND: write(item_cast<const Bend*>(item), xml, ctx);
200 4 : break;
201 30 : case ElementType::HBOX: write(item_cast<const HBox*>(item), xml, ctx);
202 30 : break;
203 624 : case ElementType::VBOX: write(item_cast<const VBox*>(item), xml, ctx);
204 624 : break;
205 0 : case ElementType::FBOX: write(item_cast<const FBox*>(item), xml, ctx);
206 0 : break;
207 1 : case ElementType::TBOX: write(item_cast<const TBox*>(item), xml, ctx);
208 1 : break;
209 0 : case ElementType::BRACKET: write(item_cast<const Bracket*>(item), xml, ctx);
210 0 : break;
211 64 : case ElementType::BREATH: write(item_cast<const Breath*>(item), xml, ctx);
212 64 : break;
213 18540 : case ElementType::CHORD: write(item_cast<const Chord*>(item), xml, ctx);
214 18540 : break;
215 0 : case ElementType::CHORD_BRACKET: write(item_cast<const ChordBracket*>(item), xml, ctx);
216 0 : break;
217 28 : case ElementType::CHORDLINE: write(item_cast<const ChordLine*>(item), xml, ctx);
218 28 : break;
219 1093 : case ElementType::CLEF: write(item_cast<const Clef*>(item), xml, ctx);
220 1093 : break;
221 7 : case ElementType::CAPO: write(item_cast<const Capo*>(item), xml, ctx);
222 7 : break;
223 589 : case ElementType::DYNAMIC: write(item_cast<const Dynamic*>(item), xml, ctx);
224 589 : break;
225 13 : case ElementType::EXPRESSION: write(item_cast<const Expression*>(item), xml, ctx);
226 13 : break;
227 141 : case ElementType::FERMATA: write(item_cast<const Fermata*>(item), xml, ctx);
228 141 : break;
229 16 : case ElementType::FIGURED_BASS: write(item_cast<const FiguredBass*>(item), xml, ctx);
230 16 : break;
231 206 : case ElementType::FINGERING: write(item_cast<const Fingering*>(item), xml, ctx);
232 206 : break;
233 68 : case ElementType::FRET_DIAGRAM: write(item_cast<const FretDiagram*>(item), xml, ctx);
234 68 : break;
235 79 : case ElementType::GLISSANDO: write(item_cast<const Glissando*>(item), xml, ctx);
236 79 : break;
237 50 : case ElementType::GRADUAL_TEMPO_CHANGE: write(item_cast<const GradualTempoChange*>(item), xml, ctx);
238 50 : break;
239 304 : case ElementType::GUITAR_BEND: write(item_cast<const GuitarBend*>(item), xml, ctx);
240 304 : break;
241 148 : case ElementType::HAIRPIN: write(item_cast<const Hairpin*>(item), xml, ctx);
242 148 : break;
243 48 : case ElementType::HAMMER_ON_PULL_OFF: write(item_cast<const HammerOnPullOff*>(item), xml, ctx);
244 48 : break;
245 720 : case ElementType::HARMONY: write(item_cast<const Harmony*>(item), xml, ctx);
246 720 : break;
247 60 : case ElementType::HARMONIC_MARK: write(item_cast<const HarmonicMark*>(item), xml, ctx);
248 60 : break;
249 12 : case ElementType::HARP_DIAGRAM: write(item_cast<const HarpPedalDiagram*>(item), xml, ctx);
250 12 : break;
251 0 : case ElementType::HOOK: write(item_cast<const Hook*>(item), xml, ctx);
252 0 : break;
253 23 : case ElementType::IMAGE: write(item_cast<const Image*>(item), xml, ctx);
254 23 : break;
255 24 : case ElementType::INSTRUMENT_CHANGE: write(item_cast<const InstrumentChange*>(item), xml, ctx);
256 24 : break;
257 72 : case ElementType::JUMP: write(item_cast<const Jump*>(item), xml, ctx);
258 72 : break;
259 1231 : case ElementType::KEYSIG: write(item_cast<const KeySig*>(item), xml, ctx);
260 1231 : break;
261 0 : case ElementType::LAISSEZ_VIB: write(item_cast<const LaissezVib*>(item), xml, ctx);
262 0 : break;
263 531 : case ElementType::LAYOUT_BREAK: write(item_cast<const LayoutBreak*>(item), xml, ctx);
264 531 : break;
265 0 : case ElementType::LEDGER_LINE: write(item_cast<const LedgerLine*>(item), xml, ctx);
266 0 : break;
267 52 : case ElementType::LET_RING: write(item_cast<const LetRing*>(item), xml, ctx);
268 52 : break;
269 13 : case ElementType::LYRICS: write(item_cast<const Lyrics*>(item), xml, ctx);
270 13 : break;
271 2 : case ElementType::LYRICSLINE: write(item_cast<const LyricsLine*>(item), xml, ctx);
272 2 : break;
273 75 : case ElementType::MARKER: write(item_cast<const Marker*>(item), xml, ctx);
274 75 : break;
275 0 : case ElementType::MEASURE_NUMBER: write(item_cast<const MeasureNumber*>(item), xml, ctx);
276 0 : break;
277 82 : case ElementType::MEASURE_REPEAT: write(item_cast<const MeasureRepeat*>(item), xml, ctx);
278 82 : break;
279 34 : case ElementType::MMREST: write(item_cast<const MMRest*>(item), xml, ctx);
280 34 : break;
281 0 : case ElementType::MMREST_RANGE: write(item_cast<const MMRestRange*>(item), xml, ctx);
282 0 : break;
283 205 : case ElementType::NOTE: write(item_cast<const Note*>(item), xml, ctx);
284 205 : break;
285 0 : case ElementType::NOTEDOT: write(item_cast<const NoteDot*>(item), xml, ctx);
286 0 : break;
287 0 : case ElementType::NOTEHEAD: write(item_cast<const NoteHead*>(item), xml, ctx);
288 0 : break;
289 2 : case ElementType::NOTELINE: write(item_cast<const NoteLine*>(item), xml, ctx);
290 2 : break;
291 130 : case ElementType::ORNAMENT: write(item_cast<const Ornament*>(item), xml, ctx);
292 130 : break;
293 108 : case ElementType::OTTAVA: write(item_cast<const Ottava*>(item), xml, ctx);
294 108 : break;
295 0 : case ElementType::PAGE: write(item_cast<const Page*>(item), xml, ctx);
296 0 : break;
297 45 : case ElementType::PALM_MUTE: write(item_cast<const PalmMute*>(item), xml, ctx);
298 45 : break;
299 0 : case ElementType::PARENTHESIS: write(item_cast<const Parenthesis*>(item), xml, ctx);
300 0 : break;
301 6 : case ElementType::PARTIAL_LYRICSLINE: write(item_cast<const PartialLyricsLine*>(item), xml, ctx);
302 6 : break;
303 0 : case ElementType::PARTIAL_TIE: write(item_cast<const PartialTie*>(item), xml, ctx);
304 0 : break;
305 63 : case ElementType::PEDAL: write(item_cast<const Pedal*>(item), xml, ctx);
306 63 : break;
307 2 : case ElementType::PICK_SCRAPE: write(item_cast<const PickScrape*>(item), xml, ctx);
308 2 : break;
309 6 : case ElementType::PLAY_COUNT_TEXT: write(item_cast<const PlayCountText*>(item), xml, ctx);
310 6 : break;
311 6 : case ElementType::PLAYTECH_ANNOTATION: write(item_cast<const PlayTechAnnotation*>(item), xml, ctx);
312 6 : break;
313 35 : case ElementType::RASGUEADO: write(item_cast<const Rasgueado*>(item), xml, ctx);
314 35 : break;
315 50 : case ElementType::REHEARSAL_MARK: write(item_cast<const RehearsalMark*>(item), xml, ctx);
316 50 : break;
317 14647 : case ElementType::REST: write(item_cast<const Rest*>(item), xml, ctx);
318 14647 : break;
319 0 : case ElementType::SEGMENT: write(item_cast<const Segment*>(item), xml, ctx);
320 0 : break;
321 257 : case ElementType::SLUR: write(item_cast<const Slur*>(item), xml, ctx);
322 257 : break;
323 0 : case ElementType::SPACER: write(item_cast<const Spacer*>(item), xml, ctx);
324 0 : break;
325 0 : case ElementType::STAFF_STATE: write(item_cast<const StaffState*>(item), xml, ctx);
326 0 : break;
327 357 : case ElementType::STAFF_TEXT: write(item_cast<const StaffText*>(item), xml, ctx);
328 357 : break;
329 0 : case ElementType::STAVE_SHARING_LABEL: write(item_cast<const StaveSharingLabel*>(item), xml, ctx);
330 0 : break;
331 0 : case ElementType::STAFFTYPE_CHANGE: write(item_cast<const StaffTypeChange*>(item), xml, ctx);
332 0 : break;
333 0 : case ElementType::STEM: write(item_cast<const Stem*>(item), xml, ctx);
334 0 : break;
335 0 : case ElementType::STEM_SLASH: write(item_cast<const StemSlash*>(item), xml, ctx);
336 0 : break;
337 73 : case ElementType::STICKING: write(item_cast<const Sticking*>(item), xml, ctx);
338 73 : break;
339 19 : case ElementType::STRING_TUNINGS: write(item_cast<const StringTunings*>(item), xml, ctx);
340 19 : break;
341 11 : case ElementType::SYMBOL: write(item_cast<const Symbol*>(item), xml, ctx);
342 11 : break;
343 0 : case ElementType::FSYMBOL: write(item_cast<const FSymbol*>(item), xml, ctx);
344 0 : break;
345 0 : case ElementType::SYSTEM: write(item_cast<const System*>(item), xml, ctx);
346 0 : break;
347 0 : case ElementType::SYSTEM_DIVIDER: write(item_cast<const SystemDivider*>(item), xml, ctx);
348 0 : break;
349 26 : case ElementType::SYSTEM_TEXT: write(item_cast<const SystemText*>(item), xml, ctx);
350 26 : break;
351 0 : case ElementType::SOUND_FLAG: write(item_cast<const SoundFlag*>(item), xml, ctx);
352 0 : break;
353 3 : case ElementType::TAPPING: write(item_cast<const Tapping*>(item), xml, ctx);
354 3 : break;
355 565 : case ElementType::TEMPO_TEXT: write(item_cast<const TempoText*>(item), xml, ctx);
356 565 : break;
357 1020 : case ElementType::TEXT: write(item_cast<const Text*>(item), xml, ctx);
358 1020 : break;
359 45 : case ElementType::TEXTLINE: write(item_cast<const TextLine*>(item), xml, ctx);
360 45 : break;
361 598 : case ElementType::TIE: write(item_cast<const Tie*>(item), xml, ctx);
362 598 : break;
363 1988 : case ElementType::TIMESIG: write(item_cast<const TimeSig*>(item), xml, ctx);
364 1988 : break;
365 21 : case ElementType::TREMOLO_SINGLECHORD: write(item_cast<const TremoloSingleChord*>(item), xml, ctx);
366 21 : break;
367 0 : case ElementType::TREMOLO_TWOCHORD: write(item_cast<const TremoloTwoChord*>(item), xml, ctx);
368 0 : break;
369 4 : case ElementType::TREMOLOBAR: write(item_cast<const TremoloBar*>(item), xml, ctx);
370 4 : break;
371 18 : case ElementType::TRILL: write(item_cast<const Trill*>(item), xml, ctx);
372 18 : break;
373 0 : case ElementType::TUPLET: write(item_cast<const Tuplet*>(item), xml, ctx);
374 0 : break;
375 26 : case ElementType::VIBRATO: write(item_cast<const Vibrato*>(item), xml, ctx);
376 26 : break;
377 55 : case ElementType::VOLTA: write(item_cast<const Volta*>(item), xml, ctx);
378 55 : break;
379 32 : case ElementType::WHAMMY_BAR: write(item_cast<const WhammyBar*>(item), xml, ctx);
380 32 : break;
381 0 : default: {
382 0 : UNREACHABLE;
383 : LOGE() << "not implemented write for type: " << item->typeName();
384 : }
385 : }
386 47628 : }
387 :
388 38496 : void TWrite::writeItems(const ElementList& items, XmlWriter& xml, WriteContext& ctx)
389 : {
390 38724 : for (const EngravingItem* e : items) {
391 228 : writeItem(e, xml, ctx);
392 : }
393 38496 : }
394 :
395 : //-----------------------------------------------------------------------------
396 : // writeProperty
397 : //
398 : // - styled properties are never written
399 : // - other properties are written if forced or if different from default value
400 : //-----------------------------------------------------------------------------
401 :
402 1516288 : void TWrite::writeProperty(const EngravingItem* item, XmlWriter& xml, Pid pid, bool force)
403 : {
404 1516288 : if (item->isStyled(pid)) {
405 56363 : return;
406 : }
407 1463523 : PropertyValue p = item->getProperty(pid);
408 1463523 : if (!p.isValid()) {
409 47 : LOGD("%s invalid property %d <%s>", item->typeName(), int(pid), propertyName(pid));
410 47 : return;
411 : }
412 1463476 : PropertyValue d = force ? PropertyValue() : item->propertyDefault(pid);
413 :
414 1463476 : if (pid == Pid::FONT_STYLE) {
415 11 : FontStyle ds = FontStyle(d.isValid() ? d.toInt() : 0);
416 11 : FontStyle fs = FontStyle(p.toInt());
417 11 : if ((fs& FontStyle::Bold) != (ds & FontStyle::Bold)) {
418 0 : xml.tag("bold", fs & FontStyle::Bold);
419 : }
420 11 : if ((fs& FontStyle::Italic) != (ds & FontStyle::Italic)) {
421 1 : xml.tag("italic", fs & FontStyle::Italic);
422 : }
423 11 : if ((fs& FontStyle::Underline) != (ds & FontStyle::Underline)) {
424 0 : xml.tag("underline", fs & FontStyle::Underline);
425 : }
426 11 : if ((fs& FontStyle::Strike) != (ds & FontStyle::Strike)) {
427 0 : xml.tag("strike", fs & FontStyle::Strike);
428 : }
429 11 : return;
430 : }
431 :
432 1463465 : P_TYPE type = propertyType(pid);
433 1463465 : if (P_TYPE::ABSOLUTE == type) {
434 0 : double f1 = p.toReal();
435 0 : if (d.isValid() && std::abs(f1 - d.toReal()) < 0.0001) { // fuzzy compare
436 0 : return;
437 : }
438 0 : p = PropertyValue(Spatium::fromAbsolute(f1, item->spatium()));
439 0 : d = PropertyValue();
440 1463465 : } else if (P_TYPE::POINT == type) {
441 3832 : PointF p1 = p.value<PointF>();
442 3832 : if (d.isValid()) {
443 3653 : PointF p2 = d.value<PointF>();
444 3653 : if ((std::abs(p1.x() - p2.x()) < 0.0001) && (std::abs(p1.y() - p2.y()) < 0.0001)) {
445 3540 : return;
446 : }
447 : }
448 292 : double q = item->offsetIsSpatiumDependent() ? item->style().spatium() : DPMM;
449 292 : p = PropertyValue(p1 / q);
450 292 : d = PropertyValue();
451 : }
452 1459925 : xml.tagProperty(pid, p, d);
453 1467074 : }
454 :
455 1395 : void TWrite::writePageLocks(const Score* score, XmlWriter& xml)
456 : {
457 1395 : std::vector<const RangeLock*> locks = score->pageLocks()->allLocks();
458 1395 : if (locks.empty()) {
459 1395 : return;
460 : }
461 :
462 0 : xml.startElement("PageLocks");
463 0 : for (const RangeLock* sl : locks) {
464 0 : writePageLock(sl, xml);
465 : }
466 0 : xml.endElement();
467 1395 : }
468 :
469 1395 : void TWrite::writeSystemLocks(const Score* score, XmlWriter& xml)
470 : {
471 1395 : std::vector<const RangeLock*> locks = score->systemLocks()->allLocks();
472 1395 : if (locks.empty()) {
473 1395 : return;
474 : }
475 :
476 0 : xml.startElement("SystemLocks");
477 0 : for (const RangeLock* sl : locks) {
478 0 : writeSystemLock(sl, xml);
479 : }
480 0 : xml.endElement();
481 1395 : }
482 :
483 1395 : void TWrite::writeSystemDividers(const Score* score, XmlWriter& xml, WriteContext& ctx)
484 : {
485 1395 : std::vector<const System*> systemsToWrite;
486 4619 : for (const System* system : score->systems()) {
487 3227 : bool writeSystem = (system->systemDividerLeft() && !system->systemDividerLeft()->generated())
488 3227 : || (system->systemDividerRight() && !system->systemDividerRight()->generated());
489 3224 : if (writeSystem) {
490 1 : systemsToWrite.push_back(system);
491 : }
492 : }
493 :
494 1395 : if (systemsToWrite.empty()) {
495 1394 : return;
496 : }
497 :
498 1 : xml.startElement("SystemDividers");
499 2 : for (const System* system : systemsToWrite) {
500 4 : xml.startElement("system", { { "idx", muse::indexOf(score->systems(), system) } });
501 1 : SystemDivider* dividerLeft = system->systemDividerLeft();
502 1 : if (dividerLeft && !dividerLeft->generated()) {
503 1 : write(dividerLeft, xml, ctx);
504 : }
505 1 : SystemDivider* dividerRight = system->systemDividerRight();
506 1 : if (dividerRight && !dividerRight->generated()) {
507 1 : write(dividerRight, xml, ctx);
508 : }
509 1 : xml.endElement();
510 : }
511 1 : xml.endElement();
512 1397 : }
513 :
514 1395 : void TWrite::writeScoreSpanners(const Score* score, XmlWriter& xml, WriteContext& ctx)
515 : {
516 1395 : if (score->spannerMap().empty()) {
517 1160 : return;
518 : }
519 235 : std::set<Spanner*> pending;
520 888 : for (const auto& i : score->spannerMap().map()) {
521 653 : Spanner* s = i.second;
522 653 : if (!s->generated() && ctx.canWrite(s)) {
523 653 : pending.insert(s);
524 : }
525 : }
526 235 : xml.startElement("SpannerMap");
527 888 : for (const auto& i : score->spannerMap().map()) {
528 653 : Spanner* s = i.second;
529 653 : if (!pending.count(s)) {
530 2 : continue;
531 : }
532 651 : if (s->links()) {
533 : // The reader resolves linkedTo immediately, so write the eligible main first.
534 88 : Spanner* main = toSpanner(s->links()->mainElement());
535 88 : if (pending.erase(main)) {
536 44 : TWrite::writeItem(main, xml, ctx);
537 : }
538 : }
539 651 : if (pending.erase(s)) {
540 609 : TWrite::writeItem(s, xml, ctx);
541 : }
542 : }
543 235 : xml.endElement();
544 235 : }
545 :
546 81 : void TWrite::writeScoreSpanners(const Score* score, track_idx_t startTrack, track_idx_t endTrack, Segment* startSegment,
547 : Segment* endSegment, XmlWriter& xml, WriteContext& ctx)
548 : {
549 81 : IF_ASSERT_FAILED(ctx.clipboardmode()) {
550 0 : LOGD() << "Should only be used in clipboard mode";
551 : }
552 :
553 81 : std::vector<Spanner*> spannersToWrite;
554 81 : Fraction startTick = startSegment->tick();
555 81 : Fraction endTick = endSegment ? endSegment->tick() : score->endTick();
556 81 : const SpannerMap::IntervalList& spanners = score->spannerMap().findContained(startTick.ticks(), endTick.ticks());
557 115 : for (auto& i : spanners) {
558 34 : Spanner* s = i.value;
559 34 : if (s->generated() || s->track() < startTrack || s->effectiveTrack2() >= endTrack || !ctx.canWrite(s)) {
560 9 : continue;
561 : }
562 : // Do not write chordrest anchored spanners ending on the final tick of the region to the clipboard
563 : // The chordrest they are anchored to is outside of the selected region
564 27 : if (s->tick2() == endTick && s->anchor() == Spanner::Anchor::CHORDREST) {
565 1 : continue;
566 : }
567 : // Don't write voltas to clipboard
568 26 : if (s->isVolta() && s->systemFlag()) {
569 1 : continue;
570 : }
571 25 : spannersToWrite.push_back(s);
572 : }
573 :
574 81 : if (spannersToWrite.empty()) {
575 63 : return;
576 : }
577 :
578 18 : xml.startElement("SpannerMap");
579 43 : for (Spanner* s : spannersToWrite) {
580 25 : TWrite::writeItem(s, xml, ctx);
581 : }
582 18 : xml.endElement();
583 81 : }
584 :
585 94708 : void TWrite::writeItemEid(const EngravingObject* item, XmlWriter& xml)
586 : {
587 94708 : if (item->score()->isPaletteScore()) {
588 0 : return;
589 : }
590 :
591 94708 : EID eid = item->eid();
592 94708 : if (!eid.isValid()) {
593 68060 : eid = item->assignNewEID();
594 : }
595 :
596 94708 : std::array<char, EID::MAX_STR_SIZE> buf{};
597 284124 : const char* last = eid.toChars(buf.data(), buf.data() + buf.size());
598 94708 : const auto size = static_cast<size_t>(last - buf.data());
599 :
600 94708 : xml.tag("eid", AsciiStringView { buf.data(), size });
601 : }
602 :
603 79529 : void TWrite::writeItemLink(const EngravingObject* item, XmlWriter& xml, WriteContext& ctx)
604 : {
605 79529 : if (!item->links() || item->links()->size() <= 1 || ctx.clipboardmode()) {
606 65811 : return;
607 : }
608 :
609 13718 : EngravingItem* mainElement = static_cast<EngravingItem*>(item->links()->mainElement());
610 13718 : if (mainElement != item) {
611 7012 : EID eidOfMainElement = mainElement->eid();
612 7012 : DO_ASSERT(eidOfMainElement.isValid());
613 7012 : xml.tag("linkedTo", eidOfMainElement.toStdString());
614 : }
615 : }
616 :
617 0 : void TWrite::writePageLock(const RangeLock* pageLock, XmlWriter& xml)
618 : {
619 0 : xml.startElement("pageLock");
620 :
621 0 : xml.tag("startMeasure", pageLock->startMB()->eid().toStdString());
622 0 : xml.tag("endMeasure", pageLock->endMB()->eid().toStdString());
623 :
624 0 : xml.endElement();
625 0 : }
626 :
627 0 : void TWrite::writeSystemLock(const RangeLock* systemLock, XmlWriter& xml)
628 : {
629 0 : xml.startElement("systemLock");
630 :
631 0 : xml.tag("startMeasure", systemLock->startMB()->eid().toStdString());
632 0 : xml.tag("endMeasure", systemLock->endMB()->eid().toStdString());
633 :
634 0 : xml.endElement();
635 0 : }
636 :
637 5660 : String TWrite::lineBreakToTag(const String& str)
638 : {
639 : // Raw newlines appearing next to tags (<font size="10> or <sym>...) get eaten by XML readers.
640 5660 : String s = str;
641 11320 : return s.replace(u"\n", u"<br/>");
642 5660 : }
643 :
644 21468 : void TWrite::writeStyledProperties(const EngravingItem* item, XmlWriter& xml)
645 : {
646 67153 : for (const StyledProperty& spp : *item->styledProperties()) {
647 45685 : writeProperty(item, xml, spp.pid);
648 : }
649 21468 : }
650 :
651 77551 : void TWrite::writeItemProperties(const EngravingItem* item, XmlWriter& xml, WriteContext& ctx)
652 : {
653 77551 : writeItemEid(item, xml);
654 :
655 77551 : bool autoplaceEnabled = item->score()->style().styleB(Sid::autoplaceEnabled);
656 77551 : if (!autoplaceEnabled) {
657 0 : item->score()->style().set(Sid::autoplaceEnabled, true);
658 0 : writeProperty(item, xml, Pid::AUTOPLACE);
659 0 : item->score()->style().set(Sid::autoplaceEnabled, autoplaceEnabled);
660 : } else {
661 77551 : writeProperty(item, xml, Pid::AUTOPLACE);
662 : }
663 :
664 77551 : writeItemLink(item, xml, ctx);
665 :
666 77551 : bool writeSpannerTrack = item->isSpanner()
667 78603 : && (toSpanner(item)->anchor() == Spanner::Anchor::NOTE
668 1052 : || (toSpanner(item)->anchor() == Spanner::Anchor::SEGMENT && ctx.clipboardmode()));
669 77551 : if ((item->track() != ctx.curTrack() && item->track() != muse::nidx && !item->isBeam() && !item->isTuplet()) || writeSpannerTrack) {
670 : // Writing track number for beams and tuplets is redundant as it is calculated
671 : // during layout.
672 2355 : int t = static_cast<int>(item->track()) + ctx.trackDiff();
673 2355 : xml.tag("track", t);
674 : }
675 :
676 310204 : for (Pid pid : { Pid::COLOR, Pid::VISIBLE, Pid::Z }) {
677 232653 : if (item->propertyFlags(pid) == PropertyFlags::NOSTYLE) {
678 228270 : writeProperty(item, xml, pid);
679 : }
680 : }
681 :
682 77551 : if (!item->offset().isNull()) {
683 104 : writeProperty(item, xml, Pid::OFFSET);
684 : }
685 :
686 77551 : if (!item->hasVoiceAssignmentProperties() && item->propertyFlags(Pid::PLACEMENT) == PropertyFlags::NOSTYLE) {
687 73532 : writeProperty(item, xml, Pid::PLACEMENT);
688 : }
689 :
690 77551 : writeProperty(item, xml, Pid::POSITION_LINKED_TO_MASTER);
691 77551 : writeProperty(item, xml, Pid::APPEARANCE_LINKED_TO_MASTER);
692 77551 : writeProperty(item, xml, Pid::EXCLUDE_FROM_OTHER_PARTS);
693 :
694 77551 : bool leftGenerated = item->leftParen() && item->leftParen()->generated();
695 77551 : bool rightGenerated = item->rightParen() && item->rightParen()->generated();
696 77551 : if (!leftGenerated || !rightGenerated) {
697 77551 : writeProperty(item, xml, Pid::HAS_PARENTHESES);
698 : }
699 77551 : if (item->leftParen() && !item->leftParen()->generated()) {
700 0 : writeItem(item->leftParen(), xml, ctx);
701 : }
702 77551 : if (item->rightParen() && !item->rightParen()->generated()) {
703 0 : writeItem(item->rightParen(), xml, ctx);
704 : }
705 77551 : }
706 :
707 2618 : void TWrite::write(const Accidental* item, XmlWriter& xml, WriteContext& ctx)
708 : {
709 2618 : xml.startElement(item);
710 2618 : writeProperty(item, xml, Pid::ACCIDENTAL_BRACKET);
711 2618 : writeProperty(item, xml, Pid::ACCIDENTAL_ROLE);
712 2618 : writeProperty(item, xml, Pid::SMALL);
713 2618 : writeProperty(item, xml, Pid::ACCIDENTAL_TYPE);
714 2618 : writeProperty(item, xml, Pid::ACCIDENTAL_STACKING_ORDER_OFFSET);
715 2618 : writeItemProperties(item, xml, ctx);
716 2618 : xml.endElement();
717 2618 : }
718 :
719 0 : void TWrite::write(const ActionIcon* item, XmlWriter& xml, WriteContext&)
720 : {
721 0 : xml.startElement(item);
722 0 : xml.tag("action", TConv::toXml(item->actionType()));
723 0 : xml.endElement();
724 0 : }
725 :
726 2 : void TWrite::write(const Ambitus* item, XmlWriter& xml, WriteContext& ctx)
727 : {
728 2 : xml.startElement(item);
729 2 : xml.tagProperty(Pid::HEAD_GROUP, item->noteHeadGroup(), Ambitus::NOTEHEADGROUP_DEFAULT);
730 2 : xml.tagProperty(Pid::HEAD_TYPE, item->noteHeadType(), Ambitus::NOTEHEADTYPE_DEFAULT);
731 2 : xml.tagProperty(Pid::MIRROR_HEAD, item->direction(), Ambitus::DIRECTION_DEFAULT);
732 2 : xml.tag("hasLine", item->hasLine(), true);
733 2 : xml.tagProperty(Pid::LINE_WIDTH, item->lineWidth(), Ambitus::LINEWIDTH_DEFAULT);
734 2 : xml.tag("topPitch", item->topPitch());
735 2 : xml.tag("topTpc", item->topTpc());
736 2 : xml.tag("bottomPitch", item->bottomPitch());
737 2 : xml.tag("bottomTpc", item->bottomTpc());
738 2 : if (item->topAccidental()->accidentalType() != AccidentalType::NONE) {
739 0 : xml.startElement("topAccidental");
740 0 : write(item->topAccidental(), xml, ctx);
741 0 : xml.endElement();
742 : }
743 2 : if (item->bottomAccidental()->accidentalType() != AccidentalType::NONE) {
744 1 : xml.startElement("bottomAccidental");
745 1 : write(item->bottomAccidental(), xml, ctx);
746 1 : xml.endElement();
747 : }
748 2 : writeItemProperties(item, xml, ctx);
749 2 : xml.endElement();
750 2 : }
751 :
752 117 : void TWrite::write(const Arpeggio* item, XmlWriter& xml, WriteContext& ctx)
753 : {
754 117 : if (!ctx.canWrite(item)) {
755 3 : return;
756 : }
757 114 : xml.startElement(item);
758 114 : writeProperty(item, xml, Pid::ARPEGGIO_TYPE);
759 114 : writeProperties(item, xml, ctx);
760 :
761 114 : xml.endElement();
762 : }
763 :
764 0 : void TWrite::write(const ChordBracket* item, XmlWriter& xml, WriteContext& ctx)
765 : {
766 0 : if (!ctx.canWrite(item)) {
767 0 : return;
768 : }
769 :
770 0 : xml.startElement(item);
771 :
772 0 : writeProperty(item, xml, Pid::BRACKET_HOOK_LEN);
773 0 : writeProperty(item, xml, Pid::BRACKET_HOOK_POS);
774 0 : writeProperty(item, xml, Pid::BRACKET_RIGHT_SIDE);
775 :
776 0 : writeProperties(item, xml, ctx);
777 :
778 0 : xml.endElement();
779 : }
780 :
781 114 : void TWrite::writeProperties(const Arpeggio* item, XmlWriter& xml, WriteContext& ctx)
782 : {
783 114 : writeItemProperties(item, xml, ctx);
784 114 : if (!RealIsNull(item->userLen1())) {
785 0 : xml.tag("userLen1", item->userLen1() / item->spatium());
786 : }
787 114 : if (!RealIsNull(item->userLen2())) {
788 0 : xml.tag("userLen2", item->userLen2() / item->spatium());
789 : }
790 114 : if (item->span() != 1) {
791 54 : xml.tag("span", item->span());
792 : }
793 114 : writeProperty(item, xml, Pid::PLAY);
794 114 : writeProperty(item, xml, Pid::TIME_STRETCH);
795 114 : }
796 :
797 614 : void TWrite::write(const Articulation* item, XmlWriter& xml, WriteContext& ctx)
798 : {
799 614 : if (!ctx.canWrite(item)) {
800 2 : return;
801 : }
802 612 : if (item->isOrnament()) {
803 0 : write(toOrnament(item), xml, ctx);
804 0 : return;
805 : }
806 612 : xml.startElement(item);
807 612 : writeProperties(item, xml, ctx);
808 612 : xml.endElement();
809 : }
810 :
811 761 : void TWrite::writeProperties(const Articulation* item, XmlWriter& xml, WriteContext& ctx)
812 : {
813 761 : if (!item->channelName().isEmpty()) {
814 0 : xml.tag("channe", { { "name", item->channelName() } });
815 : }
816 :
817 761 : writeProperty(item, xml, Pid::DIRECTION);
818 761 : if (item->textType() != ArticulationTextType::NO_TEXT) {
819 22 : xml.tag("subtype", TConv::toXml(item->textType()));
820 739 : } else if (!item->isTapping()) {
821 736 : xml.tag("subtype", SymNames::nameForSymId(item->symId()));
822 : }
823 :
824 761 : writeProperty(item, xml, Pid::PLAY);
825 761 : writeProperty(item, xml, Pid::ORNAMENT_STYLE);
826 761 : writeStyledProperties(item, xml);
827 761 : writeItemProperties(item, xml, ctx);
828 761 : }
829 :
830 146 : void TWrite::write(const Ornament* item, XmlWriter& xml, WriteContext& ctx)
831 : {
832 146 : if (!ctx.canWrite(item)) {
833 0 : return;
834 : }
835 146 : xml.startElement(item);
836 :
837 146 : if (item->cueNoteChord()) {
838 5 : write(item->cueNoteChord(), xml, ctx);
839 : } else {
840 141 : if (item->accidentalAbove()) {
841 7 : write(item->accidentalAbove(), xml, ctx);
842 : }
843 141 : if (item->accidentalBelow()) {
844 2 : write(item->accidentalBelow(), xml, ctx);
845 : }
846 : }
847 :
848 146 : writeProperty(item, xml, Pid::INTERVAL_ABOVE);
849 146 : writeProperty(item, xml, Pid::INTERVAL_BELOW);
850 146 : writeProperty(item, xml, Pid::ORNAMENT_SHOW_ACCIDENTAL);
851 146 : writeProperty(item, xml, Pid::ORNAMENT_SHOW_CUE_NOTE);
852 146 : writeProperty(item, xml, Pid::START_ON_UPPER_NOTE);
853 146 : writeProperties(static_cast<const Articulation*>(item), xml, ctx);
854 146 : xml.endElement();
855 : }
856 :
857 0 : void TWrite::write(const BagpipeEmbellishment* item, XmlWriter& xml, WriteContext&)
858 : {
859 0 : xml.startElement(item);
860 0 : xml.tag("subtype", TConv::toXml(item->embelType()));
861 0 : xml.endElement();
862 0 : }
863 :
864 1488 : void TWrite::write(const BarLine* item, XmlWriter& xml, WriteContext& ctx)
865 : {
866 1488 : xml.startElement(item);
867 :
868 1488 : writeProperty(item, xml, Pid::BARLINE_TYPE);
869 1488 : writeProperty(item, xml, Pid::BARLINE_SPAN);
870 1488 : writeProperty(item, xml, Pid::BARLINE_SPAN_FROM);
871 1488 : writeProperty(item, xml, Pid::BARLINE_SPAN_TO);
872 :
873 1488 : for (const EngravingItem* e : *item->el()) {
874 0 : writeItem(e, xml, ctx);
875 : }
876 :
877 1488 : if (ctx.clipboardmode() && item->measure()) {
878 1 : xml.tag("playCount", item->measure()->repeatCount());
879 : }
880 :
881 1488 : writeItemProperties(item, xml, ctx);
882 1488 : xml.endElement();
883 1488 : }
884 :
885 1663 : void TWrite::write(const Beam* item, XmlWriter& xml, WriteContext& ctx)
886 : {
887 1663 : if (item->elements().empty()) {
888 0 : return;
889 : }
890 1663 : xml.startElement(item);
891 1663 : writeItemProperties(item, xml, ctx);
892 :
893 1663 : writeProperty(item, xml, Pid::STEM_DIRECTION);
894 1663 : writeProperty(item, xml, Pid::BEAM_NO_SLOPE);
895 1663 : writeProperty(item, xml, Pid::GROW_LEFT);
896 1663 : writeProperty(item, xml, Pid::GROW_RIGHT);
897 1663 : writeProperty(item, xml, Pid::BEAM_CROSS_STAFF_MOVE);
898 :
899 1663 : int idx = item->directionIdx();
900 1663 : if (item->userModified()) {
901 0 : double _spatium = item->spatium();
902 0 : for (BeamFragment* f : item->beamFragments()) {
903 0 : xml.startElement("Fragment");
904 0 : xml.tag("y1", f->py1[idx] / _spatium);
905 0 : xml.tag("y2", f->py2[idx] / _spatium);
906 0 : xml.endElement();
907 : }
908 : }
909 :
910 : // this info is used for regression testing
911 : // l1/l2 is the beam position of the layout engine
912 1663 : if (MScore::testMode) {
913 1663 : double spatium8 = item->spatium() * .125;
914 3326 : for (BeamFragment* f : item->beamFragments()) {
915 1663 : xml.tag("l1", int(lrint(f->py1[idx] / spatium8)));
916 1663 : xml.tag("l2", int(lrint(f->py2[idx] / spatium8)));
917 : }
918 : }
919 :
920 1663 : xml.endElement();
921 : }
922 :
923 4 : void TWrite::write(const Bend* item, XmlWriter& xml, WriteContext& ctx)
924 : {
925 4 : xml.startElement(item);
926 16 : for (const PitchValue& v : item->points()) {
927 60 : xml.tag("point", { { "time", v.time }, { "pitch", v.pitch }, { "vibrato", v.vibrato } });
928 : }
929 4 : writeStyledProperties(item, xml);
930 4 : writeProperty(item, xml, Pid::PLAY);
931 4 : writeItemProperties(item, xml, ctx);
932 4 : xml.endElement();
933 16 : }
934 :
935 624 : void TWrite::write(const Box* item, XmlWriter& xml, WriteContext& ctx)
936 : {
937 624 : xml.startElement(item);
938 624 : writeBoxProperties(item, xml, ctx);
939 624 : xml.endElement();
940 624 : }
941 :
942 624 : void TWrite::writeBoxProperties(const Box* item, XmlWriter& xml, WriteContext& ctx)
943 : {
944 624 : if (item->isHBox()) {
945 0 : return writeProperties(dynamic_cast<const HBox*>(item), xml, ctx);
946 : }
947 624 : return writeProperties(item, xml, ctx);
948 : }
949 :
950 655 : void TWrite::writeProperties(const Box* item, XmlWriter& xml, WriteContext& ctx)
951 : {
952 7205 : for (Pid id : {
953 : Pid::BOX_HEIGHT, Pid::BOX_WIDTH, Pid::TOP_GAP, Pid::BOTTOM_GAP,
954 : Pid::LEFT_MARGIN, Pid::RIGHT_MARGIN, Pid::TOP_MARGIN, Pid::BOTTOM_MARGIN, Pid::BOX_AUTOSIZE, Pid::SIZE_SPATIUM_DEPENDENT
955 7860 : }) {
956 6550 : bool force = ((item->isVBox() || item->isFBox()) && id == Pid::BOX_HEIGHT) || (item->isHBox() && id == Pid::BOX_WIDTH);
957 6550 : writeProperty(item, xml, id, force);
958 : }
959 655 : if (item->isVBoxBase()) {
960 625 : writeProperty(item, xml, Pid::PADDING_TO_NOTATION_ABOVE);
961 625 : writeProperty(item, xml, Pid::PADDING_TO_NOTATION_BELOW);
962 : }
963 655 : writeItemProperties(item, xml, ctx);
964 1685 : for (const EngravingItem* e : item->el()) {
965 1030 : writeItem(e, xml, ctx);
966 : }
967 655 : }
968 :
969 30 : void TWrite::write(const HBox* item, XmlWriter& xml, WriteContext& ctx)
970 : {
971 30 : xml.startElement(item);
972 30 : writeProperties(item, xml, ctx);
973 30 : xml.endElement();
974 30 : }
975 :
976 30 : void TWrite::writeProperties(const HBox* item, XmlWriter& xml, WriteContext& ctx)
977 : {
978 30 : writeProperty(item, xml, Pid::CREATE_SYSTEM_HEADER);
979 30 : writeProperties(static_cast<const Box*>(item), xml, ctx);
980 30 : }
981 :
982 624 : void TWrite::write(const VBox* item, XmlWriter& xml, WriteContext& ctx)
983 : {
984 624 : write(static_cast<const Box*>(item), xml, ctx);
985 624 : }
986 :
987 0 : void TWrite::write(const FBox* item, XmlWriter& xml, WriteContext& ctx)
988 : {
989 0 : xml.startElement(item);
990 :
991 0 : writeProperty(item, xml, Pid::FRET_FRAME_TEXT_SCALE);
992 0 : writeProperty(item, xml, Pid::FRET_FRAME_DIAGRAM_SCALE);
993 0 : writeProperty(item, xml, Pid::FRET_FRAME_COLUMN_GAP);
994 0 : writeProperty(item, xml, Pid::FRET_FRAME_ROW_GAP);
995 0 : writeProperty(item, xml, Pid::FRET_FRAME_CHORDS_PER_ROW);
996 0 : writeProperty(item, xml, Pid::FRET_FRAME_H_ALIGN);
997 :
998 0 : writeProperties(static_cast<const Box*>(item), xml, ctx);
999 :
1000 0 : xml.endElement();
1001 0 : }
1002 :
1003 1 : void TWrite::write(const TBox* item, XmlWriter& xml, WriteContext& ctx)
1004 : {
1005 1 : xml.startElement(item);
1006 1 : writeProperties(static_cast<const Box*>(item), xml, ctx);
1007 1 : write(item->text(), xml, ctx);
1008 1 : xml.endElement();
1009 1 : }
1010 :
1011 0 : void TWrite::write(const Bracket* item, XmlWriter& xml, WriteContext& ctx)
1012 : {
1013 0 : bool isStartTag = false;
1014 0 : switch (item->bracketItem()->bracketType()) {
1015 0 : case BracketType::BRACE:
1016 : case BracketType::SQUARE:
1017 : case BracketType::LINE:
1018 : case BracketType::GROUP:
1019 : {
1020 0 : xml.startElement(item, { { "type", TConv::toXml(item->bracketItem()->bracketType()) } });
1021 0 : isStartTag = true;
1022 : }
1023 0 : break;
1024 0 : case BracketType::NORMAL:
1025 0 : xml.startElement(item);
1026 0 : isStartTag = true;
1027 0 : break;
1028 0 : case BracketType::NO_BRACKET:
1029 0 : break;
1030 : }
1031 :
1032 0 : if (isStartTag) {
1033 0 : if (item->bracketItem()->column()) {
1034 0 : xml.tag("level", static_cast<int>(item->bracketItem()->column()));
1035 : }
1036 :
1037 0 : writeItemProperties(item, xml, ctx);
1038 :
1039 0 : xml.endElement();
1040 : }
1041 0 : }
1042 :
1043 64 : void TWrite::write(const Breath* item, XmlWriter& xml, WriteContext& ctx)
1044 : {
1045 64 : if (!ctx.canWrite(item)) {
1046 0 : return;
1047 : }
1048 64 : xml.startElement(item);
1049 64 : writeProperty(item, xml, Pid::SYMBOL);
1050 64 : writeProperty(item, xml, Pid::PAUSE);
1051 64 : writeItemProperties(item, xml, ctx);
1052 64 : xml.endElement();
1053 : }
1054 :
1055 18998 : void TWrite::write(const Chord* item, XmlWriter& xml, WriteContext& ctx)
1056 : {
1057 18998 : bool foundNotes = false;
1058 18998 : const size_t noteCount = item->notes().size();
1059 19110 : for (size_t noteIdx = 0; noteIdx < noteCount; ++noteIdx) {
1060 19038 : if (ctx.canWriteNoteIdx(noteIdx, noteCount)) {
1061 18926 : foundNotes = true;
1062 18926 : break;
1063 : }
1064 : }
1065 18998 : if (!foundNotes) {
1066 72 : if (item->tuplet()) {
1067 : // HACK: See PR #30178 - deselected chords still not fully handled in tuplets...
1068 30 : Rest* dummyRest = Factory::createRest(item->segment());
1069 30 : dummyRest->setDurationType(item->durationType());
1070 30 : dummyRest->setTuplet(item->tuplet());
1071 30 : dummyRest->setTicks(item->ticks());
1072 30 : dummyRest->setTrack(item->track());
1073 30 : write(dummyRest, xml, ctx);
1074 30 : dummyRest->deleteLater();
1075 : } else {
1076 : // No writable notes found, write a Location instead (skip this chord)...
1077 :
1078 42 : const Fraction tick = item->tick();
1079 42 : const track_idx_t track = item->track();
1080 :
1081 42 : Location curr = Location::absolute();
1082 42 : curr.setFrac(ctx.curTick());
1083 42 : curr.setTrack(static_cast<int>(ctx.curTrack()));
1084 :
1085 42 : Location dest = Location::absolute();
1086 42 : dest.setFrac(tick);
1087 42 : dest.setTrack(static_cast<int>(track));
1088 :
1089 42 : dest.toRelative(curr);
1090 42 : TWrite::write(&dest, xml, ctx);
1091 :
1092 42 : ctx.setCurTick(tick);
1093 42 : ctx.setCurTrack(track);
1094 : }
1095 72 : return;
1096 : }
1097 :
1098 19379 : for (Chord* ch : item->graceNotes()) {
1099 453 : write(ch, xml, ctx);
1100 : }
1101 18926 : writeChordRestBeam(item, xml, ctx);
1102 18926 : xml.startElement(item);
1103 18926 : writeProperties(toChordRest(item), xml, ctx);
1104 19639 : for (const Articulation* a : item->articulations()) {
1105 713 : writeItem(a, xml, ctx);
1106 : }
1107 18926 : switch (item->noteType()) {
1108 18473 : case NoteType::NORMAL:
1109 18473 : break;
1110 69 : case NoteType::ACCIACCATURA:
1111 69 : xml.tag("acciaccatura");
1112 69 : break;
1113 169 : case NoteType::APPOGGIATURA:
1114 169 : xml.tag("appoggiatura");
1115 169 : break;
1116 4 : case NoteType::GRACE4:
1117 4 : xml.tag("grace4");
1118 4 : break;
1119 32 : case NoteType::GRACE16:
1120 32 : xml.tag("grace16");
1121 32 : break;
1122 22 : case NoteType::GRACE32:
1123 22 : xml.tag("grace32");
1124 22 : break;
1125 147 : case NoteType::GRACE8_AFTER:
1126 147 : xml.tag("grace8after");
1127 147 : break;
1128 4 : case NoteType::GRACE16_AFTER:
1129 4 : xml.tag("grace16after");
1130 4 : break;
1131 6 : case NoteType::GRACE32_AFTER:
1132 6 : xml.tag("grace32after");
1133 6 : break;
1134 0 : default:
1135 0 : break;
1136 : }
1137 :
1138 18926 : if (item->noStem()) {
1139 244 : xml.tag("noStem", item->noStem());
1140 18682 : } else if (item->stem() && (item->stem()->isUserModified() || !item->stem()->userLength().isZero())) {
1141 3 : write(item->stem(), xml, ctx);
1142 : }
1143 18926 : if (item->hook() && item->hook()->isUserModified()) {
1144 0 : write(item->hook(), xml, ctx);
1145 : }
1146 18926 : if (item->showStemSlash() != item->propertyDefault(Pid::SHOW_STEM_SLASH).toBool()) {
1147 23 : xml.tag("showStemSlash", item->showStemSlash());
1148 : }
1149 18926 : if (item->stemSlash() && item->stemSlash()->isUserModified()) {
1150 0 : write(item->stemSlash(), xml, ctx);
1151 : }
1152 18926 : writeProperty(item, xml, Pid::STEM_DIRECTION);
1153 :
1154 42588 : for (size_t noteIdx = 0; noteIdx < noteCount; ++noteIdx) {
1155 23662 : if (!ctx.canWriteNoteIdx(noteIdx, noteCount)) {
1156 114 : continue;
1157 : }
1158 23548 : const Note* note = item->notes().at(noteIdx);
1159 23548 : write(note, xml, ctx);
1160 : }
1161 :
1162 : // Write parens
1163 19076 : for (const NoteParenthesisInfo* parenPair : item->noteParentheses()) {
1164 150 : xml.startElement("NoteParenGroup");
1165 :
1166 150 : write(parenPair->leftParen(), xml, ctx);
1167 150 : write(parenPair->rightParen(), xml, ctx);
1168 :
1169 150 : xml.startElement("Notes");
1170 307 : for (const Note* note : parenPair->notes()) {
1171 157 : EID noteEID = note->eid();
1172 157 : if (!noteEID.isValid()) {
1173 0 : noteEID = note->assignNewEID();
1174 : }
1175 157 : xml.tag("NoteEID", noteEID.toStdString());
1176 : }
1177 150 : xml.endElement();
1178 150 : xml.endElement();
1179 : }
1180 :
1181 18926 : if (item->arpeggio()) {
1182 117 : writeItem(item->arpeggio(), xml, ctx);
1183 : }
1184 :
1185 18926 : if (item->tremoloSingleChord()) {
1186 91 : write(item->tremoloSingleChord(), xml, ctx);
1187 18835 : } else if (item->tremoloTwoChord() && item->tremoloChordType() != TremoloChordType::TremoloSecondChord) {
1188 52 : write(item->tremoloTwoChord(), xml, ctx);
1189 : }
1190 :
1191 18926 : writeProperty(item, xml, Pid::COMBINE_VOICE);
1192 :
1193 19021 : for (EngravingItem* e : item->el()) {
1194 95 : if (e->isChordLine() && toChordLine(e)->note()) { // this is now written by Note
1195 69 : continue;
1196 : }
1197 26 : writeItem(e, xml, ctx);
1198 : }
1199 18926 : xml.endElement();
1200 : }
1201 :
1202 33553 : void TWrite::writeChordRestBeam(const ChordRest* item, XmlWriter& xml, WriteContext& ctx)
1203 : {
1204 33553 : Beam* b = item->beam();
1205 33553 : if (b && b->elements().front() == item && (MScore::testMode || !b->generated())) {
1206 1663 : write(b, xml, ctx);
1207 : }
1208 33553 : }
1209 :
1210 33669 : void TWrite::writeProperties(const ChordRest* item, XmlWriter& xml, WriteContext& ctx)
1211 : {
1212 33669 : writeItemProperties(item, xml, ctx);
1213 :
1214 : //
1215 : // BeamMode default:
1216 : // REST - BeamMode::NONE
1217 : // CHORD - BeamMode::AUTO
1218 : //
1219 33669 : if ((item->isRest() && item->beamMode() != BeamMode::NONE) || (item->isChord() && item->beamMode() != BeamMode::AUTO)) {
1220 1776 : xml.tag("BeamMode", TConv::toXml(item->beamMode()));
1221 : }
1222 33669 : writeProperty(item, xml, Pid::SMALL);
1223 33669 : if (item->actualDurationType().dots()) {
1224 500 : xml.tag("dots", item->actualDurationType().dots());
1225 : }
1226 33669 : writeProperty(item, xml, Pid::STAFF_MOVE);
1227 :
1228 33669 : if (item->actualDurationType().isValid()) {
1229 33664 : xml.tag("durationType", TConv::toXml(item->actualDurationType().type()));
1230 : }
1231 :
1232 56572 : if (!item->ticks().isZero() && (!item->actualDurationType().fraction().isValid()
1233 56572 : || (item->actualDurationType().fraction() != item->ticks()))) {
1234 10906 : xml.tagFraction("duration", item->ticks());
1235 : //xml.tagE("duration z=\"%d\" n=\"%d\"", ticks().numerator(), ticks().denominator());
1236 : }
1237 :
1238 34104 : for (Lyrics* lyrics : item->lyrics()) {
1239 435 : write(lyrics, xml, ctx);
1240 : }
1241 :
1242 33669 : if (!item->isGrace()) {
1243 33216 : Fraction t(item->globalTicks());
1244 33216 : if (item->staff()) {
1245 33216 : t /= item->staff()->timeStretch(ctx.curTick());
1246 : }
1247 33216 : ctx.incCurTick(t);
1248 : }
1249 33669 : }
1250 :
1251 33904 : void TWrite::writeTupletStart(DurationElement* item, XmlWriter& xml, WriteContext& ctx)
1252 : {
1253 33904 : if (item->tuplet() && item->tuplet()->elements().front() == item) {
1254 601 : writeTupletStart(item->tuplet(), xml, ctx); // recursion
1255 601 : TWrite::write(item->tuplet(), xml, ctx);
1256 : }
1257 33904 : }
1258 :
1259 33904 : void TWrite::writeTupletEnd(DurationElement* item, XmlWriter& xml, WriteContext& ctx)
1260 : {
1261 33904 : if (item->tuplet() && item->tuplet()->elements().back() == item) {
1262 601 : xml.tag("endTuplet");
1263 601 : writeTupletEnd(item->tuplet(), xml, ctx); // recursion
1264 : }
1265 33904 : }
1266 :
1267 97 : void TWrite::write(const ChordLine* item, XmlWriter& xml, WriteContext& ctx)
1268 : {
1269 97 : xml.startElement(item);
1270 97 : writeProperty(item, xml, Pid::CHORD_LINE_TYPE);
1271 97 : writeProperty(item, xml, Pid::CHORD_LINE_STRAIGHT);
1272 97 : writeProperty(item, xml, Pid::CHORD_LINE_WAVY);
1273 97 : writeProperty(item, xml, Pid::PLAY);
1274 97 : writeItemProperties(item, xml, ctx);
1275 485 : for (size_t i = 0; i < size_t(ChordLine::Point::POINTS_COUNT); ++i) {
1276 388 : writeProperty(item, xml, ChordLine::bezierOffsetPid(ChordLine::Point(i)));
1277 : }
1278 97 : xml.endElement();
1279 97 : }
1280 :
1281 1093 : void TWrite::write(const Clef* item, XmlWriter& xml, WriteContext& ctx)
1282 : {
1283 1093 : xml.startElement(item);
1284 1093 : writeProperty(item, xml, Pid::CLEF_TYPE_CONCERT);
1285 1093 : writeProperty(item, xml, Pid::CLEF_TYPE_TRANSPOSING);
1286 1093 : writeProperty(item, xml, Pid::CLEF_TO_BARLINE_POS);
1287 1093 : if (item->isHeader()) {
1288 983 : xml.tag("isHeader", true);
1289 : }
1290 1093 : writeProperty(item, xml, Pid::IS_COURTESY);
1291 1093 : if (!item->showCourtesy()) {
1292 3 : xml.tag("showCourtesyClef", item->showCourtesy());
1293 : }
1294 1093 : if (item->forInstrumentChange()) {
1295 0 : xml.tag("forInstrumentChange", item->forInstrumentChange());
1296 : }
1297 1093 : writeItemProperties(item, xml, ctx);
1298 1093 : xml.endElement();
1299 1093 : }
1300 :
1301 7 : void TWrite::write(const Capo* item, XmlWriter& xml, WriteContext& ctx)
1302 : {
1303 7 : xml.startElement(item);
1304 7 : writeProperty(item, xml, Pid::ACTIVE);
1305 7 : writeProperty(item, xml, Pid::CAPO_FRET_POSITION);
1306 7 : writeProperty(item, xml, Pid::CAPO_GENERATE_TEXT);
1307 7 : writeProperty(item, xml, Pid::CAPO_TRANSPOSE_MODE);
1308 :
1309 7 : std::set<string_idx_t> orderedStrings;
1310 7 : for (string_idx_t idx : item->params().ignoredStrings) {
1311 0 : orderedStrings.insert(idx);
1312 : }
1313 :
1314 7 : for (string_idx_t idx : orderedStrings) {
1315 0 : xml.startElement("string", { { "no", idx } });
1316 0 : xml.tag("apply", false);
1317 0 : xml.endElement();
1318 : }
1319 :
1320 7 : writeProperties(static_cast<const StaffTextBase*>(item), xml, ctx, true);
1321 7 : xml.endElement();
1322 7 : }
1323 :
1324 589 : void TWrite::write(const Dynamic* item, XmlWriter& xml, WriteContext& ctx)
1325 : {
1326 589 : if (!ctx.canWrite(item)) {
1327 1 : return;
1328 : }
1329 588 : xml.startElement(item);
1330 588 : writeProperty(item, xml, Pid::DYNAMIC_TYPE);
1331 588 : writeProperty(item, xml, Pid::VELOCITY);
1332 588 : writeProperty(item, xml, Pid::AVOID_BARLINES);
1333 588 : writeProperty(item, xml, Pid::CENTER_ON_NOTEHEAD);
1334 588 : writeProperty(item, xml, Pid::PLAY);
1335 588 : writeProperty(item, xml, Pid::ANCHOR_TO_END_OF_PREVIOUS);
1336 :
1337 588 : if (item->isVelocityChangeAvailable()) {
1338 16 : writeProperty(item, xml, Pid::VELO_CHANGE);
1339 16 : writeProperty(item, xml, Pid::VELO_CHANGE_SPEED);
1340 : }
1341 :
1342 588 : writeProperties(toTextBase(item), xml, ctx, toDynamic(item)->hasCustomText());
1343 588 : xml.endElement();
1344 : }
1345 :
1346 13 : void TWrite::write(const Expression* item, XmlWriter& xml, WriteContext& ctx)
1347 : {
1348 13 : if (!ctx.canWrite(item)) {
1349 0 : return;
1350 : }
1351 13 : xml.startElement(item);
1352 13 : writeProperties(toTextBase(item), xml, ctx, true);
1353 13 : xml.endElement();
1354 : }
1355 :
1356 4333 : void TWrite::writeProperties(const TextBase* item, XmlWriter& xml, WriteContext& ctx, bool writeText)
1357 : {
1358 4333 : if (item->hasVoiceAssignmentProperties()) {
1359 601 : writeProperty(item, xml, Pid::VOICE_ASSIGNMENT);
1360 601 : writeProperty(item, xml, Pid::DIRECTION);
1361 601 : writeProperty(item, xml, Pid::CENTER_BETWEEN_STAVES);
1362 : }
1363 :
1364 4333 : writeProperty(item, xml, Pid::TEXT_STYLE);
1365 4333 : writeItemProperties(item, xml, ctx);
1366 :
1367 4333 : writeStyledProperties(item, xml);
1368 :
1369 73661 : for (const auto& spp : *textStyle(item->textStyleType())) {
1370 277131 : if (item->isStyled(spp.pid)
1371 69509 : || (spp.pid == Pid::FONT_SIZE && item->getProperty(spp.pid).toDouble() == TextBase::UNDEFINED_FONT_SIZE)
1372 69509 : || (spp.pid == Pid::FONT_FACE && item->getProperty(spp.pid).value<String>() == TextBase::UNDEFINED_FONT_FAMILY)) {
1373 69147 : continue;
1374 : }
1375 181 : writeProperty(item, xml, spp.pid);
1376 : }
1377 4333 : if (writeText) {
1378 2996 : xml.writeXml(u"text", lineBreakToTag(item->xmlText()));
1379 : }
1380 :
1381 4333 : writeProperty(item, xml, Pid::TEXT_LINKED_TO_MASTER);
1382 4333 : }
1383 :
1384 141 : void TWrite::write(const Fermata* item, XmlWriter& xml, WriteContext& ctx)
1385 : {
1386 141 : if (!ctx.canWrite(item)) {
1387 0 : return;
1388 : }
1389 :
1390 141 : xml.startElement(item);
1391 141 : xml.tag("subtype", SymNames::nameForSymId(item->symId()));
1392 141 : writeProperty(item, xml, Pid::TIME_STRETCH);
1393 141 : writeProperty(item, xml, Pid::PLAY);
1394 141 : writeProperty(item, xml, Pid::MIN_DISTANCE);
1395 141 : writeItemProperties(item, xml, ctx);
1396 141 : xml.endElement();
1397 : }
1398 :
1399 16 : void TWrite::write(const FiguredBass* item, XmlWriter& xml, WriteContext& ctx)
1400 : {
1401 16 : if (!ctx.canWrite(item)) {
1402 4 : return;
1403 : }
1404 :
1405 12 : xml.startElement(item);
1406 12 : if (!item->onNote()) {
1407 0 : xml.tag("onNote", item->onNote());
1408 : }
1409 12 : if (item->ticks().isNotZero()) {
1410 5 : xml.tagFraction("ticks", item->ticks());
1411 : }
1412 : // if unparseable items, write full text data
1413 12 : if (item->items().size() < 1) {
1414 0 : writeProperties(toTextBase(item), xml, ctx, true);
1415 : } else {
1416 : // if (textStyleType() != StyledPropertyListIdx::FIGURED_BASS)
1417 : // // if all items parsed and not unstiled, we simply have a special style: write it
1418 : // xml.tag("style", textStyle().name());
1419 26 : for (FiguredBassItem* fBItem : item->items()) {
1420 14 : write(fBItem, xml, ctx);
1421 : }
1422 12 : writeStyledProperties(item, xml);
1423 12 : writeItemProperties(item, xml, ctx);
1424 : }
1425 12 : xml.endElement();
1426 : }
1427 :
1428 14 : void TWrite::write(const FiguredBassItem* item, XmlWriter& xml, WriteContext&)
1429 : {
1430 14 : xml.startElement("FiguredBassItem", item);
1431 98 : xml.tag("brackets", {
1432 0 : { "b0", int(item->parenth1()) },
1433 0 : { "b1", int(item->parenth2()) },
1434 0 : { "b2", int(item->parenth3()) },
1435 0 : { "b3", int(item->parenth4()) },
1436 0 : { "b4", int(item->parenth5()) }
1437 : });
1438 :
1439 14 : if (item->prefix() != FiguredBassItem::Modifier::NONE) {
1440 1 : xml.tag("prefix", int(item->prefix()));
1441 : }
1442 14 : if (item->digit() != FBIDigitNone) {
1443 13 : xml.tag("digit", item->digit());
1444 : }
1445 14 : if (item->suffix() != FiguredBassItem::Modifier::NONE) {
1446 7 : xml.tag("suffix", int(item->suffix()));
1447 : }
1448 14 : if (item->contLine() != FiguredBassItem::ContLine::NONE) {
1449 1 : xml.tag("continuationLine", int(item->contLine()));
1450 : }
1451 14 : xml.endElement();
1452 28 : }
1453 :
1454 206 : void TWrite::write(const Fingering* item, XmlWriter& xml, WriteContext& ctx)
1455 : {
1456 206 : if (!ctx.canWrite(item)) {
1457 4 : return;
1458 : }
1459 202 : xml.startElement(item);
1460 202 : writeProperties(toTextBase(item), xml, ctx, true);
1461 202 : xml.endElement();
1462 : }
1463 :
1464 68 : void TWrite::write(const FretDiagram* item, XmlWriter& xml, WriteContext& ctx)
1465 : {
1466 68 : if (!ctx.canWrite(item)) {
1467 1 : return;
1468 : }
1469 67 : xml.startElement(item);
1470 :
1471 : static const std::array<Pid, 10> pids { {
1472 : Pid::MIN_DISTANCE,
1473 : Pid::FRET_OFFSET,
1474 : Pid::FRET_FRETS,
1475 : Pid::FRET_STRINGS,
1476 : Pid::FRET_NUT,
1477 : Pid::MAG,
1478 : Pid::ORIENTATION,
1479 : Pid::FRET_SHOW_FINGERINGS,
1480 : Pid::FRET_FINGERING,
1481 : Pid::EXCLUDE_VERTICAL_ALIGN
1482 : } };
1483 :
1484 : // Write properties first and only once
1485 737 : for (Pid p : pids) {
1486 670 : writeProperty(item, xml, p);
1487 : }
1488 67 : writeItemProperties(item, xml, ctx);
1489 :
1490 67 : if (item->harmony()) {
1491 34 : write(item->harmony(), xml, ctx);
1492 : }
1493 :
1494 67 : xml.startElement("fretDiagram");
1495 : {
1496 469 : for (int i = 0; i < item->strings(); ++i) {
1497 402 : FretItem::Marker m = item->marker(i);
1498 402 : std::vector<FretItem::Dot> allDots = item->dot(i);
1499 :
1500 402 : bool dotExists = false;
1501 602 : for (auto const& d : allDots) {
1502 402 : if (d.exists() && !d.isPartOfSlurBarre) { // Don't write dot if part of slur barré (will be generate during layout)
1503 202 : dotExists = true;
1504 202 : break;
1505 : }
1506 : }
1507 :
1508 : // Only write a string if we have anything to write
1509 402 : if (!dotExists && !m.exists()) {
1510 70 : continue;
1511 : }
1512 :
1513 : // Start the string writing
1514 996 : xml.startElement("string", { { "no", i } });
1515 :
1516 : // Write marker
1517 332 : if (m.exists()) {
1518 130 : xml.tag("marker", FretItem::markerTypeToName(m.mtype));
1519 : }
1520 :
1521 : // Write any dots
1522 664 : for (auto const& d : allDots) {
1523 332 : if (d.exists()) {
1524 : // TODO: write fingering
1525 808 : xml.tag("dot", { { "fret", d.fret } }, FretItem::dotTypeToName(d.dtype));
1526 : }
1527 : }
1528 :
1529 332 : xml.endElement();
1530 402 : }
1531 :
1532 337 : for (int fi = 1; fi <= item->frets(); ++fi) {
1533 270 : FretItem::Barre b = item->barre(fi);
1534 270 : if (!b.exists()) {
1535 245 : continue;
1536 : }
1537 :
1538 125 : xml.tag("barre", { { "start", b.startString }, { "end", b.endString } }, fi);
1539 : }
1540 : }
1541 67 : xml.endElement();
1542 67 : xml.endElement();
1543 559 : }
1544 :
1545 79 : void TWrite::write(const Glissando* item, XmlWriter& xml, WriteContext& ctx)
1546 : {
1547 79 : if (!ctx.canWrite(item)) {
1548 2 : return;
1549 : }
1550 77 : xml.startElement(item);
1551 :
1552 77 : xml.tagProperty("text", item->text(), item->propertyDefault(Pid::GLISS_TEXT));
1553 :
1554 77 : if (ctx.clipboardmode() && item->isHarpGliss().has_value()) {
1555 3 : xml.tagProperty("isHarpGliss", PropertyValue(item->isHarpGliss().value()));
1556 : }
1557 :
1558 308 : for (auto id : { Pid::GLISS_SHIFT, Pid::GLISS_EASEIN, Pid::GLISS_EASEOUT }) {
1559 231 : writeProperty(item, xml, id);
1560 : }
1561 :
1562 77 : writeProperties(static_cast<const SLine*>(item), xml, ctx);
1563 77 : xml.endElement();
1564 : }
1565 :
1566 304 : void TWrite::write(const GuitarBend* item, XmlWriter& xml, WriteContext& ctx)
1567 : {
1568 304 : if (!ctx.canWrite(item)) {
1569 0 : return;
1570 : }
1571 304 : xml.startElement(item);
1572 304 : xml.tag("guitarBendType", TConv::toXml(item->bendType()));
1573 304 : xml.tag("bendStartTimeFactor", item->startTimeFactor());
1574 304 : xml.tag("bendEndTimeFactor", item->endTimeFactor());
1575 :
1576 304 : if (item->targetTimeFactor().has_value()) {
1577 0 : xml.tag("bendTargetTimeFactor", item->targetTimeFactor().value());
1578 : }
1579 :
1580 304 : writeProperty(item, xml, Pid::DIRECTION);
1581 304 : writeProperty(item, xml, Pid::BEND_SHOW_HOLD_LINE);
1582 304 : if (item->isDive()) {
1583 142 : writeProperty(item, xml, Pid::GUITAR_DIVE_TAB_POS);
1584 142 : writeProperty(item, xml, Pid::VIBRATO_LINE_TYPE);
1585 142 : writeProperty(item, xml, Pid::GUITAR_DIVE_IS_SLACK);
1586 142 : if (item->bendType() == GuitarBendType::DIP || item->overlappingBendOrDive()) {
1587 0 : writeProperty(item, xml, Pid::GUITAR_BEND_AMOUNT);
1588 : }
1589 : }
1590 :
1591 304 : writeProperties(static_cast<const SLine*>(item), xml, ctx);
1592 :
1593 304 : GuitarBendHold* hold = item->holdLine();
1594 304 : if (hold) {
1595 0 : xml.startElement(hold);
1596 0 : writeProperties(static_cast<const SLine*>(hold), xml, ctx);
1597 0 : xml.endElement();
1598 : }
1599 :
1600 304 : xml.endElement();
1601 : }
1602 :
1603 0 : void TWrite::writeProperties(const GuitarBendSegment* item, XmlWriter& xml, WriteContext& ctx)
1604 : {
1605 0 : writeProperty(item, xml, Pid::BEND_VERTEX_OFF);
1606 :
1607 0 : GuitarBendText* text = item->bendText();
1608 0 : if (text && text->isUserModified()) {
1609 0 : xml.startElement(text);
1610 0 : writeProperties(toTextBase(text), xml, ctx, false);
1611 0 : xml.endElement();
1612 : }
1613 0 : }
1614 :
1615 1130 : void TWrite::writeProperties(const SLine* item, XmlWriter& xml, WriteContext& ctx)
1616 : {
1617 1130 : writeProperties(static_cast<const Spanner*>(item), xml, ctx);
1618 1130 : if (item->diagonal()) {
1619 79 : xml.tag("diagonal", item->diagonal());
1620 : }
1621 :
1622 5650 : for (Pid pid : { Pid::LINE_WIDTH,
1623 : Pid::LINE_STYLE,
1624 : Pid::DASH_LINE_LEN,
1625 6780 : Pid::DASH_GAP_LEN }) {
1626 4520 : if (item->propertyFlags(pid) == PropertyFlags::NOSTYLE) {
1627 1416 : writeProperty(item, xml, pid);
1628 : }
1629 : }
1630 :
1631 1130 : writeStyledProperties(item, xml);
1632 :
1633 1130 : if (!item->isUserModified()) {
1634 1127 : return;
1635 : }
1636 :
1637 3 : double _spatium = item->style().spatium();
1638 6 : for (const SpannerSegment* seg : item->spannerSegments()) {
1639 3 : xml.startElement("Segment", seg);
1640 3 : xml.tag("subtype", int(seg->spannerSegmentType()));
1641 3 : xml.tagPoint("offset", seg->offset() / _spatium);
1642 3 : xml.tagPoint("off2", seg->userOff2() / _spatium);
1643 3 : writeProperty(seg, xml, Pid::MIN_DISTANCE);
1644 3 : if (seg->isGuitarBendSegment()) {
1645 0 : writeProperties(static_cast<const GuitarBendSegment*>(seg), xml, ctx);
1646 : }
1647 3 : writeItemProperties(seg, xml, ctx);
1648 3 : xml.endElement();
1649 : }
1650 : }
1651 :
1652 2098 : void TWrite::writeProperties(const Spanner* item, XmlWriter& xml, WriteContext& ctx)
1653 : {
1654 2098 : writeProperty(item, xml, Pid::PLAY);
1655 2098 : if (item->anchor() == Spanner::Anchor::SEGMENT) {
1656 692 : int t2 = static_cast<int>(item->track2()) + ctx.trackDiff();
1657 692 : xml.tag("track2", t2);
1658 692 : xml.tagFraction("startTick", item->tick(), /* default = */ Fraction(-1, 0)); // Need to be able to write start of score, so a different default is needed
1659 692 : xml.tagFraction("ticks", item->ticks());
1660 1406 : } else if (!item->isGuitarBendHold()) {
1661 : /* GuitarBendHold lines are regenerated during layout by GuitarBend::updateHoldLine(),
1662 : * which recomputes their endpoints, so there is no point in serializing them */
1663 :
1664 1406 : const bool isPartialTieOrLV = item->isPartialTie() || item->isLaissezVib();
1665 1406 : const bool hasStartEndElements = item->startElement() && item->endElement();
1666 1406 : IF_ASSERT_FAILED(item->score()->isPaletteScore() || isPartialTieOrLV || hasStartEndElements) {
1667 0 : writeItemProperties(item, xml, ctx);
1668 0 : return;
1669 : }
1670 1406 : if (EngravingItem* startEl = item->startElement()) {
1671 1378 : EID startElEID = startEl->eid();
1672 1378 : if (!startElEID.isValid()) {
1673 165 : assert(item->anchor() == Spanner::Anchor::NOTE);
1674 165 : startElEID = startEl->assignNewEID();
1675 : }
1676 1378 : xml.tag("startElement", startElEID.toStdString());
1677 : }
1678 1406 : if (EngravingItem* endEl = item->endElement()) {
1679 1369 : EID endElEID = endEl->eid();
1680 1369 : IF_ASSERT_FAILED(endElEID.isValid()) {
1681 0 : endElEID = endEl->assignNewEID();
1682 : }
1683 1369 : xml.tag("endElement", endElEID.toStdString());
1684 : }
1685 : }
1686 2098 : writeItemProperties(item, xml, ctx);
1687 : }
1688 :
1689 50 : void TWrite::write(const GradualTempoChange* item, XmlWriter& xml, WriteContext& ctx)
1690 : {
1691 50 : xml.startElement(item);
1692 250 : for (Pid pid : { Pid::TEMPO_CHANGE_TYPE,
1693 : Pid::TEMPO_EASING_METHOD,
1694 : Pid::TEMPO_CHANGE_FACTOR,
1695 300 : Pid::SNAP_AFTER }) {
1696 200 : if (item->propertyFlags(pid) == PropertyFlags::NOSTYLE) {
1697 200 : writeProperty(item, xml, pid);
1698 : }
1699 : }
1700 50 : writeProperties(static_cast<const TextLineBase*>(item), xml, ctx);
1701 50 : xml.endElement();
1702 50 : }
1703 :
1704 697 : void TWrite::writeProperties(const TextLineBase* item, XmlWriter& xml, WriteContext& ctx)
1705 : {
1706 32062 : for (Pid pid : TextLineBase::textLineBasePropertyIds()) {
1707 31365 : if (item->propertyFlags(pid) == PropertyFlags::NOSTYLE) {
1708 10333 : writeProperty(item, xml, pid);
1709 : }
1710 : }
1711 :
1712 697 : writeProperties(static_cast<const SLine*>(item), xml, ctx);
1713 697 : }
1714 :
1715 0 : void TWrite::write(const Groups* item, XmlWriter& xml, WriteContext&)
1716 : {
1717 0 : xml.startElement("Groups");
1718 0 : for (const GroupNode& n : item->nodes()) {
1719 0 : xml.tag("Node", { { "pos", n.pos }, { "action", n.action } });
1720 : }
1721 0 : xml.endElement();
1722 0 : }
1723 :
1724 148 : void TWrite::write(const Hairpin* item, XmlWriter& xml, WriteContext& ctx)
1725 : {
1726 148 : if (!ctx.canWrite(item)) {
1727 0 : return;
1728 : }
1729 148 : xml.startElement(item);
1730 148 : xml.tag("subtype", int(item->hairpinType()));
1731 :
1732 1776 : for (Pid pid : { Pid::VELO_CHANGE,
1733 : Pid::HAIRPIN_CIRCLEDTIP,
1734 : Pid::SINGLE_NOTE_DYNAMICS,
1735 : Pid::VELO_CHANGE_METHOD,
1736 : Pid::VOICE_ASSIGNMENT,
1737 : Pid::DIRECTION,
1738 : Pid::CENTER_BETWEEN_STAVES,
1739 : Pid::SNAP_BEFORE,
1740 : Pid::SNAP_AFTER,
1741 : Pid::HAIRPIN_HEIGHT,
1742 1924 : Pid::HAIRPIN_CONT_HEIGHT }) {
1743 1628 : if (item->propertyFlags(pid) == PropertyFlags::NOSTYLE) {
1744 1332 : writeProperty(item, xml, pid);
1745 : }
1746 : }
1747 :
1748 148 : writeProperties(static_cast<const TextLineBase*>(item), xml, ctx);
1749 148 : xml.endElement();
1750 : }
1751 :
1752 48 : void TWrite::write(const HammerOnPullOff* item, XmlWriter& xml, WriteContext& ctx)
1753 : {
1754 48 : if (!ctx.canWrite(item)) {
1755 0 : return;
1756 : }
1757 :
1758 48 : xml.startElement(item);
1759 :
1760 48 : writeProperty(item, xml, Pid::PARTIAL_SPANNER_DIRECTION);
1761 :
1762 48 : writeProperties(toSlur(item), xml, ctx);
1763 :
1764 48 : xml.endElement();
1765 : }
1766 :
1767 48 : void TWrite::writeProperties(const HammerOnPullOffSegment* seg, XmlWriter& xml, WriteContext& ctx)
1768 : {
1769 103 : for (size_t i = 0; i < seg->hopoText().size(); ++i) {
1770 55 : HammerOnPullOffText* hopoText = seg->hopoText()[i];
1771 55 : if (!hopoText->isUserModified()) {
1772 0 : continue;
1773 : }
1774 55 : write(hopoText, xml, ctx, i);
1775 : }
1776 48 : }
1777 :
1778 55 : void TWrite::write(const HammerOnPullOffText* item, XmlWriter& xml, WriteContext& ctx, size_t idx)
1779 : {
1780 165 : xml.startElement(item, { { "idx", idx } });
1781 :
1782 55 : writeProperties(toTextBase(item), xml, ctx, /*writeText*/ false);
1783 55 : xml.endElement();
1784 110 : }
1785 :
1786 751 : static void writeHarmonyInfo(const HarmonyInfo* item, const Harmony* h, XmlWriter& xml, WriteContext& ctx)
1787 : {
1788 751 : xml.startElement("harmonyInfo");
1789 751 : if (item->rootTpc() != Tpc::TPC_INVALID || item->bassTpc() != Tpc::TPC_INVALID) {
1790 731 : int rRootTpc = item->rootTpc();
1791 731 : int rBassTpc = item->bassTpc();
1792 731 : if (h->staff()) {
1793 : // parent can be a fret diagram
1794 731 : const Segment* segment = h->getParentSeg();
1795 731 : Fraction tick = segment ? segment->tick() : Fraction(-1, 1);
1796 731 : const Interval& interval = h->staff()->transpose(tick);
1797 731 : if (ctx.clipboardmode() && !h->score()->style().styleB(Sid::concertPitch) && interval.chromatic) {
1798 0 : rRootTpc = Transpose::transposeTpc(item->rootTpc(), interval, true);
1799 0 : rBassTpc = Transpose::transposeTpc(item->bassTpc(), interval, true);
1800 : }
1801 : }
1802 :
1803 731 : if (item->id() > 0) {
1804 48 : xml.tag("extension", item->id());
1805 : }
1806 : // parser uses leading "=" as a hidden specifier for minor
1807 : // this may or may not currently be incorporated into _textName
1808 731 : String writeName = item->textName();
1809 731 : if (item->parsedChord() && item->parsedChord()->name().startsWith(u'=') && !writeName.startsWith(u'=')) {
1810 0 : writeName = u"=" + writeName;
1811 : }
1812 731 : if (!writeName.isEmpty()) {
1813 540 : xml.tag("name", writeName);
1814 : }
1815 731 : if (rRootTpc != Tpc::TPC_INVALID) {
1816 731 : xml.tag("root", rRootTpc);
1817 : }
1818 731 : if (rBassTpc != Tpc::TPC_INVALID) {
1819 9 : xml.tag("bass", rBassTpc);
1820 : }
1821 731 : } else {
1822 20 : xml.tag("name", item->textName());
1823 : }
1824 :
1825 751 : xml.endElement();
1826 751 : }
1827 :
1828 754 : void TWrite::write(const Harmony* item, XmlWriter& xml, WriteContext& ctx)
1829 : {
1830 754 : if (!ctx.canWrite(item) || item->chords().empty()) {
1831 4 : return;
1832 : }
1833 750 : xml.startElement(item);
1834 750 : writeProperty(item, xml, Pid::HARMONY_TYPE);
1835 750 : writeProperty(item, xml, Pid::PLAY);
1836 :
1837 : //! needed to genarate harmony_to_diagram.xml
1838 : // xml.tag("name", item->harmonyName());
1839 :
1840 : // check tpcs valid?
1841 750 : if (item->rootCase() != NoteCaseType::CAPITAL) {
1842 1 : xml.tag("rootCase", TConv::toXml(item->rootCase()));
1843 : }
1844 :
1845 750 : if (item->bassCase() != NoteCaseType::CAPITAL) {
1846 0 : xml.tag("bassCase", TConv::toXml(item->bassCase()));
1847 : }
1848 :
1849 1501 : for (const HarmonyInfo* info : item->chords()) {
1850 751 : writeHarmonyInfo(info, item, xml, ctx);
1851 750 : }
1852 :
1853 750 : for (const HDegree& hd : item->degreeList()) { // Do we really still need this?
1854 0 : HDegreeType tp = hd.type();
1855 0 : if (tp == HDegreeType::ADD || tp == HDegreeType::ALTER || tp == HDegreeType::SUBTRACT) {
1856 0 : xml.startElement("degree");
1857 0 : xml.tag("degree-value", hd.value());
1858 0 : xml.tag("degree-alter", hd.alter());
1859 0 : switch (tp) {
1860 0 : case HDegreeType::ADD:
1861 0 : xml.tag("degree-type", "add");
1862 0 : break;
1863 0 : case HDegreeType::ALTER:
1864 0 : xml.tag("degree-type", "alter");
1865 0 : break;
1866 0 : case HDegreeType::SUBTRACT:
1867 0 : xml.tag("degree-type", "subtract");
1868 0 : break;
1869 0 : default:
1870 0 : break;
1871 : }
1872 0 : xml.endElement();
1873 : }
1874 : }
1875 :
1876 750 : writeProperty(item, xml, Pid::HARMONY_DO_NOT_STACK_MODIFIERS);
1877 750 : writeProperty(item, xml, Pid::EXCLUDE_VERTICAL_ALIGN);
1878 750 : writeProperties(toTextBase(item), xml, ctx, false);
1879 : //Pid::HARMONY_VOICE_LITERAL, Pid::HARMONY_VOICING, Pid::HARMONY_DURATION
1880 : //written by the above function call because they are part of element style
1881 750 : xml.endElement();
1882 : }
1883 :
1884 60 : void TWrite::write(const HarmonicMark* item, XmlWriter& xml, WriteContext& ctx)
1885 : {
1886 60 : if (!ctx.canWrite(item)) {
1887 0 : return;
1888 : }
1889 60 : xml.startElement(item);
1890 60 : writeProperties(static_cast<const TextLineBase*>(item), xml, ctx);
1891 60 : xml.endElement();
1892 : }
1893 :
1894 12 : void TWrite::write(const HarpPedalDiagram* item, XmlWriter& xml, WriteContext& ctx)
1895 : {
1896 12 : if (!ctx.canWrite(item)) {
1897 0 : return;
1898 : }
1899 12 : xml.startElement(item);
1900 12 : writeProperty(item, xml, Pid::HARP_IS_DIAGRAM);
1901 :
1902 : // Write vector of harp strings. Order is always D, C, B, E, F, G, A
1903 12 : xml.startElement("pedalState");
1904 192 : for (size_t idx = 0; idx < item->getPedalState().size(); idx++) {
1905 336 : xml.tag("string", { { "name", idx } }, static_cast<int>(item->getPedalState().at(idx)));
1906 : }
1907 12 : xml.endElement();
1908 :
1909 12 : writeProperties(toTextBase(item), xml, ctx, true);
1910 12 : xml.endElement();
1911 84 : }
1912 :
1913 0 : void TWrite::write(const Hook* item, XmlWriter& xml, WriteContext& ctx)
1914 : {
1915 0 : xml.startElement(item);
1916 0 : xml.tag("name", SymNames::nameForSymId(item->sym()));
1917 0 : if (item->scoreFont()) {
1918 0 : xml.tag("font", item->scoreFont()->name());
1919 : }
1920 0 : writeProperties(static_cast<const BSymbol*>(item), xml, ctx);
1921 0 : xml.endElement();
1922 0 : }
1923 :
1924 36 : void TWrite::writeProperties(const BSymbol* item, XmlWriter& xml, WriteContext& ctx)
1925 : {
1926 41 : for (const EngravingItem* e : item->leafs()) {
1927 5 : writeItem(e, xml, ctx);
1928 : }
1929 36 : writeItemProperties(item, xml, ctx);
1930 36 : }
1931 :
1932 23 : void TWrite::write(const Image* item, XmlWriter& xml, WriteContext& ctx)
1933 : {
1934 23 : xml.startElement(item);
1935 23 : writeProperties(static_cast<const BSymbol*>(item), xml, ctx);
1936 :
1937 23 : xml.tag("path", item->storeItem() ? item->storeItem()->hashName() : std::string());
1938 :
1939 23 : writeProperty(item, xml, Pid::AUTOSCALE);
1940 23 : writeProperty(item, xml, Pid::SIZE);
1941 23 : writeProperty(item, xml, Pid::LOCK_ASPECT_RATIO);
1942 23 : writeProperty(item, xml, Pid::SIZE_IS_SPATIUM);
1943 :
1944 23 : xml.endElement();
1945 23 : }
1946 :
1947 1769 : void TWrite::write(const Instrument* item, XmlWriter& xml, WriteContext&, const Part* part)
1948 : {
1949 1769 : if (item->id().isEmpty()) {
1950 39 : xml.startElement("Instrument");
1951 : } else {
1952 5190 : xml.startElement("Instrument", { { "id", item->id() } });
1953 : }
1954 :
1955 1769 : if (!item->soundId().empty()) {
1956 0 : xml.tag("soundId", item->soundId());
1957 : }
1958 :
1959 1769 : if (!item->instrumentLabel().empty()) {
1960 1435 : write(item->instrumentLabel(), xml);
1961 : }
1962 :
1963 : // if (!_trackName.empty())
1964 1769 : xml.tag("trackName", item->trackName());
1965 1769 : if (item->minPitchP() > MIN_PITCH) {
1966 1180 : xml.tag("minPitchP", item->minPitchP());
1967 : }
1968 1769 : if (item->maxPitchP() < MAX_PITCH) {
1969 1180 : xml.tag("maxPitchP", item->maxPitchP());
1970 : }
1971 1769 : if (item->minPitchA() > MIN_PITCH) {
1972 1180 : xml.tag("minPitchA", item->minPitchA());
1973 : }
1974 1769 : if (item->maxPitchA() < MAX_PITCH) {
1975 1180 : xml.tag("maxPitchA", item->maxPitchA());
1976 : }
1977 1769 : if (item->transpose().diatonic) {
1978 350 : xml.tag("transposeDiatonic", item->transpose().diatonic);
1979 : }
1980 1769 : if (item->transpose().chromatic) {
1981 350 : xml.tag("transposeChromatic", item->transpose().chromatic);
1982 : }
1983 1769 : if (!item->musicXmlId().isEmpty()) {
1984 1730 : xml.tag("instrumentId", item->musicXmlId());
1985 : }
1986 1769 : if (item->useDrumset()) {
1987 39 : xml.tag("useDrumset", item->useDrumset());
1988 39 : item->drumset()->save(xml);
1989 : }
1990 2786 : for (size_t i = 0; i < item->cleffTypeCount(); ++i) {
1991 1017 : ClefTypeList ct = item->clefType(i);
1992 1017 : if (ct.concertClef == ct.transposingClef) {
1993 1003 : if (ct.concertClef != ClefType::G) {
1994 511 : if (i) {
1995 1756 : xml.tag("clef", { { "staff", i + 1 } }, TConv::toXml(ct.concertClef));
1996 : } else {
1997 72 : xml.tag("clef", TConv::toXml(ct.concertClef));
1998 : }
1999 : }
2000 : } else {
2001 14 : if (i) {
2002 0 : xml.tag("concertClef", { { "staff", i + 1 } }, TConv::toXml(ct.concertClef));
2003 0 : xml.tag("transposingClef", { { "staff", i + 1 } }, TConv::toXml(ct.transposingClef));
2004 : } else {
2005 14 : xml.tag("concertClef", TConv::toXml(ct.concertClef));
2006 14 : xml.tag("transposingClef", TConv::toXml(ct.transposingClef));
2007 : }
2008 : }
2009 : }
2010 :
2011 1769 : if (item->singleNoteDynamics() != item->getSingleNoteDynamicsFromTemplate()) {
2012 553 : xml.tag("singleNoteDynamics", item->singleNoteDynamics());
2013 : }
2014 :
2015 1769 : if (item->glissandoStyle() != GlissandoStyle::CHROMATIC) {
2016 44 : xml.tag("glissandoStyle", TConv::toXml(item->glissandoStyle()));
2017 : }
2018 :
2019 1769 : if (!item->stringData()->isNull()) {
2020 424 : write(item->stringData(), xml);
2021 : }
2022 :
2023 1769 : for (const NamedEventList& a : item->midiActions()) {
2024 0 : write(&a, xml, "MidiAction");
2025 : }
2026 10065 : for (const MidiArticulation& a : item->articulation()) {
2027 8296 : write(&a, xml);
2028 : }
2029 3744 : for (const InstrChannel* a : item->channel()) {
2030 1975 : write(a, xml, part);
2031 : }
2032 1769 : xml.endElement();
2033 3938 : }
2034 :
2035 2737 : static void midi_event_write(const MidiCoreEvent& e, XmlWriter& xml)
2036 : {
2037 2737 : switch (e.type()) {
2038 0 : case ME_NOTEON:
2039 0 : xml.tag("note-on", { { "channel", e.channel() }, { "pitch", e.pitch() }, { "velo", e.velo() } });
2040 0 : break;
2041 :
2042 0 : case ME_NOTEOFF:
2043 0 : xml.tag("note-off", { { "channel", e.channel() }, { "pitch", e.pitch() }, { "velo", e.velo() } });
2044 0 : break;
2045 :
2046 2737 : case ME_CONTROLLER:
2047 2737 : if (e.controller() == CTRL_PROGRAM) {
2048 1886 : if (e.channel() == 0) {
2049 5658 : xml.tag("program", { { "value", e.value() } });
2050 : } else {
2051 0 : xml.tag("program", { { "channel", e.channel() }, { "value", e.value() } });
2052 : }
2053 : } else {
2054 851 : if (e.channel() == 0) {
2055 3404 : xml.tag("controller", { { "ctrl", e.controller() }, { "value", e.value() } });
2056 : } else {
2057 0 : xml.tag("controller", { { "channel", e.channel() }, { "ctrl", e.controller() }, { "value", e.value() } });
2058 : }
2059 : }
2060 2737 : break;
2061 0 : default:
2062 0 : LOGD("MidiCoreEvent::write: unknown type");
2063 0 : break;
2064 : }
2065 5474 : }
2066 :
2067 1975 : void TWrite::write(const InstrChannel* item, XmlWriter& xml, const Part* part)
2068 : {
2069 1975 : if (item->name().isEmpty() || item->name() == InstrChannel::DEFAULT_NAME) {
2070 1724 : xml.startElement("Channel");
2071 : } else {
2072 753 : xml.startElement("Channel", { { "name", item->name() } });
2073 : }
2074 1975 : if (item->color() != InstrChannel::DEFAULT_COLOR) {
2075 0 : xml.tag("color", item->color());
2076 : }
2077 :
2078 15800 : for (const MidiCoreEvent& e : item->initList()) {
2079 13825 : if (e.type() == ME_INVALID) {
2080 89 : continue;
2081 : }
2082 13736 : if (e.type() == ME_CONTROLLER) {
2083 : // Don't write bank if automatically switched, but always write if switched by the user
2084 13736 : if (e.dataA() == CTRL_HBANK && e.dataB() == 0 && !item->userBankController()) {
2085 1897 : continue;
2086 : }
2087 11839 : if (e.dataA() == CTRL_LBANK && e.dataB() == 0 && !item->userBankController()) {
2088 1901 : continue;
2089 : }
2090 9938 : if (e.dataA() == CTRL_VOLUME && e.dataB() == 100) {
2091 1614 : continue;
2092 : }
2093 8324 : if (e.dataA() == CTRL_PANPOT && e.dataB() == 64) {
2094 1722 : continue;
2095 : }
2096 6602 : if (e.dataA() == CTRL_REVERB_SEND && e.dataB() == 0) {
2097 1933 : continue;
2098 : }
2099 4669 : if (e.dataA() == CTRL_CHORUS_SEND && e.dataB() == 0) {
2100 1932 : continue;
2101 : }
2102 : }
2103 :
2104 2737 : midi_event_write(e, xml);
2105 : }
2106 1975 : if (!MScore::testMode) {
2107 : // xml.tag("synti", ::synti->name(synti));
2108 0 : xml.tag("synti", item->synti());
2109 : }
2110 :
2111 1975 : if (part && part->masterScore()->exportMidiMapping() && part->score() == part->masterScore()) {
2112 242 : xml.tag("midiPort", part->masterScore()->midiMapping(item->channel())->port());
2113 242 : xml.tag("midiChannel", part->masterScore()->midiMapping(item->channel())->channel());
2114 : }
2115 1975 : for (const NamedEventList& a : item->midiActions) {
2116 0 : write(&a, xml, "MidiAction");
2117 : }
2118 1975 : for (const MidiArticulation& a : item->articulation) {
2119 0 : write(&a, xml);
2120 : }
2121 1975 : xml.endElement();
2122 2226 : }
2123 :
2124 8296 : void TWrite::write(const MidiArticulation* item, XmlWriter& xml)
2125 : {
2126 8296 : if (item->name.isEmpty()) {
2127 1120 : xml.startElement("Articulation");
2128 : } else {
2129 21528 : xml.startElement("Articulation", { { "name", item->name } });
2130 : }
2131 8296 : if (!item->descr.isEmpty()) {
2132 0 : xml.tag("descr", item->descr);
2133 : }
2134 8296 : xml.tag("velocity", item->velocity);
2135 8296 : xml.tag("gateTime", item->gateTime);
2136 8296 : xml.endElement();
2137 15472 : }
2138 :
2139 0 : void TWrite::write(const StaffLabel& item, XmlWriter& xml)
2140 : {
2141 0 : xml.startElement("StaffLabel");
2142 0 : writeProperties(item, xml);
2143 0 : xml.endElement();
2144 0 : }
2145 :
2146 1435 : void TWrite::writeProperties(const StaffLabel& item, XmlWriter& xml)
2147 : {
2148 1435 : String longName = item.longName();
2149 1435 : if (!longName.empty()) {
2150 1412 : xml.writeXml(u"longName", lineBreakToTag(longName));
2151 : }
2152 :
2153 1435 : String shortName = item.shortName();
2154 1435 : if (!shortName.empty()) {
2155 1252 : xml.writeXml(u"shortName", lineBreakToTag(shortName));
2156 : }
2157 1435 : }
2158 :
2159 1435 : void TWrite::write(const InstrumentLabel& item, XmlWriter& xml)
2160 : {
2161 1435 : xml.startElement("InstrumentLabel");
2162 1435 : writeProperties(item, xml);
2163 1435 : xml.endElement();
2164 1435 : }
2165 :
2166 1435 : void TWrite::writeProperties(const InstrumentLabel& item, XmlWriter& xml)
2167 : {
2168 1435 : writeProperties(static_cast<StaffLabel>(item), xml);
2169 :
2170 1435 : String transposition = item.transposition();
2171 1435 : if (!transposition.empty()) {
2172 0 : xml.writeXml(u"transposition", lineBreakToTag(transposition));
2173 : }
2174 :
2175 1435 : if (!item.showTranspositionLong()) {
2176 0 : xml.tag("showTranspositionLong", item.showTranspositionLong());
2177 : }
2178 :
2179 1435 : if (!item.showTranspositionShort()) {
2180 0 : xml.tag("showTranspositionShort", item.showTranspositionShort());
2181 : }
2182 :
2183 1435 : if (item.number() != 0) {
2184 2 : xml.tag("number", item.number());
2185 : }
2186 :
2187 1435 : if (!item.showNumberLong()) {
2188 1 : xml.tag("showNumberLong", item.showNumberLong());
2189 : }
2190 :
2191 1435 : if (!item.showNumberShort()) {
2192 1 : xml.tag("showNumberShort", item.showNumberShort());
2193 : }
2194 :
2195 1435 : if (item.useCustomName()) {
2196 0 : xml.tag("useCustomName", item.useCustomName());
2197 : }
2198 :
2199 1435 : if (!item.customNameLong().empty()) {
2200 0 : xml.writeXml(u"customNameLong", item.customNameLong());
2201 : }
2202 :
2203 1435 : if (!item.customNameShort().empty()) {
2204 0 : xml.writeXml(u"customNameShort", item.customNameShort());
2205 : }
2206 :
2207 1435 : if (!item.allowGroupName()) {
2208 1 : xml.tag("allowGroupName", item.allowGroupName());
2209 : }
2210 :
2211 1435 : if (!item.customNameLongGroup().empty()) {
2212 0 : xml.writeXml(u"customNameLongGroup", item.customNameLongGroup());
2213 : }
2214 :
2215 1435 : if (!item.customNameShortGroup().empty()) {
2216 0 : xml.writeXml(u"customNameShortGroup", item.customNameShortGroup());
2217 : }
2218 :
2219 1435 : if (item.useCustomGroupName()) {
2220 0 : xml.tag("useCustomGroupName", item.useCustomGroupName());
2221 : }
2222 :
2223 1435 : if (!item.customNameLongIndividual().empty()) {
2224 0 : xml.writeXml(u"customNameLongIndividual", item.customNameLongIndividual());
2225 : }
2226 :
2227 1435 : if (!item.customNameShortIndividual().empty()) {
2228 0 : xml.writeXml(u"customNameShortIndividual", item.customNameShortIndividual());
2229 : }
2230 :
2231 1435 : if (item.useCustomIndividualName()) {
2232 0 : xml.tag("useCustomIndividualName", item.useCustomIndividualName());
2233 : }
2234 1435 : }
2235 :
2236 0 : void TWrite::write(const NamedEventList* item, XmlWriter& xml, const AsciiStringView& n)
2237 : {
2238 0 : xml.startElement(n, { { "name", item->name } });
2239 0 : if (!item->descr.empty()) {
2240 0 : xml.tag("descr", item->descr);
2241 : }
2242 0 : for (const MidiCoreEvent& e : item->events) {
2243 0 : midi_event_write(e, xml);
2244 : }
2245 0 : xml.endElement();
2246 0 : }
2247 :
2248 24 : void TWrite::write(const InstrumentChange* item, XmlWriter& xml, WriteContext& ctx)
2249 : {
2250 24 : xml.startElement(item);
2251 24 : write(item->instrument(), xml, ctx, item->part());
2252 24 : if (item->init()) {
2253 1 : xml.tag("init", item->init());
2254 : }
2255 24 : writeProperties(toTextBase(item), xml, ctx, true);
2256 24 : xml.endElement();
2257 24 : }
2258 :
2259 72 : void TWrite::write(const Jump* item, XmlWriter& xml, WriteContext& ctx)
2260 : {
2261 72 : xml.startElement(item);
2262 72 : writeProperties(toTextBase(item), xml, ctx, true);
2263 72 : xml.tag("jumpTo", item->jumpTo());
2264 72 : xml.tag("playUntil", item->playUntil());
2265 72 : xml.tag("continueAt", item->continueAt());
2266 72 : writeProperty(item, xml, Pid::PLAY_REPEATS);
2267 72 : xml.endElement();
2268 72 : }
2269 :
2270 1231 : void TWrite::write(const KeySig* item, XmlWriter& xml, WriteContext& ctx)
2271 : {
2272 1231 : xml.startElement(item);
2273 1231 : writeItemProperties(item, xml, ctx);
2274 1231 : if (item->isAtonal()) {
2275 7 : xml.tag("custom", 1);
2276 : } else {
2277 1224 : xml.tag("concertKey", int(item->concertKey()));
2278 1224 : if (item->concertKey() != item->key()) {
2279 114 : xml.tag("actualKey", int(item->key()));
2280 : }
2281 1224 : if (item->isCustom()) {
2282 0 : xml.tag("custom", 1);
2283 0 : for (const CustDef& cd : item->customKeyDefs()) {
2284 0 : xml.startElement("CustDef");
2285 0 : xml.tag("sym", SymNames::nameForSymId(cd.sym));
2286 0 : xml.tag("def", { { "degree", cd.degree }, { "xAlt", cd.xAlt.val() }, { "octAlt", cd.octAlt } });
2287 0 : xml.endElement();
2288 : }
2289 : }
2290 : }
2291 :
2292 1231 : if (item->mode() != KeyMode::UNKNOWN) {
2293 312 : xml.tag("mode", TConv::toXml(item->mode()));
2294 : }
2295 :
2296 1231 : if (item->jianpuNumbering() != JianpuNumbering::FOLLOW_SCORE_KEY) {
2297 1 : xml.tag("jianpuNumbering", TConv::toXml(item->jianpuNumbering()));
2298 1 : xml.tag("jianpuTonicKey", TConv::toXml(item->jianpuTonicKey()));
2299 1 : xml.tag("jianpuTonicMode", TConv::toXml(item->jianpuTonicMode()));
2300 : }
2301 :
2302 1231 : writeProperty(item, xml, Pid::SHOW_COURTESY);
2303 1231 : writeProperty(item, xml, Pid::IS_COURTESY);
2304 :
2305 1231 : if (item->forInstrumentChange()) {
2306 0 : xml.tag("forInstrumentChange", true);
2307 : }
2308 1231 : xml.endElement();
2309 1231 : }
2310 :
2311 21 : void TWrite::write(const LaissezVib* item, XmlWriter& xml, WriteContext& ctx)
2312 : {
2313 21 : xml.startElement(item);
2314 21 : writeProperty(item, xml, Pid::MIN_LENGTH);
2315 21 : writeProperty(item, xml, Pid::TIE_PLACEMENT);
2316 21 : writeProperties(static_cast<const SlurTie*>(item), xml, ctx);
2317 21 : xml.endElement();
2318 21 : }
2319 :
2320 531 : void TWrite::write(const LayoutBreak* item, XmlWriter& xml, WriteContext& ctx)
2321 : {
2322 531 : xml.startElement(item);
2323 531 : writeItemProperties(item, xml, ctx);
2324 :
2325 3717 : for (auto id :
2326 : { Pid::LAYOUT_BREAK, Pid::PAUSE, Pid::START_WITH_LONG_NAMES, Pid::START_WITH_MEASURE_ONE, Pid::FIRST_SYSTEM_INDENTATION,
2327 4248 : Pid::SHOW_COURTESY }) {
2328 3186 : writeProperty(item, xml, id);
2329 : }
2330 :
2331 531 : xml.endElement();
2332 531 : }
2333 :
2334 0 : void TWrite::write(const LedgerLine* item, XmlWriter& xml, WriteContext&)
2335 : {
2336 0 : xml.startElement(item);
2337 0 : xml.tag("lineWidth", item->width() / item->spatium());
2338 0 : xml.tag("lineLen", item->len() / item->spatium());
2339 0 : if (!item->vertical()) {
2340 0 : xml.tag("vertical", item->vertical());
2341 : }
2342 0 : xml.endElement();
2343 0 : }
2344 :
2345 52 : void TWrite::write(const LetRing* item, XmlWriter& xml, WriteContext& ctx)
2346 : {
2347 52 : if (!ctx.canWrite(item)) {
2348 0 : return;
2349 : }
2350 52 : xml.startElement(item);
2351 52 : writeProperties(static_cast<const TextLineBase*>(item), xml, ctx);
2352 52 : xml.endElement();
2353 : }
2354 :
2355 290 : void TWrite::write(const Location* item, XmlWriter& xml, WriteContext&)
2356 : {
2357 : static constexpr Location relDefaults = Location::relative();
2358 :
2359 290 : DO_ASSERT(item->isRelative());
2360 290 : xml.startElement("location");
2361 290 : xml.tag("staves", item->staff(), relDefaults.staff());
2362 290 : xml.tag("voices", item->voice(), relDefaults.voice());
2363 290 : xml.tag("measures", item->measure(), relDefaults.measure());
2364 290 : xml.tagFraction("fractions", item->frac().reduced(), relDefaults.frac());
2365 290 : xml.tag("grace", item->graceIndex(), relDefaults.graceIndex());
2366 290 : xml.tag("notes", item->note(), relDefaults.note());
2367 290 : xml.tag("timeTick", item->isTimeTick(), false);
2368 290 : xml.endElement();
2369 290 : }
2370 :
2371 448 : void TWrite::write(const Lyrics* item, XmlWriter& xml, WriteContext& ctx)
2372 : {
2373 448 : if (!ctx.canWrite(item)) {
2374 5 : return;
2375 : }
2376 443 : xml.startElement(item);
2377 443 : writeProperty(item, xml, Pid::VERSE);
2378 443 : if (item->syllabic() != LyricsSyllabic::SINGLE) {
2379 189 : xml.tag("syllabic", TConv::toXml(item->syllabic()));
2380 : }
2381 443 : writeProperty(item, xml, Pid::LYRIC_TICKS);
2382 443 : writeProperty(item, xml, Pid::CENTER_BETWEEN_STAVES);
2383 :
2384 443 : writeProperties(toTextBase(item), xml, ctx, true);
2385 443 : if (item->separator() && !item->separator()->generated()) {
2386 0 : write(item->separator(), xml, ctx);
2387 : }
2388 443 : xml.endElement();
2389 : }
2390 :
2391 2 : void TWrite::write(const LyricsLine* item, XmlWriter& xml, WriteContext& ctx)
2392 : {
2393 2 : if (!ctx.canWrite(item)) {
2394 0 : return;
2395 : }
2396 2 : xml.startElement(item);
2397 2 : writeProperties(static_cast<const SLine*>(item), xml, ctx);
2398 2 : xml.endElement();
2399 : }
2400 :
2401 75 : void TWrite::write(const Marker* item, XmlWriter& xml, WriteContext& ctx)
2402 : {
2403 75 : xml.startElement(item);
2404 75 : writeProperties(toTextBase(item), xml, ctx, true);
2405 75 : xml.tag("label", item->label());
2406 75 : writeProperty(item, xml, Pid::MARKER_TYPE);
2407 75 : writeProperty(item, xml, Pid::MARKER_CENTER_ON_SYMBOL);
2408 75 : xml.endElement();
2409 75 : }
2410 :
2411 0 : void TWrite::write(const MeasureNumber* item, XmlWriter& xml, WriteContext& ctx)
2412 : {
2413 0 : if (!ctx.canWrite(item)) {
2414 0 : return;
2415 : }
2416 0 : xml.startElement(item);
2417 0 : writeProperties(toTextBase(item), xml, ctx, true);
2418 0 : xml.endElement();
2419 : }
2420 :
2421 82 : void TWrite::write(const MeasureRepeat* item, XmlWriter& xml, WriteContext& ctx)
2422 : {
2423 82 : xml.startElement(item);
2424 82 : writeProperty(item, xml, Pid::SUBTYPE);
2425 82 : writeProperties(toRest(item), xml, ctx);
2426 82 : writeProperty(item, xml, Pid::MEASURE_REPEAT_NUMBER_OFFSET);
2427 82 : writeItems(item->el(), xml, ctx);
2428 82 : xml.endElement();
2429 82 : }
2430 :
2431 82 : void TWrite::writeProperties(const Rest* item, XmlWriter& xml, WriteContext& ctx)
2432 : {
2433 82 : writeProperties(toChordRest(item), xml, ctx);
2434 82 : }
2435 :
2436 34 : void TWrite::write(const MMRest* item, XmlWriter& xml, WriteContext& ctx)
2437 : {
2438 34 : xml.startElement("Rest"); // for compatibility, see also Measure::readVoice()
2439 34 : writeProperties(toChordRest(item), xml, ctx);
2440 34 : writeProperty(item, xml, Pid::MMREST_NUMBER_OFFSET);
2441 34 : writeProperty(item, xml, Pid::MMREST_NUMBER_VISIBLE);
2442 34 : writeItems(item->el(), xml, ctx);
2443 34 : xml.endElement();
2444 34 : }
2445 :
2446 0 : void TWrite::write(const MMRestRange* item, XmlWriter& xml, WriteContext& ctx)
2447 : {
2448 0 : if (!ctx.canWrite(item)) {
2449 0 : return;
2450 : }
2451 0 : xml.startElement(item);
2452 0 : writeProperties(toTextBase(item), xml, ctx, true);
2453 0 : xml.endElement();
2454 : }
2455 :
2456 23753 : void TWrite::write(const Note* item, XmlWriter& xml, WriteContext& ctx)
2457 : {
2458 23753 : xml.startElement(item);
2459 23753 : writeItemProperties(item, xml, ctx);
2460 :
2461 23753 : if (item->accidental()) {
2462 2608 : write(item->accidental(), xml, ctx);
2463 : }
2464 23753 : writeItems(item->el(), xml, ctx);
2465 23753 : bool write_dots = false;
2466 24201 : for (NoteDot* dot : item->dots()) {
2467 1344 : if (!dot->offset().isNull() || !dot->visible() || dot->color() != ctx.configuration()->defaultColor()
2468 1344 : || dot->visible() != item->visible()) {
2469 0 : write_dots = true;
2470 0 : break;
2471 : }
2472 : }
2473 23753 : if (write_dots) {
2474 0 : for (NoteDot* dot : item->dots()) {
2475 0 : write(dot, xml, ctx);
2476 : }
2477 : }
2478 :
2479 23753 : if (item->laissezVib()) {
2480 21 : write(item->laissezVib(), xml, ctx);
2481 : }
2482 :
2483 23753 : if (item->incomingPartialTie()) {
2484 28 : write(item->incomingPartialTie(), xml, ctx);
2485 : }
2486 :
2487 23753 : if (item->outgoingPartialTie()) {
2488 16 : write(item->outgoingPartialTie(), xml, ctx);
2489 : }
2490 :
2491 23753 : if (Tie* tieBack = item->tieBackNonPartial()) {
2492 599 : Note* tieStartNote = tieBack->startNote();
2493 599 : const std::optional<Fraction>& firstClipboardTick = ctx.firstClipboardTick();
2494 608 : bool tieStartOutOfRange = firstClipboardTick.has_value() && tieStartNote
2495 608 : && tieStartNote->tick() < firstClipboardTick.value();
2496 599 : if (!tieStartOutOfRange) {
2497 598 : TWrite::writeItem(tieBack, xml, ctx);
2498 : }
2499 : }
2500 :
2501 23753 : if ((item->chord() == 0 || item->chord()->playEventType() != PlayEventType::Auto) && !item->playEvents().empty()) {
2502 25 : xml.startElement("Events");
2503 50 : for (const NoteEvent& e : item->playEvents()) {
2504 25 : write(&e, xml, ctx);
2505 : }
2506 25 : xml.endElement();
2507 : }
2508 475060 : for (Pid id : { Pid::PITCH, Pid::CENT_OFFSET, Pid::TPC1, Pid::TPC2, Pid::SMALL, Pid::MIRROR_HEAD, Pid::DOT_POSITION,
2509 : Pid::HEAD_SCHEME, Pid::HEAD_GROUP, Pid::USER_VELOCITY, Pid::PLAY, Pid::TUNING, Pid::FRET, Pid::STRING,
2510 498813 : Pid::GHOST, Pid::DEAD, Pid::HEAD_TYPE, Pid::FIXED, Pid::FIXED_LINE }) {
2511 451307 : writeProperty(item, xml, id);
2512 : }
2513 :
2514 24138 : for (Spanner* e : item->spannerBack()) {
2515 385 : TWrite::writeItem(e, xml, ctx);
2516 : }
2517 :
2518 23848 : for (EngravingItem* e : item->chord()->el()) {
2519 95 : if (e->isChordLine() && toChordLine(e)->note() && toChordLine(e)->note() == item) {
2520 69 : write(toChordLine(e), xml, ctx);
2521 : }
2522 : }
2523 :
2524 23753 : if (item->overrideBendVisibilityRules()) {
2525 0 : xml.tag("overrideBendVisibilityRules", true);
2526 : }
2527 :
2528 23753 : writeProperty(item, xml, Pid::HIDE_GENERATED_PARENTHESES);
2529 :
2530 23753 : xml.endElement();
2531 23753 : }
2532 :
2533 25 : void TWrite::write(const NoteEvent* item, XmlWriter& xml, WriteContext&)
2534 : {
2535 25 : xml.startElement("Event");
2536 25 : xml.tag("pitch", item->pitch(), 0);
2537 25 : xml.tag("ontime", item->ontime(), 0);
2538 25 : xml.tag("len", item->len(), NoteEvent::NOTE_LENGTH);
2539 25 : xml.endElement();
2540 25 : }
2541 :
2542 8 : void TWrite::write(const NoteDot* item, XmlWriter& xml, WriteContext& ctx)
2543 : {
2544 8 : xml.startElement(item);
2545 8 : writeItemProperties(item, xml, ctx);
2546 8 : xml.endElement();
2547 8 : }
2548 :
2549 0 : void TWrite::write(const NoteHead* item, XmlWriter& xml, WriteContext& ctx)
2550 : {
2551 0 : write(static_cast<const Symbol*>(item), xml, ctx);
2552 0 : }
2553 :
2554 2 : void TWrite::write(const NoteLine* item, XmlWriter& xml, WriteContext& ctx)
2555 : {
2556 2 : if (!ctx.canWrite(item)) {
2557 0 : return;
2558 : }
2559 2 : xml.startElement(item);
2560 2 : writeProperties(static_cast<const TextLineBase*>(item), xml, ctx);
2561 2 : xml.endElement();
2562 : }
2563 :
2564 108 : void TWrite::write(const Ottava* item, XmlWriter& xml, WriteContext& ctx)
2565 : {
2566 108 : if (!ctx.canWrite(item)) {
2567 0 : return;
2568 : }
2569 108 : xml.startElement(item);
2570 324 : for (Pid pid : { Pid::OTTAVA_TYPE, Pid::NUMBERS_ONLY }) {
2571 216 : if (item->propertyFlags(pid) == PropertyFlags::NOSTYLE) {
2572 108 : writeProperty(item, xml, pid);
2573 : }
2574 : }
2575 108 : writeProperties(static_cast<const TextLineBase*>(item), xml, ctx);
2576 108 : xml.endElement();
2577 : }
2578 :
2579 0 : void TWrite::write(const Page* item, XmlWriter& xml, WriteContext& ctx)
2580 : {
2581 0 : xml.startElement(item);
2582 0 : for (System* system : item->systems()) {
2583 0 : write(system, xml, ctx);
2584 : }
2585 0 : xml.endElement();
2586 0 : }
2587 :
2588 45 : void TWrite::write(const PalmMute* item, XmlWriter& xml, WriteContext& ctx)
2589 : {
2590 45 : if (!ctx.canWrite(item)) {
2591 0 : return;
2592 : }
2593 45 : xml.startElement(item);
2594 45 : writeProperties(static_cast<const TextLineBase*>(item), xml, ctx);
2595 45 : xml.endElement();
2596 : }
2597 :
2598 300 : void TWrite::write(const Parenthesis* item, XmlWriter& xml, WriteContext& ctx)
2599 : {
2600 300 : if (!ctx.canWrite(item)) {
2601 0 : return;
2602 : }
2603 :
2604 300 : xml.startElement(item);
2605 300 : writeProperty(item, xml, Pid::HORIZONTAL_DIRECTION);
2606 300 : writeItemProperties(item, xml, ctx);
2607 300 : xml.endElement();
2608 : }
2609 :
2610 1745 : void TWrite::write(const Part* item, XmlWriter& xml, WriteContext& ctx)
2611 : {
2612 1745 : if (item->isSharedPart()) {
2613 1 : write(toSharedPart(item), xml, ctx);
2614 1 : return;
2615 : }
2616 :
2617 6976 : xml.startElement(item, { { "id", item->id().toUint64() } });
2618 :
2619 1744 : writeItemEid(item, xml);
2620 :
2621 1744 : writeProperties(item, xml, ctx);
2622 :
2623 1744 : if (SharedPart* sharedPart = item->sharedPart()) {
2624 2 : DO_ASSERT(sharedPart->eid().isValid());
2625 2 : xml.tag("sharedPart", sharedPart->eid().toStdString());
2626 : }
2627 :
2628 1744 : xml.endElement();
2629 3488 : }
2630 :
2631 4 : static void writeStaveSharingState(const StaveSharingState& state, const Fraction& tick, XmlWriter& xml)
2632 : {
2633 4 : if (!state.isUserModified()) {
2634 4 : return;
2635 : }
2636 0 : xml.startElement("StaveSharingState", { { "tick", tick.toString() } });
2637 0 : if (state.isReset()) {
2638 0 : xml.tag("isReset", state.isReset());
2639 : }
2640 0 : for (const auto& [originTrack, sharedTrack] : state.userTrackMap().value()) {
2641 0 : xml.tag("trackMap", { { "origin", originTrack }, { "shared", sharedTrack } });
2642 : }
2643 0 : xml.endElement();
2644 0 : }
2645 :
2646 1 : void TWrite::write(const SharedPart* item, XmlWriter& xml, WriteContext& ctx)
2647 : {
2648 4 : xml.startElement(item, { { "id", item->id().toUint64() } });
2649 :
2650 1 : writeItemEid(item, xml);
2651 :
2652 1 : xml.tag(propertyName(Pid::SHARED_PART_ENABLED), item->getProperty(Pid::SHARED_PART_ENABLED).toBool());
2653 :
2654 1 : const Fraction& endTick = item->score()->endTick();
2655 :
2656 5 : for (const auto& [tick, state] : item->staveSharingStatesBetweenTicks(Fraction(0, 1), endTick)) {
2657 4 : writeStaveSharingState(state, tick, xml);
2658 1 : }
2659 :
2660 1 : writeProperties(item, xml, ctx);
2661 :
2662 1 : xml.endElement();
2663 3 : }
2664 :
2665 1745 : void TWrite::writeProperties(const Part* item, XmlWriter& xml, WriteContext& ctx)
2666 : {
2667 1978 : auto shouldWriteStaff = [&ctx](const Staff* staff) {
2668 1978 : if (!ctx.shouldWriteRange()) {
2669 1978 : return true;
2670 : }
2671 :
2672 0 : const WriteRange& range = ctx.range().value();
2673 0 : const staff_idx_t idx = staff->idx();
2674 :
2675 0 : return idx >= range.startStaffIdx && idx < range.endStaffIdx;
2676 1745 : };
2677 :
2678 3723 : for (const Staff* staff : item->staves()) {
2679 1978 : if (shouldWriteStaff(staff)) {
2680 1978 : write(staff, xml, ctx);
2681 : }
2682 : }
2683 :
2684 1745 : if (bool show = item->getProperty(Pid::VISIBLE).toBool(); !show) {
2685 4 : xml.tag("show", show);
2686 : }
2687 :
2688 1745 : if (item->soloist()) {
2689 1 : xml.tag("soloist", item->soloist());
2690 : }
2691 :
2692 1745 : if (item->hideWhenEmpty() != AutoOnOff::AUTO) {
2693 0 : xml.tag("hideWhenEmpty", TConv::toXml(item->hideWhenEmpty()));
2694 : }
2695 :
2696 1745 : if (item->hideStavesWhenIndividuallyEmpty()) {
2697 2 : xml.tag("hideStavesWhenIndividuallyEmpty", item->hideStavesWhenIndividuallyEmpty());
2698 : }
2699 :
2700 1745 : if (item->preferSharpFlat() != PreferSharpFlat::AUTO) {
2701 10 : switch (item->preferSharpFlat()) {
2702 0 : case PreferSharpFlat::AUTO:
2703 0 : break;
2704 4 : case PreferSharpFlat::FLATS:
2705 4 : xml.tag("preferSharpFlat", "flats");
2706 4 : break;
2707 2 : case PreferSharpFlat::SHARPS:
2708 2 : xml.tag("preferSharpFlat", "sharps");
2709 2 : break;
2710 4 : case PreferSharpFlat::NONE:
2711 4 : xml.tag("preferSharpFlat", "none");
2712 4 : break;
2713 0 : default:
2714 0 : break;
2715 : }
2716 : }
2717 :
2718 1745 : write(item->instrument(), xml, ctx, item);
2719 1745 : }
2720 :
2721 44 : void TWrite::write(const PartialTie* item, XmlWriter& xml, WriteContext& ctx)
2722 : {
2723 44 : xml.startElement(item);
2724 44 : writeProperty(item, xml, Pid::TIE_PLACEMENT);
2725 44 : writeProperty(item, xml, Pid::PARTIAL_SPANNER_DIRECTION);
2726 44 : writeProperties(static_cast<const SlurTie*>(item), xml, ctx);
2727 44 : xml.endElement();
2728 44 : }
2729 :
2730 6 : void TWrite::write(const PartialLyricsLine* item, XmlWriter& xml, WriteContext& ctx)
2731 : {
2732 6 : if (!ctx.canWrite(item)) {
2733 0 : return;
2734 : }
2735 6 : xml.startElement(item);
2736 18 : for (Pid pid : { Pid::VERSE, Pid::CENTER_BETWEEN_STAVES }) {
2737 12 : if (item->propertyFlags(pid) == PropertyFlags::NOSTYLE) {
2738 12 : writeProperty(item, xml, pid);
2739 : }
2740 : }
2741 6 : xml.tag("isEndMelisma", item->isEndMelisma());
2742 6 : writeProperties(static_cast<const SLine*>(item), xml, ctx);
2743 6 : xml.endElement();
2744 : }
2745 :
2746 63 : void TWrite::write(const Pedal* item, XmlWriter& xml, WriteContext& ctx)
2747 : {
2748 63 : if (!ctx.canWrite(item)) {
2749 0 : return;
2750 : }
2751 63 : xml.startElement(item);
2752 63 : writeProperties(static_cast<const TextLineBase*>(item), xml, ctx);
2753 63 : xml.endElement();
2754 : }
2755 :
2756 2 : void TWrite::write(const PickScrape* item, XmlWriter& xml, WriteContext& ctx)
2757 : {
2758 2 : if (!ctx.canWrite(item)) {
2759 0 : return;
2760 : }
2761 2 : xml.startElement(item);
2762 2 : writeProperties(static_cast<const TextLineBase*>(item), xml, ctx);
2763 2 : xml.endElement();
2764 : }
2765 :
2766 6 : void TWrite::write(const PlayCountText* item, XmlWriter& xml, WriteContext& ctx)
2767 : {
2768 6 : xml.startElement(item);
2769 6 : writeProperty(item, xml, Pid::PLAY_COUNT_TEXT_SETTING);
2770 6 : writeProperty(item, xml, Pid::PLAY_COUNT_TEXT);
2771 6 : writeProperties(toTextBase(item), xml, ctx, true);
2772 6 : xml.endElement();
2773 6 : }
2774 :
2775 6 : void TWrite::write(const PlayTechAnnotation* item, XmlWriter& xml, WriteContext& ctx)
2776 : {
2777 6 : xml.startElement(item);
2778 6 : writeProperty(item, xml, Pid::PLAY_TECH_TYPE);
2779 6 : writeProperty(item, xml, Pid::PLAY);
2780 6 : writeProperties(toTextBase(item), xml, ctx, true);
2781 6 : xml.endElement();
2782 6 : }
2783 :
2784 35 : void TWrite::write(const Rasgueado* item, XmlWriter& xml, WriteContext& ctx)
2785 : {
2786 35 : if (!ctx.canWrite(item)) {
2787 0 : return;
2788 : }
2789 35 : xml.startElement(item);
2790 35 : writeProperties(static_cast<const TextLineBase*>(item), xml, ctx);
2791 35 : xml.endElement();
2792 : }
2793 :
2794 50 : void TWrite::write(const RehearsalMark* item, XmlWriter& xml, WriteContext& ctx)
2795 : {
2796 50 : if (!ctx.canWrite(item)) {
2797 0 : return;
2798 : }
2799 50 : xml.startElement(item);
2800 50 : writeProperties(toTextBase(item), xml, ctx, true);
2801 50 : xml.endElement();
2802 : }
2803 :
2804 14677 : void TWrite::write(const Rest* item, XmlWriter& xml, WriteContext& ctx)
2805 : {
2806 14677 : if (item->isGap()) {
2807 50 : return;
2808 : }
2809 14627 : writeChordRestBeam(item, xml, ctx);
2810 14627 : xml.startElement(item);
2811 14627 : writeStyledProperties(item, xml);
2812 14627 : writeProperty(item, xml, Pid::ALIGN_WITH_OTHER_RESTS);
2813 14627 : writeProperties(toChordRest(item), xml, ctx);
2814 14627 : writeItems(item->el(), xml, ctx);
2815 14627 : bool write_dots = false;
2816 14719 : for (NoteDot* dot : item->dotList()) {
2817 300 : if (!dot->offset().isNull() || !dot->visible() || dot->color() != ctx.configuration()->defaultColor()
2818 300 : || dot->visible() != item->visible()) {
2819 8 : write_dots = true;
2820 8 : break;
2821 : }
2822 : }
2823 14627 : if (write_dots) {
2824 16 : for (NoteDot* dot: item->dotList()) {
2825 8 : write(dot, xml, ctx);
2826 : }
2827 : }
2828 14627 : xml.endElement();
2829 : }
2830 :
2831 39118 : void TWrite::write(const Segment* item, XmlWriter& xml, WriteContext&)
2832 : {
2833 39118 : if (item->written()) {
2834 9772 : return;
2835 : }
2836 29346 : item->setWritten(true);
2837 29346 : if (item->extraLeadingSpace().isZero()) {
2838 29346 : return;
2839 : }
2840 0 : xml.startElement(item);
2841 0 : xml.tag("leadingSpace", item->extraLeadingSpace().val());
2842 0 : xml.endElement();
2843 : }
2844 :
2845 257 : void TWrite::write(const Slur* item, XmlWriter& xml, WriteContext& ctx)
2846 : {
2847 257 : if (!ctx.canWrite(item)) {
2848 0 : return;
2849 : }
2850 :
2851 257 : xml.startElement(item);
2852 :
2853 257 : writeProperty(item, xml, Pid::PARTIAL_SPANNER_DIRECTION);
2854 :
2855 257 : writeProperties(static_cast<const SlurTie*>(item), xml, ctx);
2856 257 : xml.endElement();
2857 : }
2858 :
2859 968 : void TWrite::writeProperties(const SlurTie* item, XmlWriter& xml, WriteContext& ctx)
2860 : {
2861 968 : writeProperties(static_cast<const Spanner*>(item), xml, ctx);
2862 968 : int idx = 0;
2863 1958 : for (const SpannerSegment* ss : item->spannerSegments()) {
2864 990 : writeSlur(((SlurTieSegment*)ss), xml, ctx, idx++);
2865 : }
2866 968 : writeProperty(item, xml, Pid::SLUR_DIRECTION);
2867 968 : writeProperty(item, xml, Pid::SLUR_STYLE_TYPE);
2868 968 : writeProperty(item, xml, Pid::MASK_SLURTIE);
2869 968 : }
2870 :
2871 990 : void TWrite::writeSlur(const SlurTieSegment* seg, XmlWriter& xml, WriteContext& ctx, int no)
2872 : {
2873 990 : if (!seg->isUserModified()) {
2874 937 : return;
2875 : }
2876 :
2877 159 : xml.startElement(seg, { { "no", no } });
2878 :
2879 53 : writeProperty(seg, xml, Pid::BEZIER_OFFSET1);
2880 53 : writeProperty(seg, xml, Pid::BEZIER_OFFSET2);
2881 53 : writeProperty(seg, xml, Pid::BEZIER_OFFSET3);
2882 53 : writeProperty(seg, xml, Pid::BEZIER_OFFSET4);
2883 :
2884 53 : if (seg->isHammerOnPullOffSegment()) {
2885 48 : writeProperties(toHammerOnPullOffSegment(seg), xml, ctx);
2886 : }
2887 :
2888 53 : writeItemProperties(seg, xml, ctx);
2889 53 : xml.endElement();
2890 53 : }
2891 :
2892 0 : void TWrite::write(const Spacer* item, XmlWriter& xml, WriteContext& ctx)
2893 : {
2894 0 : xml.startElement(item);
2895 0 : xml.tag("subtype", int(item->spacerType()));
2896 0 : writeItemProperties(item, xml, ctx);
2897 0 : xml.tag("space", item->gap().val());
2898 0 : xml.endElement();
2899 0 : }
2900 :
2901 1978 : void TWrite::write(const Staff* item, XmlWriter& xml, WriteContext& ctx)
2902 : {
2903 1978 : xml.startElement(item);
2904 :
2905 1978 : writeItemEid(item, xml);
2906 1978 : writeItemLink(item, xml, ctx);
2907 :
2908 : // for copy/paste we need to know the actual transposition
2909 1978 : if (ctx.clipboardmode()) {
2910 0 : Interval v = item->part()->instrument()->transpose(); // TODO: tick?
2911 0 : if (v.diatonic) {
2912 0 : xml.tag("transposeDiatonic", v.diatonic);
2913 : }
2914 0 : if (v.chromatic) {
2915 0 : xml.tag("transposeChromatic", v.chromatic);
2916 : }
2917 : }
2918 :
2919 1978 : write(item->staffType(Fraction(0, 1)), xml, ctx);
2920 1978 : ClefTypeList ct = item->defaultClefType();
2921 1978 : if (ct.concertClef == ct.transposingClef) {
2922 1973 : if (ct.concertClef != ClefType::G) {
2923 218 : xml.tag("defaultClef", TConv::toXml(ct.concertClef));
2924 : }
2925 : } else {
2926 5 : xml.tag("defaultConcertClef", TConv::toXml(ct.concertClef));
2927 5 : xml.tag("defaultTransposingClef", TConv::toXml(ct.transposingClef));
2928 : }
2929 :
2930 1978 : if (item->hideWhenEmpty() != AutoOnOff::AUTO) {
2931 0 : xml.tag("hideWhenEmpty", TConv::toXml(item->hideWhenEmpty()));
2932 : }
2933 1978 : if (item->cutaway()) {
2934 0 : xml.tag("cutaway", item->cutaway());
2935 : }
2936 1978 : if (item->showIfEntireSystemEmpty()) {
2937 0 : xml.tag("showIfSystemEmpty", item->showIfEntireSystemEmpty());
2938 : }
2939 1978 : if (item->hideSystemBarLine()) {
2940 0 : xml.tag("hideSystemBarLine", item->hideSystemBarLine());
2941 : }
2942 1978 : if (item->mergeMatchingRests() != AutoOnOff::AUTO) {
2943 0 : xml.tag("mergeMatchingRests", TConv::toXml(item->mergeMatchingRests()));
2944 : }
2945 1978 : if (!item->visible()) {
2946 2 : xml.tag("isStaffVisible", item->visible());
2947 : }
2948 :
2949 2337 : for (const BracketItem* i : item->score()->brackets(item->idx())) {
2950 359 : write(i, xml);
2951 : }
2952 :
2953 1978 : writeProperty(item, xml, Pid::STAFF_BARLINE_SPAN);
2954 1978 : writeProperty(item, xml, Pid::STAFF_BARLINE_SPAN_FROM);
2955 1978 : writeProperty(item, xml, Pid::STAFF_BARLINE_SPAN_TO);
2956 1978 : writeProperty(item, xml, Pid::STAFF_USERDIST);
2957 1978 : writeProperty(item, xml, Pid::PLAYBACK_VOICE1);
2958 1978 : writeProperty(item, xml, Pid::PLAYBACK_VOICE2);
2959 1978 : writeProperty(item, xml, Pid::PLAYBACK_VOICE3);
2960 1978 : writeProperty(item, xml, Pid::PLAYBACK_VOICE4);
2961 1978 : writeProperty(item, xml, Pid::SHOW_MEASURE_NUMBERS);
2962 :
2963 1978 : xml.endElement();
2964 1978 : }
2965 :
2966 359 : void TWrite::write(const BracketItem* item, XmlWriter& xml)
2967 : {
2968 359 : if (item->bracketType() == BracketType::NO_BRACKET) {
2969 150 : return;
2970 : }
2971 :
2972 209 : xml.startElement(item);
2973 :
2974 209 : xml.tag("type", TConv::toXml(item->bracketType()));
2975 209 : writeProperty(item, xml, Pid::BRACKET_SPAN, /*force*/ true);
2976 209 : writeProperty(item, xml, Pid::BRACKET_COLUMN, /*force*/ true);
2977 209 : writeProperty(item, xml, Pid::VISIBLE);
2978 :
2979 209 : if (item->bracketType() == BracketType::GROUP) {
2980 0 : writeProperty(item, xml, Pid::GROUP_BRACKET_SHOW_TEXT);
2981 0 : writeProperty(item, xml, Pid::GROUP_BRACKET_SHOW_BRACKET);
2982 0 : write(item->label(), xml);
2983 : }
2984 :
2985 209 : xml.endElement();
2986 : }
2987 :
2988 0 : void TWrite::write(const StaffState* item, XmlWriter& xml, WriteContext& ctx)
2989 : {
2990 0 : xml.startElement(item);
2991 0 : xml.tag("subtype", int(item->staffStateType()));
2992 0 : if (item->staffStateType() == StaffStateType::INSTRUMENT) {
2993 0 : write(item->instrument(), xml, ctx, nullptr);
2994 : }
2995 0 : writeItemProperties(item, xml, ctx);
2996 0 : xml.endElement();
2997 0 : }
2998 :
2999 357 : void TWrite::write(const StaffText* item, XmlWriter& xml, WriteContext& ctx)
3000 : {
3001 357 : if (!ctx.canWrite(item)) {
3002 26 : return;
3003 : }
3004 :
3005 331 : xml.startElement(item);
3006 :
3007 331 : writeProperties(static_cast<const StaffTextBase*>(item), xml, ctx);
3008 :
3009 331 : if (const SoundFlag* flag = item->soundFlag()) {
3010 0 : writeItem(flag, xml, ctx);
3011 : }
3012 :
3013 331 : xml.endElement();
3014 : }
3015 :
3016 0 : void TWrite::write(const StaveSharingLabel* item, XmlWriter& xml, WriteContext& ctx)
3017 : {
3018 0 : if (!ctx.canWrite(item)) {
3019 0 : return;
3020 : }
3021 :
3022 0 : xml.startElement(item);
3023 :
3024 0 : writeProperties(static_cast<const StaffTextBase*>(item), xml, ctx);
3025 :
3026 0 : xml.endElement();
3027 : }
3028 :
3029 26 : void TWrite::write(const StaffTextBase* item, XmlWriter& xml, WriteContext& ctx)
3030 : {
3031 26 : if (!ctx.canWrite(item)) {
3032 5 : return;
3033 : }
3034 :
3035 21 : xml.startElement(item);
3036 21 : writeProperties(item, xml, ctx);
3037 21 : xml.endElement();
3038 : }
3039 :
3040 352 : void TWrite::writeProperties(const StaffTextBase* item, XmlWriter& xml, WriteContext& ctx)
3041 : {
3042 352 : for (const ChannelActions& s : item->channelActions()) {
3043 0 : int channel = s.channel;
3044 0 : for (const String& name : s.midiActionNames) {
3045 0 : xml.tag("MidiAction", { { "channel", channel }, { "name", name } });
3046 : }
3047 : }
3048 1760 : for (voice_idx_t voice = 0; voice < VOICES; ++voice) {
3049 1408 : if (!item->channelName(voice).isEmpty()) {
3050 0 : xml.tag("channelSwitch", { { "voice", voice }, { "name", item->channelName(voice) } });
3051 : }
3052 : }
3053 352 : if (item->setAeolusStops()) {
3054 0 : for (int i = 0; i < 4; ++i) {
3055 0 : xml.tag("aeolus", { { "group", i } }, item->aeolusStop(i));
3056 : }
3057 : }
3058 352 : if (item->swing()) {
3059 : DurationType swingUnit;
3060 5 : if (item->swingParameters().swingUnit == Constants::DIVISION / 2) {
3061 5 : swingUnit = DurationType::V_EIGHTH;
3062 0 : } else if (item->swingParameters().swingUnit == Constants::DIVISION / 4) {
3063 0 : swingUnit = DurationType::V_16TH;
3064 : } else {
3065 0 : swingUnit = DurationType::V_ZERO;
3066 : }
3067 5 : int swingRatio = item->swingParameters().swingRatio;
3068 20 : xml.tag("swing", { { "unit", TConv::toXml(swingUnit) }, { "ratio", swingRatio } });
3069 : }
3070 :
3071 352 : writeProperties(toTextBase(item), xml, ctx, true);
3072 357 : }
3073 :
3074 1978 : void TWrite::write(const StaffType* item, XmlWriter& xml, WriteContext& ctx)
3075 : {
3076 7912 : xml.startElement("StaffType", { { "group", TConv::toXml(item->group()) } });
3077 1978 : if (!item->xmlName().isEmpty()) {
3078 1978 : xml.tag("name", item->xmlName());
3079 : }
3080 1978 : if (!item->staffLabel().empty()) {
3081 0 : write(item->staffLabel(), xml);
3082 : }
3083 1978 : if (item->lines() != 5) {
3084 78 : xml.tag("lines", item->lines());
3085 : }
3086 1978 : if (!RealIsEqual(item->lineDistance().val(), 1.0)) {
3087 69 : xml.tag("lineDistance", item->lineDistance().val());
3088 : }
3089 1978 : if (!RealIsNull(item->yoffset().val())) {
3090 0 : xml.tag("yoffset", item->yoffset().val());
3091 : }
3092 1978 : if (!RealIsEqual(item->userMag(), 1.0)) {
3093 1 : xml.tag("mag", item->userMag());
3094 : }
3095 1978 : if (item->isSmall()) {
3096 1 : xml.tag("small", item->isSmall());
3097 : }
3098 1978 : if (item->stepOffset()) {
3099 0 : xml.tag("stepOffset", item->stepOffset());
3100 : }
3101 1978 : if (!item->genClef()) {
3102 0 : xml.tag("clef", item->genClef());
3103 : }
3104 1978 : if (item->stemless()) {
3105 66 : xml.tag("stemless", item->stemless());
3106 : }
3107 1978 : if (!item->showBarlines()) {
3108 0 : xml.tag("barlines", item->showBarlines());
3109 : }
3110 1978 : if (!item->genTimesig()) {
3111 66 : xml.tag("timesig", item->genTimesig());
3112 : }
3113 1978 : if (item->invisible()) {
3114 1 : xml.tag("invisible", item->invisible());
3115 : }
3116 1978 : if (item->color() != ctx.configuration()->defaultColor()) {
3117 1 : xml.tagProperty(Pid::COLOR, item->color());
3118 : }
3119 1978 : if (item->group() == StaffGroup::STANDARD || item->group() == StaffGroup::JIANPU) {
3120 1879 : xml.tag("noteheadScheme", TConv::toXml(item->noteHeadScheme()), TConv::toXml(NoteHeadScheme::HEAD_NORMAL));
3121 1879 : if (item->group() == StaffGroup::JIANPU) {
3122 3 : xml.tag("jianpuTextStyle", TConv::toXml(item->jianpuTextStyle()));
3123 : }
3124 : }
3125 1978 : xml.tag("instrumentLabelVisibility", TConv::toXml(item->instrumentLabelVisibility()),
3126 1978 : TConv::toXml(InstrumentLabelVisibility::AUTO));
3127 1978 : if (item->group() == StaffGroup::STANDARD || item->group() == StaffGroup::JIANPU || item->group() == StaffGroup::PERCUSSION) {
3128 1909 : if (!item->genKeysig()) {
3129 30 : xml.tag("keysig", item->genKeysig());
3130 : }
3131 1909 : if (!item->showLedgerLines()) {
3132 0 : xml.tag("ledgerlines", item->showLedgerLines());
3133 : }
3134 : } else {
3135 69 : xml.tag("durations", item->genDurations());
3136 69 : xml.tag("durationFontName", item->durationFontName()); // write font names anyway for backward compatibility
3137 69 : xml.tag("durationFontSize", item->durationFontSize());
3138 69 : xml.tag("durationFontY", item->durationFontUserY());
3139 69 : if (item->symRepeat() != TablatureSymbolRepeat::NEVER) {
3140 1 : xml.tag("symbolRepeat", int(item->symRepeat()));
3141 : }
3142 69 : xml.tag("fretUseTextStyle", item->fretUseTextStyle());
3143 69 : if (item->fretUseTextStyle()) {
3144 68 : xml.tag("fretTextStyle", TConv::toXml(item->fretTextStyle()));
3145 : } else {
3146 1 : xml.tag("fretPresetIdx", item->fretPresetIdx());
3147 1 : xml.tag("fretFontSize", item->fretFontSize());
3148 1 : xml.tag("fretFontY", item->fretFontUserY());
3149 : }
3150 69 : xml.tag("linesThrough", item->linesThrough());
3151 69 : xml.tag("minimStyle", int(item->minimStyle()));
3152 69 : xml.tag("onLines", item->onLines());
3153 69 : xml.tag("showRests", item->showRests());
3154 69 : xml.tag("stemsDown", item->stemsDown());
3155 69 : xml.tag("stemsThrough", item->stemThrough());
3156 69 : xml.tag("upsideDown", item->upsideDown());
3157 69 : xml.tag("showTabFingering", item->showTabFingering(), false);
3158 69 : xml.tag("useNumbers", item->useNumbers());
3159 : // only output "showBackTied" if different from !"stemless"
3160 : // to match the behaviour in 2.0.2 scores (or older)
3161 69 : if (item->showBackTied() != !item->stemless()) {
3162 1 : xml.tag("showBackTied", item->showBackTied());
3163 : }
3164 : }
3165 1978 : xml.endElement();
3166 5934 : }
3167 :
3168 0 : void TWrite::write(const StaffTypeChange* item, XmlWriter& xml, WriteContext& ctx)
3169 : {
3170 0 : xml.startElement(item);
3171 0 : if (item->staffType()) {
3172 0 : write(item->staffType(), xml, ctx);
3173 : }
3174 0 : writeItemProperties(item, xml, ctx);
3175 0 : xml.endElement();
3176 0 : }
3177 :
3178 3 : void TWrite::write(const Stem* item, XmlWriter& xml, WriteContext& ctx)
3179 : {
3180 3 : xml.startElement(item);
3181 3 : writeItemProperties(item, xml, ctx);
3182 3 : writeProperty(item, xml, Pid::USER_LEN);
3183 3 : writeProperty(item, xml, Pid::LINE_WIDTH);
3184 3 : xml.endElement();
3185 3 : }
3186 :
3187 0 : void TWrite::write(const StemSlash* item, XmlWriter& xml, WriteContext& ctx)
3188 : {
3189 0 : xml.startElement(item);
3190 0 : writeItemProperties(item, xml, ctx);
3191 0 : xml.endElement();
3192 0 : }
3193 :
3194 73 : void TWrite::write(const Sticking* item, XmlWriter& xml, WriteContext& ctx)
3195 : {
3196 73 : if (!ctx.canWrite(item)) {
3197 0 : return;
3198 : }
3199 73 : xml.startElement(item);
3200 73 : writeProperties(toTextBase(item), xml, ctx, true);
3201 73 : xml.endElement();
3202 : }
3203 :
3204 443 : void TWrite::write(const StringData* item, XmlWriter& xml)
3205 : {
3206 443 : xml.startElement("StringData");
3207 443 : xml.tag("frets", item->frets());
3208 3045 : for (const instrString& strg : item->stringList()) {
3209 2602 : XmlWriter::Attributes attrs;
3210 :
3211 2602 : if (strg.open) {
3212 0 : attrs.push_back({ "open", "1" });
3213 : }
3214 :
3215 2602 : if (strg.useFlat) {
3216 16 : attrs.push_back({ "useFlat", "1" });
3217 : }
3218 :
3219 2602 : xml.tag("string", attrs, strg.pitch);
3220 2602 : }
3221 443 : xml.endElement();
3222 443 : }
3223 :
3224 19 : void TWrite::write(const StringTunings* item, XmlWriter& xml, WriteContext& ctx)
3225 : {
3226 19 : xml.startElement(item);
3227 :
3228 19 : writeProperty(item, xml, Pid::STRINGTUNINGS_PRESET);
3229 :
3230 19 : xml.tag("visibleStrings", TConv::toXml(item->visibleStrings()));
3231 :
3232 19 : if (!item->stringData()->isNull()) {
3233 19 : write(item->stringData(), xml);
3234 : }
3235 :
3236 19 : writeProperties(static_cast<const StaffTextBase*>(item), xml, ctx, true);
3237 19 : xml.endElement();
3238 19 : }
3239 :
3240 11 : void TWrite::write(const Symbol* item, XmlWriter& xml, WriteContext& ctx)
3241 : {
3242 11 : xml.startElement(item);
3243 11 : xml.tag("name", SymNames::nameForSymId(item->sym()));
3244 11 : if (item->scoreFont()) {
3245 0 : xml.tag("font", item->scoreFont()->name());
3246 0 : writeProperty(item, xml, Pid::SYMBOLS_SIZE);
3247 0 : writeProperty(item, xml, Pid::SYMBOL_ANGLE);
3248 : }
3249 11 : writeProperties(static_cast<const BSymbol*>(item), xml, ctx);
3250 11 : xml.endElement();
3251 11 : }
3252 :
3253 0 : void TWrite::write(const FSymbol* item, XmlWriter& xml, WriteContext& ctx)
3254 : {
3255 0 : xml.startElement(item);
3256 0 : xml.tag("font", item->font().family().id());
3257 0 : xml.tag("fontsize", item->font().pointSizeF());
3258 0 : xml.tag("code", item->code());
3259 0 : writeProperties(static_cast<const BSymbol*>(item), xml, ctx);
3260 0 : xml.endElement();
3261 0 : }
3262 :
3263 0 : void TWrite::write(const System* item, XmlWriter& xml, WriteContext& ctx)
3264 : {
3265 0 : xml.startElement(item);
3266 0 : if (item->systemDividerLeft() && item->systemDividerLeft()->isUserModified()) {
3267 0 : write(item->systemDividerLeft(), xml, ctx);
3268 : }
3269 0 : if (item->systemDividerRight() && item->systemDividerRight()->isUserModified()) {
3270 0 : write(item->systemDividerRight(), xml, ctx);
3271 : }
3272 0 : xml.endElement();
3273 0 : }
3274 :
3275 2 : void TWrite::write(const SystemDivider* item, XmlWriter& xml, WriteContext& ctx)
3276 : {
3277 8 : xml.startElement(item, { { "type", (item->dividerType() == SystemDividerType::LEFT ? "left" : "right") } });
3278 :
3279 2 : writeProperty(item, xml, Pid::SCORE_FONT);
3280 2 : writeProperty(item, xml, Pid::SYMBOLS_SIZE);
3281 2 : writeProperty(item, xml, Pid::SYMBOL_ANGLE);
3282 :
3283 2 : writeProperties(static_cast<const BSymbol*>(item), xml, ctx);
3284 2 : xml.endElement();
3285 6 : }
3286 :
3287 26 : void TWrite::write(const SystemText* item, XmlWriter& xml, WriteContext& ctx)
3288 : {
3289 26 : write(static_cast<const StaffTextBase*>(item), xml, ctx);
3290 26 : }
3291 :
3292 0 : void TWrite::write(const SoundFlag* item, XmlWriter& xml, WriteContext&)
3293 : {
3294 0 : if (item->soundPresets().empty() && item->playingTechnique().empty()) {
3295 0 : return;
3296 : }
3297 :
3298 0 : xml.startElement(item);
3299 :
3300 0 : writeProperty(item, xml, Pid::PLAY);
3301 :
3302 0 : if (!item->soundPresets().empty()) {
3303 0 : xml.tag("presets", item->soundPresets().join(u","));
3304 : }
3305 :
3306 0 : if (!item->playingTechnique().empty()) {
3307 0 : xml.tag("playingTechnique", item->playingTechnique());
3308 : }
3309 :
3310 0 : writeProperty(item, xml, Pid::APPLY_TO_ALL_STAVES);
3311 :
3312 0 : xml.endElement();
3313 : }
3314 :
3315 3 : void TWrite::write(const Tapping* item, XmlWriter& xml, WriteContext& ctx)
3316 : {
3317 3 : xml.startElement(item);
3318 :
3319 3 : xml.tag("hand", TConv::toXml(item->hand()));
3320 :
3321 3 : if (item->halfSlurAbove() && item->halfSlurAbove()->isUserModified()) {
3322 0 : write(item->halfSlurAbove(), xml, ctx);
3323 : }
3324 3 : if (item->halfSlurBelow() && item->halfSlurBelow()->isUserModified()) {
3325 0 : write(item->halfSlurBelow(), xml, ctx);
3326 : }
3327 :
3328 3 : writeProperties(toArticulation(item), xml, ctx);
3329 3 : xml.endElement();
3330 3 : }
3331 :
3332 0 : void TWrite::write(const TappingHalfSlur* item, XmlWriter& xml, WriteContext& ctx)
3333 : {
3334 0 : xml.startElement(item);
3335 :
3336 0 : xml.tag("isHalfSlurAbove", item->isHalfSlurAbove());
3337 0 : writeProperties(static_cast<const SlurTie*>(item), xml, ctx);
3338 :
3339 0 : xml.endElement();
3340 0 : }
3341 :
3342 565 : void TWrite::write(const TempoText* item, XmlWriter& xml, WriteContext& ctx)
3343 : {
3344 565 : xml.startElement(item);
3345 565 : writeProperty(item, xml, Pid::PLAY);
3346 565 : xml.tag("tempo", TConv::toXml(item->tempo(), Constants::TEMPO_PRECISION));
3347 565 : if (item->followText()) {
3348 86 : xml.tag("followText", item->followText());
3349 : }
3350 565 : switch (item->tempoTextType()) {
3351 565 : case TempoTextType::NORMAL:
3352 565 : break;
3353 0 : case TempoTextType::A_TEMPO:
3354 0 : xml.tag("type", "aTempo");
3355 0 : break;
3356 0 : case TempoTextType::TEMPO_PRIMO:
3357 0 : xml.tag("type", "tempoPrimo");
3358 0 : break;
3359 : }
3360 565 : writeProperties(toTextBase(item), xml, ctx, true);
3361 565 : xml.endElement();
3362 565 : }
3363 :
3364 1021 : void TWrite::write(const Text* item, XmlWriter& xml, WriteContext& ctx)
3365 : {
3366 1021 : if (!ctx.canWrite(item)) {
3367 0 : return;
3368 : }
3369 1021 : xml.startElement(item);
3370 1021 : writeProperties(toTextBase(item), xml, ctx, true);
3371 1021 : xml.endElement();
3372 : }
3373 :
3374 45 : void TWrite::write(const TextLine* item, XmlWriter& xml, WriteContext& ctx)
3375 : {
3376 45 : if (!ctx.canWrite(item)) {
3377 0 : return;
3378 : }
3379 45 : if (item->systemFlag()) {
3380 0 : xml.startElement(item, { { "system", "1" } });
3381 : } else {
3382 45 : xml.startElement(item);
3383 : }
3384 45 : writeProperties(static_cast<const TextLineBase*>(item), xml, ctx);
3385 45 : xml.endElement();
3386 0 : }
3387 :
3388 598 : void TWrite::write(const Tie* item, XmlWriter& xml, WriteContext& ctx)
3389 : {
3390 598 : xml.startElement(item);
3391 598 : writeProperty(item, xml, Pid::TIE_PLACEMENT);
3392 598 : writeProperties(static_cast<const SlurTie*>(item), xml, ctx);
3393 598 : xml.endElement();
3394 598 : }
3395 :
3396 1988 : void TWrite::write(const TimeSig* item, XmlWriter& xml, WriteContext& ctx)
3397 : {
3398 1988 : xml.startElement(item);
3399 1988 : writeProperty(item, xml, Pid::TIMESIG_TYPE);
3400 1988 : writeItemProperties(item, xml, ctx);
3401 :
3402 1988 : xml.tag("sigN", item->numerator());
3403 1988 : xml.tag("sigD", item->denominator());
3404 1988 : if (item->stretch() != Fraction(1, 1)) {
3405 1 : xml.tag("stretchN", item->stretch().numerator());
3406 1 : xml.tag("stretchD", item->stretch().denominator());
3407 : }
3408 1988 : writeProperty(item, xml, Pid::NUMERATOR_STRING);
3409 1988 : writeProperty(item, xml, Pid::DENOMINATOR_STRING);
3410 1988 : if (!item->groups().empty()) {
3411 0 : write(&item->groups(), xml, ctx);
3412 : }
3413 1988 : writeProperty(item, xml, Pid::SHOW_COURTESY);
3414 1988 : writeProperty(item, xml, Pid::IS_COURTESY);
3415 1988 : writeProperty(item, xml, Pid::SCALE);
3416 :
3417 1988 : xml.endElement();
3418 1988 : }
3419 :
3420 112 : void TWrite::write(const TremoloSingleChord* item, XmlWriter& xml, WriteContext& ctx)
3421 : {
3422 112 : if (!ctx.canWrite(item)) {
3423 2 : return;
3424 : }
3425 :
3426 110 : xml.startElement(item);
3427 :
3428 110 : writeProperty(item, xml, Pid::TREMOLO_TYPE);
3429 110 : writeProperty(item, xml, Pid::PLAY);
3430 110 : writeItemProperties(item, xml, ctx);
3431 110 : xml.endElement();
3432 : }
3433 :
3434 52 : void TWrite::write(const TremoloTwoChord* item, XmlWriter& xml, WriteContext& ctx)
3435 : {
3436 52 : if (!ctx.canWrite(item)) {
3437 1 : return;
3438 : }
3439 :
3440 51 : xml.startElement(item);
3441 :
3442 51 : writeProperty(item, xml, Pid::TREMOLO_TYPE);
3443 51 : writeProperty(item, xml, Pid::TREMOLO_STYLE);
3444 51 : writeProperty(item, xml, Pid::PLAY);
3445 51 : writeItemProperties(item, xml, ctx);
3446 :
3447 : // write manual adjustments to file
3448 51 : int idx = item->directionIdx();
3449 51 : if (item->userModified()) {
3450 0 : double _spatium = item->spatium();
3451 :
3452 0 : xml.startElement("Fragment");
3453 0 : xml.tag("y1", item->beamFragment().py1[idx] / _spatium);
3454 0 : xml.tag("y2", item->beamFragment().py2[idx] / _spatium);
3455 0 : xml.endElement();
3456 : }
3457 :
3458 : // this info is used for regression testing
3459 : // l1/l2 is the beam position of the layout engine
3460 51 : if (MScore::testMode) {
3461 51 : double spatium8 = item->spatium() * .125;
3462 51 : xml.tag("l1", int(lrint(item->beamFragment().py1[idx] / spatium8)));
3463 51 : xml.tag("l2", int(lrint(item->beamFragment().py2[idx] / spatium8)));
3464 : }
3465 51 : xml.endElement();
3466 : }
3467 :
3468 4 : void TWrite::write(const TremoloBar* item, XmlWriter& xml, WriteContext& ctx)
3469 : {
3470 4 : xml.startElement(item);
3471 4 : writeProperty(item, xml, Pid::MAG);
3472 4 : writeProperty(item, xml, Pid::LINE_WIDTH);
3473 4 : writeProperty(item, xml, Pid::PLAY);
3474 16 : for (const PitchValue& v : item->points()) {
3475 60 : xml.tag("point", { { "time", v.time }, { "pitch", v.pitch }, { "vibrato", v.vibrato } });
3476 : }
3477 4 : writeItemProperties(item, xml, ctx);
3478 4 : xml.endElement();
3479 16 : }
3480 :
3481 18 : void TWrite::write(const Trill* item, XmlWriter& xml, WriteContext& ctx)
3482 : {
3483 18 : if (!ctx.canWrite(item)) {
3484 0 : return;
3485 : }
3486 18 : xml.startElement(item);
3487 18 : xml.tag("subtype", TConv::toXml(item->trillType()));
3488 :
3489 18 : if (item->propertyFlags(Pid::ORNAMENT_STYLE) == PropertyFlags::NOSTYLE) {
3490 18 : writeProperty(item, xml, Pid::ORNAMENT_STYLE);
3491 : }
3492 18 : writeProperties(static_cast<const SLine*>(item), xml, ctx);
3493 :
3494 18 : if (item->ornament()) {
3495 16 : write(item->ornament(), xml, ctx);
3496 : }
3497 18 : xml.endElement();
3498 : }
3499 :
3500 601 : void TWrite::write(const Tuplet* item, XmlWriter& xml, WriteContext& ctx)
3501 : {
3502 601 : xml.startElement(item);
3503 601 : writeItemProperties(item, xml, ctx);
3504 :
3505 601 : writeProperty(item, xml, Pid::NORMAL_NOTES);
3506 601 : writeProperty(item, xml, Pid::ACTUAL_NOTES);
3507 601 : writeProperty(item, xml, Pid::P1);
3508 601 : writeProperty(item, xml, Pid::P2);
3509 :
3510 601 : xml.tag("baseNote", TConv::toXml(item->baseLen().type()));
3511 601 : if (int dots = item->baseLen().dots()) {
3512 1 : xml.tag("baseDots", dots);
3513 : }
3514 :
3515 601 : if (item->number()) {
3516 591 : xml.startElement("Number", item->number());
3517 591 : writeProperty(item->number(), xml, Pid::TEXT_STYLE);
3518 591 : writeProperty(item->number(), xml, Pid::TEXT);
3519 591 : xml.endElement();
3520 : }
3521 :
3522 601 : writeStyledProperties(item, xml);
3523 :
3524 601 : xml.endElement();
3525 601 : }
3526 :
3527 26 : void TWrite::write(const Vibrato* item, XmlWriter& xml, WriteContext& ctx)
3528 : {
3529 26 : if (!ctx.canWrite(item)) {
3530 0 : return;
3531 : }
3532 26 : xml.startElement(item);
3533 26 : xml.tag("subtype", TConv::toXml(item->vibratoType()));
3534 26 : writeProperties(static_cast<const SLine*>(item), xml, ctx);
3535 26 : xml.endElement();
3536 : }
3537 :
3538 55 : void TWrite::write(const Volta* item, XmlWriter& xml, WriteContext& ctx)
3539 : {
3540 55 : xml.startElement(item);
3541 55 : writeProperties(static_cast<const TextLineBase*>(item), xml, ctx);
3542 55 : xml.tag("endings", TConv::toXml(item->endings()));
3543 55 : xml.endElement();
3544 55 : }
3545 :
3546 32 : void TWrite::write(const WhammyBar* item, XmlWriter& xml, WriteContext& ctx)
3547 : {
3548 32 : if (!ctx.canWrite(item)) {
3549 0 : return;
3550 : }
3551 32 : xml.startElement(item);
3552 32 : writeProperties(static_cast<const TextLineBase*>(item), xml, ctx);
3553 32 : xml.endElement();
3554 : }
3555 :
3556 : //---------------------------------------------------------
3557 : // writeVoiceMove
3558 : // write <move> and starting <voice> tags to denote
3559 : // change in position.
3560 : // Returns true if <voice> tag was written.
3561 : //---------------------------------------------------------
3562 :
3563 17872 : static bool writeVoiceMove(XmlWriter& xml, WriteContext& ctx, Segment* seg, const Fraction& startTick, track_idx_t track,
3564 : int* lastTrackWrittenPtr)
3565 : {
3566 17872 : bool voiceTagWritten = false;
3567 17872 : int& lastTrackWritten = *lastTrackWrittenPtr;
3568 17872 : if ((lastTrackWritten < static_cast<int>(track)) && !ctx.clipboardmode()) {
3569 17103 : while (lastTrackWritten < (static_cast < int > (track) - 1)) {
3570 45 : xml.tag("voice");
3571 45 : ++lastTrackWritten;
3572 : }
3573 17058 : xml.startElement("voice");
3574 17058 : ctx.setCurTick(startTick);
3575 17058 : ctx.setCurTrack(track);
3576 17058 : ++lastTrackWritten;
3577 17058 : voiceTagWritten = true;
3578 : }
3579 :
3580 17872 : if ((ctx.curTick() != seg->tick()) || (track != ctx.curTrack())) {
3581 248 : Location curr = Location::absolute();
3582 248 : Location dest = Location::absolute();
3583 248 : curr.setFrac(ctx.curTick());
3584 248 : dest.setFrac(seg->tick());
3585 248 : curr.setTrack(static_cast<int>(ctx.curTrack()));
3586 248 : dest.setTrack(static_cast<int>(track));
3587 :
3588 248 : dest.toRelative(curr);
3589 248 : dest.setIsTimeTick(seg->isTimeTickType());
3590 248 : TWrite::write(&dest, xml, ctx);
3591 :
3592 248 : ctx.setCurTick(seg->tick());
3593 248 : ctx.setCurTrack(track);
3594 : }
3595 :
3596 17872 : return voiceTagWritten;
3597 : }
3598 :
3599 0 : static void writeTimeSig(Score* score, const Fraction& tick, XmlWriter& xml, WriteContext& ctx)
3600 : {
3601 0 : Fraction tsf = score->sigmap()->timesig(tick).nominal();
3602 0 : TimeSig* ts = Factory::createTimeSig(score->dummy());
3603 0 : ts->setSig(tsf);
3604 0 : TWrite::write(ts, xml, ctx);
3605 0 : ts->masterScore()->eidRegister()->removeItem(ts);
3606 0 : delete ts;
3607 0 : }
3608 :
3609 : //---------------------------------------------------------
3610 : // writeSegments
3611 : // ls - write upto this segment (excluding)
3612 : // can be zero
3613 : //---------------------------------------------------------
3614 84 : void TWrite::writeSegments(XmlWriter& xml, WriteContext& ctx, track_idx_t strack, track_idx_t etrack,
3615 : Segment* sseg, Segment* eseg, bool writeSystemElements, bool forceTimeSig)
3616 : {
3617 84 : bool clip = ctx.clipboardmode();
3618 :
3619 : // in clipboard mode, ls might be in an mmrest
3620 : // since we are traversing regular measures,
3621 : // force them out of mmRest
3622 84 : if (clip) {
3623 84 : Measure* lm = eseg ? eseg->measure() : 0;
3624 84 : Measure* fm = sseg ? sseg->measure() : 0;
3625 84 : if (lm && lm->isMMRest()) {
3626 0 : lm = lm->mmRestLast();
3627 0 : if (lm) {
3628 0 : eseg = lm->nextMeasure() ? lm->nextMeasure()->first() : nullptr;
3629 : } else {
3630 0 : LOGD("writeSegments: no measure for end segment in mmrest");
3631 : }
3632 : }
3633 84 : if (fm && fm->isMMRest()) {
3634 0 : fm = fm->mmRestFirst();
3635 0 : if (fm) {
3636 0 : sseg = fm->first(SegmentType::ChordRest);
3637 : }
3638 : }
3639 : }
3640 :
3641 84 : std::vector<Segment*> segments;
3642 619 : for (Segment* segment = sseg; segment && segment != eseg; segment = segment->next1()) {
3643 535 : segments.push_back(segment);
3644 : }
3645 :
3646 84 : writeSegments(xml, ctx, strack, etrack, segments, writeSystemElements, forceTimeSig);
3647 84 : }
3648 :
3649 16606 : void TWrite::writeSegments(XmlWriter& xml, WriteContext& ctx, track_idx_t strack, track_idx_t etrack, const std::vector<Segment*>& segments,
3650 : bool writeSystemElements, bool forceTimeSig)
3651 : {
3652 16606 : if (segments.empty()) {
3653 0 : return;
3654 : }
3655 :
3656 16606 : Segment* sseg = segments.front();
3657 16606 : Score* score = sseg->score();
3658 16606 : Fraction startTick = ctx.curTick();
3659 :
3660 16606 : int lastTrackWritten = static_cast<int>(strack - 1); // for counting necessary <voice> tags
3661 83030 : for (track_idx_t track = strack; track < etrack; ++track) {
3662 66424 : if (!ctx.canWriteVoice(track)) {
3663 5 : if (forceTimeSig && track2voice(track) == 0) {
3664 0 : bool voiceTagWritten = writeVoiceMove(xml, ctx, sseg, startTick, track, &lastTrackWritten);
3665 0 : writeTimeSig(score, startTick, xml, ctx);
3666 0 : if (voiceTagWritten) {
3667 0 : xml.endElement(); // </voice>
3668 : }
3669 : }
3670 :
3671 5 : continue;
3672 5 : }
3673 :
3674 66419 : bool voiceTagWritten = false;
3675 66419 : bool timeSigWritten = false; // for forceTimeSig
3676 66419 : bool crWritten = false; // for forceTimeSig
3677 66419 : bool keySigWritten = false; // for forceTimeSig
3678 :
3679 313415 : for (Segment* segment : segments) {
3680 246996 : if (!segment->enabled()) {
3681 1728 : continue;
3682 : }
3683 245268 : if (track == 0) {
3684 45043 : segment->setWritten(false);
3685 : }
3686 245268 : EngravingItem* e = segment->element(track);
3687 :
3688 : //
3689 : // special case: - barline span > 1
3690 : // - part (excerpt) staff starts after
3691 : // barline element
3692 245268 : bool needMove = (segment->tick() != ctx.curTick() || (static_cast<int>(track) > lastTrackWritten));
3693 245268 : if ((segment->isEndBarLineType()) && !e && writeSystemElements && ((track % VOICES) == 0)) {
3694 : // search barline:
3695 55 : for (int idx = static_cast<int>(track - VOICES); idx >= 0; idx -= static_cast<int>(VOICES)) {
3696 0 : if (segment->element(idx)) {
3697 0 : int oDiff = ctx.trackDiff();
3698 0 : ctx.setTrackDiff(idx); // staffIdx should be zero
3699 0 : TWrite::writeItem(segment->element(idx), xml, ctx);
3700 0 : ctx.setTrackDiff(oDiff);
3701 0 : break;
3702 : }
3703 : }
3704 : }
3705 259204 : for (EngravingItem* e1 : segment->annotations()) {
3706 13936 : if (e1->generated()) {
3707 0 : continue;
3708 : }
3709 13936 : bool writeSystem = writeSystemElements;
3710 13936 : if (!writeSystem) {
3711 3632 : ElementType et = e1->type();
3712 3632 : if ((et == ElementType::REHEARSAL_MARK)
3713 3484 : || (et == ElementType::SYSTEM_TEXT)
3714 3452 : || (et == ElementType::TRIPLET_FEEL)
3715 3452 : || (et == ElementType::PLAYTECH_ANNOTATION)
3716 3444 : || (et == ElementType::CAPO)
3717 3436 : || (et == ElementType::STRING_TUNINGS)
3718 3380 : || (et == ElementType::JUMP)
3719 3380 : || (et == ElementType::MARKER)
3720 3380 : || (et == ElementType::TEMPO_TEXT)
3721 2420 : || (et == ElementType::VOLTA)
3722 2420 : || (et == ElementType::GRADUAL_TEMPO_CHANGE)
3723 2420 : || (et == ElementType::PLAY_COUNT_TEXT)) {
3724 1228 : writeSystem = (e1->track() == track); // always show these on appropriate staves
3725 : }
3726 : }
3727 13936 : if (e1->track() != track || (e1->systemFlag() && !writeSystem)) {
3728 11295 : continue;
3729 : }
3730 2641 : if (needMove) {
3731 1146 : voiceTagWritten |= writeVoiceMove(xml, ctx, segment, startTick, track, &lastTrackWritten);
3732 1146 : needMove = false;
3733 : }
3734 2641 : TWrite::writeItem(e1, xml, ctx);
3735 : }
3736 :
3737 245268 : if (!e || !ctx.canWrite(e)) {
3738 184350 : continue;
3739 : }
3740 60918 : if (e->generated()) {
3741 21750 : continue;
3742 : }
3743 0 : if (forceTimeSig && track2voice(track) == 0 && segment->segmentType() == SegmentType::ChordRest && !timeSigWritten
3744 39168 : && !crWritten) {
3745 : // Ensure that <voice> tag is open
3746 0 : voiceTagWritten |= writeVoiceMove(xml, ctx, segment, startTick, track, &lastTrackWritten);
3747 : // we will miss a key sig!
3748 0 : if (!keySigWritten) {
3749 0 : Key ck = score->staff(track2staff(track))->concertKey(segment->tick());
3750 0 : Key tk = score->staff(track2staff(track))->key(segment->tick());
3751 0 : KeySig* ks = Factory::createKeySig(score->dummy());
3752 0 : ks->setKey(ck, tk);
3753 0 : TWrite::write(ks, xml, ctx);
3754 0 : ks->masterScore()->eidRegister()->removeItem(ks);
3755 0 : delete ks;
3756 0 : keySigWritten = true;
3757 : }
3758 : // we will miss a time sig!
3759 0 : writeTimeSig(score, segment->tick(), xml, ctx);
3760 0 : timeSigWritten = true;
3761 : }
3762 39168 : if (needMove) {
3763 16726 : voiceTagWritten |= writeVoiceMove(xml, ctx, segment, startTick, track, &lastTrackWritten);
3764 : // needMove = false; //! NOTE Not necessary, because needMove is currently never read again.
3765 : }
3766 39168 : if (e->isChordRest()) {
3767 33303 : ChordRest* cr = toChordRest(e);
3768 33303 : writeTupletStart(cr, xml, ctx);
3769 : }
3770 39168 : TWrite::writeItem(e, xml, ctx);
3771 :
3772 39168 : if (e->isChordRest()) {
3773 33303 : ChordRest* cr = toChordRest(e);
3774 33303 : writeTupletEnd(cr, xml, ctx);
3775 : }
3776 :
3777 39168 : if (!(e->isRest() && toRest(e)->isGap())) {
3778 39118 : TWrite::write(segment, xml, ctx); // write only once
3779 : }
3780 39168 : if (forceTimeSig) {
3781 0 : if (segment->segmentType() == SegmentType::KeySig) {
3782 0 : keySigWritten = true;
3783 : }
3784 0 : if (segment->segmentType() == SegmentType::TimeSig) {
3785 0 : timeSigWritten = true;
3786 : }
3787 0 : if (segment->segmentType() == SegmentType::ChordRest) {
3788 0 : crWritten = true;
3789 : }
3790 : }
3791 : }
3792 :
3793 66419 : if (voiceTagWritten) {
3794 17058 : xml.endElement(); // </voice>
3795 : }
3796 : }
3797 : }
|