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 :
23 : #include "read206.h"
24 :
25 : #include <cmath>
26 :
27 : #include "global/defer.h"
28 :
29 : #include "compat/pageformat.h"
30 :
31 : #include "engravingerrors.h"
32 :
33 : #include "iengravingfont.h"
34 :
35 : #include "rw/compat/compatutils.h"
36 :
37 : #include "style/style.h"
38 : #include "style/textstyle.h"
39 :
40 : #include "types/typesconv.h"
41 : #include "types/symnames.h"
42 :
43 : #include "dom/accidental.h"
44 : #include "dom/ambitus.h"
45 : #include "dom/arpeggio.h"
46 : #include "dom/articulation.h"
47 : #include "dom/barline.h"
48 : #include "dom/beam.h"
49 : #include "dom/bend.h"
50 : #include "dom/box.h"
51 : #include "dom/breath.h"
52 : #include "dom/chord.h"
53 : #include "dom/chordline.h"
54 : #include "dom/drumset.h"
55 : #include "dom/dynamic.h"
56 : #include "dom/excerpt.h"
57 : #include "dom/factory.h"
58 : #include "dom/fermata.h"
59 : #include "dom/fingering.h"
60 : #include "dom/glissando.h"
61 : #include "dom/hairpin.h"
62 : #include "dom/hook.h"
63 : #include "dom/image.h"
64 : #include "dom/keysig.h"
65 : #include "dom/linkedobjects.h"
66 : #include "dom/lyrics.h"
67 : #include "dom/marker.h"
68 : #include "dom/masterscore.h"
69 : #include "dom/measure.h"
70 : #include "dom/measurenumber.h"
71 : #include "dom/measurerepeat.h"
72 : #include "dom/mmrest.h"
73 : #include "dom/note.h"
74 : #include "dom/noteline.h"
75 : #include "dom/ornament.h"
76 : #include "dom/ottava.h"
77 : #include "dom/page.h"
78 : #include "dom/part.h"
79 : #include "dom/pedal.h"
80 : #include "dom/rehearsalmark.h"
81 : #include "dom/rest.h"
82 : #include "dom/score.h"
83 : #include "dom/sig.h"
84 : #include "dom/slur.h"
85 : #include "dom/spacer.h"
86 : #include "dom/staff.h"
87 : #include "dom/staff.h"
88 : #include "dom/stafftext.h"
89 : #include "dom/stem.h"
90 : #include "dom/stemslash.h"
91 : #include "dom/system.h"
92 : #include "dom/systemdivider.h"
93 : #include "dom/systemtext.h"
94 : #include "dom/tempotext.h"
95 : #include "dom/textline.h"
96 : #include "dom/tie.h"
97 : #include "dom/timesig.h"
98 : #include "dom/trill.h"
99 : #include "dom/tremolotwochord.h"
100 : #include "dom/tremolosinglechord.h"
101 : #include "dom/tuplet.h"
102 : #include "dom/utils.h"
103 : #include "dom/volta.h"
104 :
105 : #include "../../editing/editstaffbrackets.h"
106 : #include "../../editing/transpose.h"
107 :
108 : #include "../compat/readchordlisthook.h"
109 : #include "../compat/readstyle.h"
110 :
111 : #include "engraving/rw/read114/read114.h"
112 : #include "engraving/rw/read400/tread.h"
113 :
114 : #include "log.h"
115 :
116 : using namespace mu;
117 : using namespace muse;
118 : using namespace mu::engraving;
119 : using namespace mu::engraving::rw;
120 : using namespace mu::engraving::read400;
121 : using namespace mu::engraving::read206;
122 : using namespace mu::engraving::compat;
123 :
124 : static void readText206(XmlReader& e, ReadContext& ctx, TextBase* t, EngravingItem* be);
125 :
126 26 : static int readSigEvent(SigEvent* sigEvent, XmlReader& e, int fileDivision)
127 : {
128 26 : int tick = e.intAttribute("tick", 0);
129 26 : tick = tick * Constants::DIVISION / fileDivision;
130 :
131 26 : int numerator = 1;
132 26 : int denominator = 1;
133 26 : int denominator2 = -1;
134 26 : int numerator2 = -1;
135 :
136 78 : while (e.readNextStartElement()) {
137 52 : const AsciiStringView tag(e.name());
138 52 : if (tag == "nom") {
139 26 : numerator = e.readInt();
140 26 : } else if (tag == "denom") {
141 26 : denominator = e.readInt();
142 0 : } else if (tag == "nom2") {
143 0 : numerator2 = e.readInt();
144 0 : } else if (tag == "denom2") {
145 0 : denominator2 = e.readInt();
146 : } else {
147 0 : e.unknown();
148 : }
149 : }
150 26 : if ((numerator2 == -1) || (denominator2 == -1)) {
151 26 : numerator2 = numerator;
152 26 : denominator2 = denominator;
153 : }
154 :
155 26 : sigEvent->setTimesig(TimeSigFrac(numerator, denominator));
156 26 : sigEvent->setNominal(TimeSigFrac(numerator2, denominator2));
157 26 : return tick;
158 : }
159 :
160 26 : void Read206::readTimeSigMap(TimeSigMap* map, XmlReader& e, read400::ReadContext& ctx)
161 : {
162 52 : while (e.readNextStartElement()) {
163 26 : const AsciiStringView tag(e.name());
164 26 : if (tag == "sig") {
165 26 : SigEvent t;
166 26 : int tick = readSigEvent(&t, e, ctx.fileDivision());
167 26 : (*map)[tick] = t;
168 : } else {
169 0 : e.unknown();
170 : }
171 : }
172 26 : map->normalize();
173 26 : }
174 :
175 : //---------------------------------------------------------
176 : // excessTextStyles206
177 : // The first map has the name of the style as the string
178 : // The second map has the mapping of each Sid that the style identifies
179 : // to the default value for that sid.
180 : //---------------------------------------------------------
181 :
182 : static std::map<String, std::map<Sid, PropertyValue> > excessTextStyles206;
183 :
184 107 : void Read206::readTextStyle206(MStyle* style, XmlReader& e, ReadContext& ctx, std::map<String, std::map<Sid, PropertyValue> >& excessStyles)
185 : {
186 107 : String family = u"FreeSerif";
187 107 : double size = 10;
188 107 : bool sizeIsSpatiumDependent = false;
189 107 : FontStyle fontStyle = FontStyle::Normal;
190 107 : Align align = { AlignH::LEFT, AlignV::TOP };
191 107 : PointF offset;
192 107 : OffsetType offsetType = OffsetType::SPATIUM;
193 :
194 107 : FrameType frameType = FrameType::NO_FRAME;
195 107 : Spatium paddingWidth(0.0);
196 107 : Spatium frameWidth(0.0);
197 107 : Color foregroundColor = Color::BLACK;
198 107 : Color backgroundColor = Color::transparent;
199 :
200 107 : PlacementV placement = PlacementV::ABOVE;
201 107 : bool placementValid = false;
202 :
203 107 : String name = e.attribute("name");
204 107 : Color frameColor = Color::BLACK;
205 :
206 107 : bool systemFlag = false;
207 107 : double lineWidth = -1.0;
208 :
209 942 : while (e.readNextStartElement()) {
210 835 : const AsciiStringView tag(e.name());
211 :
212 835 : if (tag == "name") {
213 106 : name = e.readText();
214 729 : } else if (tag == "family") {
215 107 : family = e.readText();
216 622 : } else if (tag == "size") {
217 107 : size = e.readDouble();
218 515 : } else if (tag == "bold") {
219 13 : if (e.readInt()) {
220 13 : fontStyle = fontStyle + FontStyle::Bold;
221 : }
222 502 : } else if (tag == "italic") {
223 16 : if (e.readInt()) {
224 16 : fontStyle = fontStyle + FontStyle::Italic;
225 : }
226 486 : } else if (tag == "underline") {
227 0 : if (e.readInt()) {
228 0 : fontStyle = fontStyle + FontStyle::Underline;
229 : }
230 : #if 0 // should not happen, but won't harm either
231 : } else if (tag == "strike") {
232 : if (e.readInt()) {
233 : fontStyle = fontStyle + FontStyle::Strike;
234 : }
235 : #endif
236 486 : } else if (tag == "align") { // obsolete
237 0 : e.skipCurrentElement();
238 486 : } else if (tag == "anchor") { // obsolete
239 0 : e.skipCurrentElement();
240 486 : } else if (tag == "halign") {
241 107 : align.horizontal = TConv::fromXml(e.readAsciiText(), AlignH::LEFT);
242 379 : } else if (tag == "valign") {
243 107 : align.vertical = TConv::fromXml(e.readAsciiText(), AlignV::TOP);
244 272 : } else if (tag == "xoffset") {
245 41 : double xo = e.readDouble();
246 41 : if (offsetType == OffsetType::ABS) {
247 0 : xo /= INCH;
248 : }
249 41 : offset.setX(xo);
250 231 : } else if (tag == "yoffset") {
251 41 : double yo = e.readDouble();
252 41 : if (offsetType == OffsetType::ABS) {
253 0 : yo /= INCH;
254 : }
255 41 : offset.setY(yo);
256 190 : } else if (tag == "rxoffset" || tag == "ryoffset") { // obsolete
257 0 : e.readDouble();
258 190 : } else if (tag == "offsetType") {
259 107 : const String& val(e.readText());
260 107 : OffsetType ot = OffsetType::ABS;
261 107 : if (val == "spatium" || val == "1") {
262 83 : ot = OffsetType::SPATIUM;
263 : }
264 107 : if (ot != offsetType) {
265 24 : offsetType = ot;
266 24 : if (ot == OffsetType::ABS) {
267 24 : offset /= INCH; // convert spatium -> inch
268 : } else {
269 0 : offset *= INCH; // convert inch -> spatium
270 : }
271 : }
272 190 : } else if (tag == "sizeIsSpatiumDependent" || tag == "spatiumSizeDependent") {
273 58 : sizeIsSpatiumDependent = e.readInt();
274 25 : } else if (tag == "frameWidth") { // obsolete
275 0 : frameType = FrameType::RECTANGLE;
276 0 : /*frameWidthMM =*/ e.readDouble();
277 25 : } else if (tag == "frameWidthS") {
278 3 : frameType = FrameType::RECTANGLE;
279 3 : frameWidth = Spatium(e.readDouble());
280 22 : } else if (tag == "frame") {
281 0 : frameType = e.readInt() ? FrameType::RECTANGLE : FrameType::NO_FRAME;
282 22 : } else if (tag == "paddingWidth") { // obsolete
283 : /*paddingWidthMM =*/
284 0 : e.readDouble();
285 22 : } else if (tag == "paddingWidthS") {
286 3 : paddingWidth = Spatium(e.readDouble());
287 19 : } else if (tag == "frameRound") {
288 3 : e.readDouble();
289 16 : } else if (tag == "frameColor") {
290 3 : frameColor = e.readColor();
291 13 : } else if (tag == "foregroundColor") {
292 0 : foregroundColor = e.readColor();
293 13 : } else if (tag == "backgroundColor") {
294 0 : backgroundColor = e.readColor();
295 13 : } else if (tag == "circle") {
296 1 : frameType = e.readInt() ? FrameType::CIRCLE : FrameType::NO_FRAME;
297 12 : } else if (tag == "systemFlag") {
298 12 : systemFlag = e.readInt();
299 0 : } else if (tag == "placement") {
300 0 : String value(e.readText());
301 0 : if (value == "above") {
302 0 : placement = PlacementV::ABOVE;
303 0 : } else if (value == "below") {
304 0 : placement = PlacementV::BELOW;
305 : }
306 0 : placementValid = true;
307 0 : } else if (tag == "lineWidth") {
308 0 : lineWidth = e.readDouble();
309 : } else {
310 0 : e.unknown();
311 : }
312 : }
313 107 : if (family == "MuseJazz") {
314 42 : family = u"MuseJazz Text";
315 : }
316 :
317 : struct StyleTable {
318 : const char* name;
319 : TextStyleType ss;
320 107 : } styleTable[] = {
321 : { "", TextStyleType::DEFAULT },
322 : { "Title", TextStyleType::TITLE },
323 : { "Subtitle", TextStyleType::SUBTITLE },
324 : { "Composer", TextStyleType::COMPOSER },
325 : { "Lyricist", TextStyleType::LYRICIST },
326 : { "Lyrics Odd Lines", TextStyleType::LYRICS_ODD },
327 : { "Lyrics Even Lines", TextStyleType::LYRICS_EVEN },
328 : { "Fingering", TextStyleType::FINGERING },
329 : { "LH Guitar Fingering", TextStyleType::LH_GUITAR_FINGERING },
330 : { "RH Guitar Fingering", TextStyleType::RH_GUITAR_FINGERING },
331 : { "String Number", TextStyleType::STRING_NUMBER },
332 : { "Instrument Name (Long)", TextStyleType::INSTRUMENT_LONG },
333 : { "Instrument Name (Short)", TextStyleType::INSTRUMENT_SHORT },
334 : { "Instrument Name (Part)", TextStyleType::INSTRUMENT_EXCERPT },
335 : { "Dynamics", TextStyleType::DYNAMICS },
336 : { "Technique", TextStyleType::IGNORED_TYPES },
337 : { "Tempo", TextStyleType::TEMPO },
338 : { "Metronome", TextStyleType::METRONOME },
339 : { "Measure Number", TextStyleType::MEASURE_NUMBER },
340 : { "Translator", TextStyleType::TRANSLATOR },
341 : { "Tuplet", TextStyleType::TUPLET },
342 : { "System", TextStyleType::SYSTEM },
343 : { "Staff", TextStyleType::STAFF },
344 : { "Chord Symbol", TextStyleType::HARMONY_A },
345 : { "Rehearsal Mark", TextStyleType::REHEARSAL_MARK },
346 : { "Repeat Text Left", TextStyleType::REPEAT_LEFT },
347 : { "Repeat Text Right", TextStyleType::REPEAT_RIGHT },
348 : { "Frame", TextStyleType::FRAME },
349 : { "Text Line", TextStyleType::TEXTLINE },
350 : { "Glissando", TextStyleType::GLISSANDO },
351 : { "Ottava", TextStyleType::OTTAVA },
352 : { "Pedal", TextStyleType::PEDAL },
353 : { "Hairpin", TextStyleType::HAIRPIN },
354 : { "Bend", TextStyleType::BEND },
355 : { "Header", TextStyleType::HEADER },
356 : { "Footer", TextStyleType::FOOTER },
357 : { "Instrument Change", TextStyleType::INSTRUMENT_CHANGE },
358 : { "Repeat Text", TextStyleType::IGNORED_TYPES, }, // Repeat Text style no longer exists
359 : { "Figured Bass", TextStyleType::IGNORED_TYPES, }, // F.B. data are in style properties
360 : { "Volta", TextStyleType::VOLTA },
361 : };
362 107 : TextStyleType ss = TextStyleType::TEXT_TYPES;
363 2792 : for (const auto& i : styleTable) {
364 2762 : if (name == i.name) {
365 77 : ss = i.ss;
366 77 : break;
367 : }
368 : }
369 :
370 107 : if (ss == TextStyleType::IGNORED_TYPES) {
371 4 : return;
372 : }
373 :
374 103 : if (ss == TextStyleType::DEFAULT) {
375 : // This could be false in older files but newer files must have this true
376 1 : sizeIsSpatiumDependent = true;
377 : }
378 :
379 103 : bool isExcessStyle = false;
380 103 : if (ss == TextStyleType::TEXT_TYPES) {
381 30 : ss = ctx.addUserTextStyle(name);
382 30 : if (ss == TextStyleType::TEXT_TYPES) {
383 0 : LOGD("unhandled substyle <%s>", muPrintable(name));
384 0 : isExcessStyle = true;
385 : } else {
386 30 : int idx = int(ss) - int(TextStyleType::USER1);
387 30 : if ((int(ss) < int(TextStyleType::USER1)) || (int(ss) > int(TextStyleType::USER12))) {
388 0 : LOGD("User style index %d outside of range.", idx);
389 0 : return;
390 : }
391 30 : Sid sid[] = { Sid::user1Name, Sid::user2Name, Sid::user3Name, Sid::user4Name, Sid::user5Name, Sid::user6Name,
392 : Sid::user7Name, Sid::user8Name, Sid::user9Name, Sid::user10Name, Sid::user11Name, Sid::user12Name };
393 30 : style->set(sid[idx], name);
394 : }
395 : }
396 :
397 103 : std::map<Sid, PropertyValue> excessPairs;
398 : const TextStyle* ts;
399 103 : if (isExcessStyle) {
400 0 : ts = textStyle(TextStyleType::USER1);
401 : } else {
402 103 : ts = textStyle(ss);
403 : }
404 1751 : for (const auto& i : *ts) {
405 1648 : if (ctx.shouldSkipProperty(i.pid)) {
406 0 : continue;
407 : }
408 :
409 1648 : PropertyValue value;
410 1648 : if (i.sid == Sid::NOSTYLE) {
411 0 : break;
412 : }
413 1648 : switch (i.pid) {
414 0 : case Pid::TEXT_STYLE:
415 0 : value = ss;
416 0 : break;
417 103 : case Pid::BEGIN_FONT_FACE:
418 : case Pid::CONTINUE_FONT_FACE:
419 : case Pid::END_FONT_FACE:
420 : case Pid::FONT_FACE:
421 103 : value = family;
422 103 : break;
423 103 : case Pid::BEGIN_FONT_SIZE:
424 : case Pid::CONTINUE_FONT_SIZE:
425 : case Pid::END_FONT_SIZE:
426 : case Pid::FONT_SIZE:
427 103 : value = size;
428 103 : break;
429 103 : case Pid::BEGIN_FONT_STYLE:
430 : case Pid::CONTINUE_FONT_STYLE:
431 : case Pid::END_FONT_STYLE:
432 : case Pid::FONT_STYLE:
433 103 : value = int(fontStyle);
434 103 : break;
435 103 : case Pid::FRAME_TYPE:
436 103 : value = int(frameType);
437 103 : break;
438 103 : case Pid::FRAME_WIDTH:
439 103 : value = frameWidth;
440 103 : break;
441 103 : case Pid::FRAME_PADDING:
442 103 : value = paddingWidth;
443 103 : break;
444 103 : case Pid::FRAME_FG_COLOR:
445 103 : value = PropertyValue::fromValue(frameColor);
446 103 : break;
447 103 : case Pid::FRAME_BG_COLOR:
448 103 : value = PropertyValue::fromValue(backgroundColor);
449 103 : break;
450 103 : case Pid::SIZE_SPATIUM_DEPENDENT:
451 103 : value = sizeIsSpatiumDependent;
452 103 : break;
453 103 : case Pid::BEGIN_TEXT_ALIGN:
454 : case Pid::CONTINUE_TEXT_ALIGN:
455 : case Pid::END_TEXT_ALIGN:
456 : case Pid::ALIGN:
457 103 : value = PropertyValue::fromValue(align);
458 103 : break;
459 93 : case Pid::POSITION:
460 93 : value = PropertyValue::fromValue(align.horizontal);
461 93 : break;
462 0 : case Pid::SYSTEM_FLAG:
463 0 : value = systemFlag;
464 0 : break;
465 0 : case Pid::BEGIN_HOOK_HEIGHT:
466 : case Pid::END_HOOK_HEIGHT:
467 0 : value = PropertyValue();
468 0 : break;
469 0 : case Pid::PLACEMENT:
470 0 : if (placementValid) {
471 0 : value = placement;
472 : }
473 0 : break;
474 0 : case Pid::LINE_WIDTH:
475 0 : if (lineWidth != -1.0) {
476 0 : value = lineWidth;
477 : }
478 0 : break;
479 525 : default:
480 : // LOGD("unhandled property <%s>%d", propertyName(i.pid), int (i.pid));
481 525 : break;
482 : }
483 1648 : if (value.isValid()) {
484 1123 : if (isExcessStyle) {
485 0 : excessPairs[i.sid] = value;
486 : } else {
487 1123 : style->set(i.sid, value);
488 : }
489 : }
490 : // else
491 : // LOGD("invalid style value <%s> pid<%s>", MStyle::valueName(i.sid), propertyName(i.pid));
492 1648 : }
493 :
494 103 : if (isExcessStyle && excessPairs.size() > 0) {
495 0 : excessStyles[name] = excessPairs;
496 : }
497 111 : }
498 :
499 142 : void Read206::readAccidental206(Accidental* a, XmlReader& e, ReadContext& ctx)
500 : {
501 360 : while (e.readNextStartElement()) {
502 218 : const AsciiStringView tag(e.name());
503 218 : if (tag == "bracket") {
504 21 : int i = e.readInt();
505 21 : if (i == 0 || i == 1) {
506 21 : a->setBracket(AccidentalBracket(i));
507 : }
508 197 : } else if (tag == "subtype") {
509 142 : String text = e.readText();
510 : static const std::map<String, AccidentalType> accMap = {
511 0 : { u"none", AccidentalType::NONE },
512 0 : { u"sharp", AccidentalType::SHARP },
513 0 : { u"flat", AccidentalType::FLAT },
514 0 : { u"natural", AccidentalType::NATURAL },
515 0 : { u"double sharp", AccidentalType::SHARP2 },
516 0 : { u"double flat", AccidentalType::FLAT2 },
517 0 : { u"flat-slash", AccidentalType::FLAT_SLASH },
518 0 : { u"flat-slash2", AccidentalType::FLAT_SLASH2 },
519 0 : { u"mirrored-flat2", AccidentalType::MIRRORED_FLAT2 },
520 0 : { u"mirrored-flat", AccidentalType::MIRRORED_FLAT },
521 0 : { u"sharp-slash", AccidentalType::SHARP_SLASH },
522 0 : { u"sharp-slash2", AccidentalType::SHARP_SLASH2 },
523 0 : { u"sharp-slash3", AccidentalType::SHARP_SLASH3 },
524 0 : { u"sharp-slash4", AccidentalType::SHARP_SLASH4 },
525 0 : { u"sharp arrow up", AccidentalType::SHARP_ARROW_UP },
526 0 : { u"sharp arrow down", AccidentalType::SHARP_ARROW_DOWN },
527 0 : { u"flat arrow up", AccidentalType::FLAT_ARROW_UP },
528 0 : { u"flat arrow down", AccidentalType::FLAT_ARROW_DOWN },
529 0 : { u"natural arrow up", AccidentalType::NATURAL_ARROW_UP },
530 0 : { u"natural arrow down", AccidentalType::NATURAL_ARROW_DOWN },
531 0 : { u"sori", AccidentalType::SORI },
532 0 : { u"koron", AccidentalType::KORON }
533 166 : };
534 142 : auto it = accMap.find(text);
535 142 : if (it == accMap.end()) {
536 0 : LOGD("invalid type %s", muPrintable(text));
537 0 : a->setAccidentalType(AccidentalType::NONE);
538 : } else {
539 142 : a->setAccidentalType(it->second);
540 : }
541 197 : } else if (tag == "role") {
542 43 : AccidentalRole r = AccidentalRole(e.readInt());
543 43 : if (r == AccidentalRole::AUTO || r == AccidentalRole::USER) {
544 43 : a->setRole(r);
545 : }
546 12 : } else if (tag == "small") {
547 0 : a->setSmall(e.readInt());
548 12 : } else if (TRead::readItemProperties(a, e, ctx)) {
549 : } else {
550 0 : e.unknown();
551 : }
552 : }
553 143 : }
554 :
555 0 : VoiceAssignment Read206::readDynamicRange(int i)
556 : {
557 0 : switch (i) {
558 0 : case 0:
559 0 : return VoiceAssignment::ALL_VOICE_IN_STAFF;
560 0 : case 1:
561 : case 2:
562 0 : break;
563 : }
564 :
565 0 : return VoiceAssignment::ALL_VOICE_IN_INSTRUMENT;
566 : }
567 :
568 253 : NoteHeadGroup Read206::convertHeadGroup(int i)
569 : {
570 : NoteHeadGroup val;
571 253 : switch (i) {
572 89 : case 1:
573 89 : val = NoteHeadGroup::HEAD_CROSS;
574 89 : break;
575 28 : case 2:
576 28 : val = NoteHeadGroup::HEAD_DIAMOND;
577 28 : break;
578 14 : case 3:
579 14 : val = NoteHeadGroup::HEAD_TRIANGLE_DOWN;
580 14 : break;
581 9 : case 4:
582 9 : val = NoteHeadGroup::HEAD_MI;
583 9 : break;
584 14 : case 5:
585 14 : val = NoteHeadGroup::HEAD_SLASH;
586 14 : break;
587 18 : case 6:
588 18 : val = NoteHeadGroup::HEAD_XCIRCLE;
589 18 : break;
590 7 : case 7:
591 7 : val = NoteHeadGroup::HEAD_DO;
592 7 : break;
593 7 : case 8:
594 7 : val = NoteHeadGroup::HEAD_RE;
595 7 : break;
596 7 : case 9:
597 7 : val = NoteHeadGroup::HEAD_FA;
598 7 : break;
599 7 : case 10:
600 7 : val = NoteHeadGroup::HEAD_LA;
601 7 : break;
602 7 : case 11:
603 7 : val = NoteHeadGroup::HEAD_TI;
604 7 : break;
605 7 : case 12:
606 7 : val = NoteHeadGroup::HEAD_SOL;
607 7 : break;
608 8 : case 13:
609 8 : val = NoteHeadGroup::HEAD_BREVIS_ALT;
610 8 : break;
611 31 : case 0:
612 : default:
613 31 : val = NoteHeadGroup::HEAD_NORMAL;
614 : }
615 253 : return val;
616 : }
617 :
618 43 : static NoteHeadType convertHeadType(int i)
619 : {
620 : NoteHeadType val;
621 43 : switch (i) {
622 14 : case 0:
623 14 : val = NoteHeadType::HEAD_WHOLE;
624 14 : break;
625 15 : case 1:
626 15 : val = NoteHeadType::HEAD_HALF;
627 15 : break;
628 0 : case 2:
629 0 : val = NoteHeadType::HEAD_QUARTER;
630 0 : break;
631 14 : case 3:
632 14 : val = NoteHeadType::HEAD_BREVIS;
633 14 : break;
634 0 : default:
635 0 : val = NoteHeadType::HEAD_AUTO;
636 : }
637 43 : return val;
638 : }
639 :
640 : //---------------------------------------------------------
641 : // ArticulationNames
642 : //---------------------------------------------------------
643 :
644 : static struct ArticulationNames {
645 : SymId id;
646 : AsciiStringView name;
647 : } articulationNames[] = {
648 : { SymId::fermataAbove, "fermata", },
649 : { SymId::fermataShortAbove, "shortfermata", },
650 : { SymId::fermataLongAbove, "longfermata", },
651 : { SymId::fermataVeryLongAbove, "verylongfermata", },
652 : { SymId::articAccentAbove, "sforzato", },
653 : { SymId::articStaccatoAbove, "staccato", },
654 : { SymId::articStaccatissimoAbove, "staccatissimo", },
655 : { SymId::articTenutoAbove, "tenuto", },
656 : { SymId::articTenutoStaccatoAbove, "portato", },
657 : { SymId::articMarcatoAbove, "marcato", },
658 : { SymId::guitarFadeIn, "fadein", },
659 : { SymId::guitarFadeOut, "fadeout", },
660 : { SymId::guitarVolumeSwell, "volumeswell", },
661 : { SymId::wiggleSawtooth, "wigglesawtooth", },
662 : { SymId::wiggleSawtoothWide, "wigglesawtoothwide", },
663 : { SymId::wiggleVibratoLargeFaster, "wigglevibratolargefaster", },
664 : { SymId::wiggleVibratoLargeSlowest, "wigglevibratolargeslowest", },
665 : { SymId::brassMuteOpen, "ouvert", },
666 : { SymId::brassMuteClosed, "plusstop", },
667 : { SymId::stringsUpBow, "upbow", },
668 : { SymId::stringsDownBow, "downbow", },
669 : { SymId::ornamentTurnInverted, "reverseturn", },
670 : { SymId::ornamentTurn, "turn", },
671 : { SymId::ornamentTrill, "trill", },
672 : { SymId::ornamentShortTrill, "prall", },
673 : { SymId::ornamentMordent, "mordent", },
674 : { SymId::ornamentTremblement, "prallprall", },
675 : { SymId::ornamentPrallMordent, "prallmordent", },
676 : { SymId::ornamentUpPrall, "upprall", },
677 : { SymId::ornamentUpMordent, "upmordent", },
678 : { SymId::ornamentDownMordent, "downmordent", },
679 : { SymId::ornamentPrallDown, "pralldown", },
680 : { SymId::ornamentPrallUp, "prallup", },
681 : { SymId::ornamentLinePrall, "lineprall", },
682 : { SymId::ornamentPrecompSlide, "schleifer", },
683 : { SymId::pluckedSnapPizzicatoAbove, "snappizzicato", },
684 : { SymId::stringsThumbPosition, "thumb", },
685 : { SymId::luteFingeringRHThumb, "lutefingeringthumb", },
686 : { SymId::luteFingeringRHFirst, "lutefingering1st", },
687 : { SymId::luteFingeringRHSecond, "lutefingering2nd", },
688 : { SymId::luteFingeringRHThird, "lutefingering3rd", },
689 :
690 : { SymId::ornamentPrecompMordentUpperPrefix, "downprall" },
691 : { SymId::ornamentPrecompMordentUpperPrefix, "ornamentDownPrall" },
692 : };
693 :
694 249 : SymId Read206::articulationNames2SymId206(const AsciiStringView& s)
695 : {
696 4300 : for (auto i : articulationNames) {
697 4286 : if (i.name == s) {
698 235 : return i.id;
699 : }
700 : }
701 14 : return SymId::noSym;
702 : }
703 :
704 : //---------------------------------------------------------
705 : // readDrumset
706 : //---------------------------------------------------------
707 :
708 68 : static void readDrumset206(Drumset* ds, XmlReader& e)
709 : {
710 68 : int pitch = e.intAttribute("pitch", -1);
711 68 : if (!pitchIsValid(pitch)) {
712 0 : LOGD("load drumset: invalid pitch %d", pitch);
713 0 : return;
714 : }
715 415 : while (e.readNextStartElement()) {
716 347 : const AsciiStringView tag(e.name());
717 347 : if (tag == "head") {
718 68 : ds->drum(pitch).notehead = Read206::convertHeadGroup(e.readInt());
719 279 : } else if (tag == "variants") {
720 0 : while (e.readNextStartElement()) {
721 0 : const AsciiStringView tagv(e.name());
722 0 : if (tagv == "variant") {
723 0 : DrumInstrumentVariant div;
724 0 : div.pitch = e.attribute("pitch").toInt();
725 0 : while (e.readNextStartElement()) {
726 0 : const AsciiStringView taga(e.name());
727 0 : if (taga == "articulation") {
728 0 : AsciiStringView oldArticulationName = e.readAsciiText();
729 0 : SymId oldId = Read206::articulationNames2SymId206(oldArticulationName);
730 0 : div.articulationName = Articulation::symId2ArticulationName(oldId);
731 0 : } else if (taga == "tremolo") {
732 0 : div.tremolo = TConv::fromXml(e.readAsciiText(), TremoloType::INVALID_TREMOLO);
733 : }
734 : }
735 0 : ds->drum(pitch).addVariant(div);
736 0 : }
737 : }
738 279 : } else if (ds->readDrumProperties(e, pitch)) {
739 : } else {
740 0 : e.unknown();
741 : }
742 : }
743 : }
744 :
745 : //---------------------------------------------------------
746 : // readInstrument
747 : //---------------------------------------------------------
748 :
749 55 : static void readInstrument206(Instrument* i, Part* p, XmlReader& e, ReadContext& ctx)
750 : {
751 55 : int bank = 0;
752 55 : char volume = 100;
753 55 : char pan = 60;
754 55 : char chorus = 30;
755 55 : char reverb = 30;
756 55 : bool customDrumset = false;
757 55 : i->clearChannels(); // remove default channel
758 957 : while (e.readNextStartElement()) {
759 902 : const AsciiStringView tag(e.name());
760 902 : if (tag == "Drum") {
761 : // if we see one of this tags, a custom drumset will
762 : // be created
763 68 : if (!i->drumset()) {
764 0 : i->setDrumset(new Drumset(*smDrumset));
765 : }
766 68 : if (!customDrumset) {
767 4 : i->drumset()->clear();
768 4 : customDrumset = true;
769 : }
770 68 : readDrumset206(i->drumset(), e);
771 834 : } else if (read400::TRead::readProperties(i, e, ctx, p, &customDrumset)) {
772 : } else {
773 0 : e.unknown();
774 : }
775 : }
776 :
777 55 : i->updateInstrumentId();
778 :
779 : // Read single-note dynamics from template
780 55 : i->setSingleNoteDynamicsFromTemplate();
781 :
782 55 : if (i->channel().empty()) { // for backward compatibility
783 0 : InstrChannel* a = new InstrChannel;
784 0 : a->setName(String::fromUtf8(InstrChannel::DEFAULT_NAME));
785 0 : a->setProgram(i->recognizeMidiProgram());
786 0 : a->setBank(bank);
787 0 : a->setVolume(volume);
788 0 : a->setPan(pan);
789 0 : a->setReverb(reverb);
790 0 : a->setChorus(chorus);
791 0 : i->appendChannel(a);
792 55 : } else if (i->channel(0)->program() < 0) {
793 0 : i->channel(0)->setProgram(i->recognizeMidiProgram());
794 : }
795 55 : if (i->useDrumset()) {
796 4 : if (i->channel()[0]->bank() == 0) {
797 0 : i->channel()[0]->setBank(128);
798 : }
799 : }
800 55 : }
801 :
802 : //---------------------------------------------------------
803 : // readStaff
804 : //---------------------------------------------------------
805 :
806 60 : static void readStaff(Staff* staff, XmlReader& e, ReadContext& ctx)
807 : {
808 161 : while (e.readNextStartElement()) {
809 101 : const AsciiStringView tag(e.name());
810 101 : if (tag == "type") { // obsolete
811 0 : int staffTypeIdx = e.readInt();
812 0 : LOGD("obsolete: Staff::read staffTypeIdx %d", staffTypeIdx);
813 101 : } else if (tag == "StaffType") {
814 60 : StaffType st;
815 60 : TRead::read(&st, e, ctx);
816 60 : staff->setStaffType(Fraction(0, 1), st);
817 101 : } else if (tag == "defaultClef") { // sets both default transposing and concert clef
818 9 : ClefType ct = TConv::fromXml(e.readAsciiText(), ClefType::G);
819 9 : staff->setDefaultClefType(ClefTypeList(ct, ct));
820 32 : } else if (tag == "defaultConcertClef") {
821 0 : staff->setDefaultClefType(ClefTypeList(TConv::fromXml(e.readAsciiText(), ClefType::G),
822 0 : staff->defaultClefType().transposingClef));
823 32 : } else if (tag == "defaultTransposingClef") {
824 0 : staff->setDefaultClefType(ClefTypeList(staff->defaultClefType().concertClef,
825 0 : TConv::fromXml(e.readAsciiText(), ClefType::G)));
826 32 : } else if (tag == "small") {
827 0 : staff->staffType(Fraction(0, 1))->setSmall(e.readInt());
828 32 : } else if (tag == "invisible") {
829 0 : staff->staffType(Fraction(0, 1))->setInvisible(e.readInt());
830 32 : } else if (tag == "neverHide") {
831 0 : bool v = e.readInt();
832 0 : if (v) {
833 0 : staff->setHideWhenEmpty(AutoOnOff::OFF);
834 : }
835 32 : } else if (tag == "showIfSystemEmpty") {
836 0 : staff->setShowIfEntireSystemEmpty(e.readInt());
837 32 : } else if (tag == "hideSystemBarLine") {
838 0 : staff->setHideSystemBarLine(e.readInt());
839 32 : } else if (tag == "keylist") {
840 0 : read400::TRead::read(&staff->keyList(), e, ctx);
841 32 : } else if (tag == "bracket") {
842 24 : int col = e.intAttribute("col", -1);
843 24 : if (col == -1) {
844 24 : col = static_cast<int>(ctx.score()->brackets(staff->idx()).size());
845 : }
846 24 : EditStaffBrackets::setBracketType(ctx.score(), staff->idx(), col, BracketType(e.intAttribute("type", -1)));
847 24 : EditStaffBrackets::setBracketSpan(ctx.score(), staff->idx(), col, e.intAttribute("span", 0));
848 24 : EditStaffBrackets::setBracketVisible(ctx.score(), staff->idx(), col, static_cast<bool>(e.intAttribute("visible", 1)));
849 24 : e.readNext();
850 8 : } else if (tag == "barLineSpan") {
851 2 : staff->setBarLineFrom(e.intAttribute("from", 0));
852 2 : staff->setBarLineTo(e.intAttribute("to", 0));
853 2 : const int barLineSpan = e.readInt();
854 2 : if (barLineSpan > 0) {
855 1 : ctx.setStaffBarLineSpan(staff->idx(), static_cast<size_t>(barLineSpan - 1));
856 : } else {
857 1 : if (barLineSpan < 0) {
858 0 : LOGW() << "barLineSpan is negative: " << barLineSpan;
859 : }
860 1 : ctx.setStaffBarLineSpan(staff->idx(), 0);
861 : }
862 6 : } else if (tag == "distOffset") {
863 0 : staff->setUserDist(Spatium(e.readDouble()));
864 6 : } else if (tag == "mag") {
865 : /*_userMag =*/
866 0 : e.readDouble(0.1, 10.0);
867 6 : } else if (tag == "linkedTo") {
868 6 : int v = e.readInt() - 1;
869 6 : Staff* st = staff->score()->masterScore()->staff(v);
870 6 : if (staff->links()) {
871 0 : LOGD("Staff::readProperties: multiple <linkedTo> tags");
872 0 : if (!st || staff->isLinked(st)) { // maybe we don't need actually to relink...
873 0 : continue;
874 : }
875 : // not using unlink() here as it may delete _links
876 : // a pointer to which is stored also in XmlReader.
877 0 : staff->links()->remove(staff);
878 0 : staff->setLinks(nullptr);
879 : }
880 6 : if (st && st != staff) {
881 6 : staff->linkTo(st);
882 0 : } else if (!staff->score()->isMaster() && !st) {
883 : // if it is a master score it is OK not to find
884 : // a staff which is going after the current one.
885 0 : LOGD("staff %d not found in parent", v);
886 : }
887 0 : } else if (tag == "color") {
888 0 : staff->staffType(Fraction(0, 1))->setColor(e.readColor());
889 0 : } else if (tag == "transposeDiatonic") {
890 0 : ctx.setTransposeDiatonic(static_cast<int8_t>(e.readInt()));
891 0 : } else if (tag == "transposeChromatic") {
892 0 : ctx.setTransposeChromatic(static_cast<int8_t>(e.readInt()));
893 : } else {
894 0 : e.unknown();
895 : }
896 : }
897 60 : }
898 :
899 : //---------------------------------------------------------
900 : // readPart
901 : //---------------------------------------------------------
902 :
903 55 : void Read206::readPart206(Part* part, XmlReader& e, ReadContext& ctx)
904 : {
905 226 : while (e.readNextStartElement()) {
906 171 : const AsciiStringView tag(e.name());
907 171 : if (tag == "Instrument") {
908 55 : Instrument* i = part->instrument();
909 55 : readInstrument206(i, part, e, ctx);
910 55 : Drumset* ds = i->drumset();
911 55 : Staff* s = part->staff(0);
912 55 : int lld = s ? std::round(s->lineDistance(Fraction(0, 1))) : 1;
913 55 : if (ds && s && lld > 1) {
914 0 : for (int j = 0; j < DRUM_INSTRUMENTS; ++j) {
915 0 : ds->drum(j).line /= lld;
916 : }
917 : }
918 116 : } else if (tag == "Staff") {
919 60 : Staff* staff = Factory::createStaff(part);
920 60 : ctx.appendStaff(staff);
921 60 : readStaff(staff, e, ctx);
922 56 : } else if (tag == "name") {
923 0 : part->instrument()->setLongName(e.readText());
924 56 : } else if (tag == "shortName") {
925 0 : part->instrument()->setShortName(e.readText());
926 56 : } else if (tag == "show") {
927 1 : part->setShow(e.readInt());
928 : } else {
929 55 : e.unknown();
930 : }
931 : }
932 55 : }
933 :
934 : //---------------------------------------------------------
935 : // readAmbitus
936 : //---------------------------------------------------------
937 :
938 2 : static void readAmbitus(Ambitus* ambitus, XmlReader& e, ReadContext& ctx)
939 : {
940 15 : while (e.readNextStartElement()) {
941 13 : const AsciiStringView tag(e.name());
942 13 : if (tag == "head") {
943 1 : ambitus->setNoteHeadGroup(Read206::convertHeadGroup(e.readInt()));
944 12 : } else if (tag == "headType") {
945 1 : ambitus->setNoteHeadType(convertHeadType(e.readInt()));
946 11 : } else if (read400::TRead::readProperties(ambitus, e, ctx)) {
947 : } else {
948 0 : e.unknown();
949 : }
950 : }
951 2 : }
952 :
953 : //---------------------------------------------------------
954 : // readNote
955 : //---------------------------------------------------------
956 :
957 986 : static void readNote206(Note* note, XmlReader& e, ReadContext& ctx)
958 : {
959 986 : note->setTpc1(Tpc::TPC_INVALID);
960 986 : note->setTpc2(Tpc::TPC_INVALID);
961 :
962 3629 : while (e.readNextStartElement()) {
963 2643 : const AsciiStringView tag(e.name());
964 2643 : if (tag == "Accidental") {
965 141 : Accidental* a = Factory::createAccidental(note);
966 141 : a->setTrack(note->track());
967 141 : Read206::readAccidental206(a, e, ctx);
968 141 : note->add(a);
969 2502 : } else if (tag == "head") {
970 99 : int i = e.readInt();
971 99 : NoteHeadGroup val = Read206::convertHeadGroup(i);
972 99 : note->setHeadGroup(val);
973 2403 : } else if (tag == "headType") {
974 42 : int i = e.readInt();
975 42 : NoteHeadType val = convertHeadType(i);
976 42 : note->setHeadType(val);
977 2361 : } else if (Read206::readNoteProperties206(note, e, ctx)) {
978 : } else {
979 362 : e.unknown();
980 : }
981 : }
982 : // ensure sane values:
983 986 : note->setPitch(clampPitch(note->pitch()));
984 :
985 986 : if (!tpcIsValid(note->tpc1()) && !tpcIsValid(note->tpc2())) {
986 0 : Key key = (note->staff() && note->chord()) ? note->staff()->key(note->chord()->tick()) : Key::C;
987 0 : int tpc = pitch2tpc(note->pitch(), key, Prefer::NEAREST);
988 0 : if (note->concertPitch()) {
989 0 : note->setTpc1(tpc);
990 : } else {
991 0 : note->setTpc2(tpc);
992 : }
993 : }
994 986 : if (!(tpcIsValid(note->tpc1()) && tpcIsValid(note->tpc2()))) {
995 0 : Fraction tick = note->chord() ? note->chord()->tick() : Fraction(-1, 1);
996 0 : Interval v = note->staff() ? note->staff()->transpose(tick) : Interval();
997 0 : if (tpcIsValid(note->tpc1())) {
998 0 : v.flip();
999 0 : if (v.isZero()) {
1000 0 : note->setTpc2(note->tpc1());
1001 : } else {
1002 0 : note->setTpc2(Transpose::transposeTpc(note->tpc1(), v, true));
1003 : }
1004 : } else {
1005 0 : if (v.isZero()) {
1006 0 : note->setTpc1(note->tpc2());
1007 : } else {
1008 0 : note->setTpc1(Transpose::transposeTpc(note->tpc2(), v, true));
1009 : }
1010 : }
1011 : }
1012 986 : }
1013 :
1014 : //---------------------------------------------------------
1015 : // adjustPlacement
1016 : //---------------------------------------------------------
1017 :
1018 18 : static void adjustPlacement(EngravingItem* e)
1019 : {
1020 18 : if (!e || !e->staff()) {
1021 2 : return;
1022 : }
1023 :
1024 : // element to use to determine placement
1025 : // for spanners, choose first segment
1026 : EngravingItem* ee;
1027 : Spanner* spanner;
1028 16 : if (e->isSpanner()) {
1029 7 : spanner = toSpanner(e);
1030 7 : if (spanner->spannerSegments().empty()) {
1031 7 : return;
1032 : }
1033 0 : ee = spanner->spannerSegments().front();
1034 0 : if (!ee) {
1035 0 : return;
1036 : }
1037 : } else {
1038 9 : spanner = nullptr;
1039 9 : ee = e;
1040 : }
1041 :
1042 : // determine placement based on offset
1043 : // anything below staff will be set to below
1044 9 : double staffHeight = e->staff()->staffHeight();
1045 9 : double threshold = staffHeight;
1046 9 : double offsetAdjust = 0.0;
1047 9 : PlacementV defaultPlacement = e->propertyDefault(Pid::PLACEMENT).value<PlacementV>();
1048 : PlacementV newPlacement;
1049 : // most offsets will be recorded as relative to top staff line
1050 : // exceptions are styled offsets on elements with default placement below
1051 : double normalize;
1052 9 : if (defaultPlacement == PlacementV::BELOW && ee->offset().isNull()) {
1053 0 : normalize = staffHeight;
1054 : } else {
1055 9 : normalize = 0.0;
1056 : }
1057 9 : double ypos = ee->offset().y() + normalize;
1058 9 : if (ypos >= threshold) {
1059 0 : newPlacement = PlacementV::BELOW;
1060 0 : offsetAdjust -= staffHeight;
1061 : } else {
1062 9 : newPlacement = PlacementV::ABOVE;
1063 : }
1064 :
1065 : // set placement
1066 9 : e->setProperty(Pid::PLACEMENT, newPlacement);
1067 9 : if (newPlacement != defaultPlacement) {
1068 0 : e->setPropertyFlags(Pid::PLACEMENT, PropertyFlags::UNSTYLED);
1069 : }
1070 :
1071 : // adjust offset
1072 9 : if (spanner) {
1073 : // adjust segments individually
1074 0 : for (auto a : spanner->spannerSegments()) {
1075 : // spanner segments share the placement setting of the spanner
1076 : // just adjust offset
1077 0 : if (defaultPlacement == PlacementV::BELOW && a->offset().isNull()) {
1078 0 : normalize = staffHeight;
1079 : } else {
1080 0 : normalize = 0.0;
1081 : }
1082 0 : double yp = a->offset().y() + normalize;
1083 0 : a->ryoffset() += normalize + offsetAdjust;
1084 :
1085 : // if any segments are offset to opposite side of staff from placement,
1086 : // or if they are within staff,
1087 : // disable autoplace
1088 : bool disableAutoplace;
1089 0 : if (yp + a->height() <= 0.0) {
1090 0 : disableAutoplace = (newPlacement == PlacementV::BELOW);
1091 0 : } else if (yp > staffHeight) {
1092 0 : disableAutoplace = (newPlacement == PlacementV::ABOVE);
1093 : } else {
1094 0 : disableAutoplace = true;
1095 : }
1096 0 : if (disableAutoplace) {
1097 0 : a->setAutoplace(false);
1098 : }
1099 : // needed for https://musescore.org/en/node/281312
1100 : // ideally we would rebase and calculate new offset
1101 : // but this may not be possible
1102 : // since original offset is relative to system
1103 0 : a->rxoffset() = 0;
1104 : }
1105 : } else {
1106 9 : e->ryoffset() += normalize + offsetAdjust;
1107 : // if within staff, disable autoplace
1108 9 : if (ypos + e->height() > 0.0 && ypos <= staffHeight) {
1109 0 : e->setAutoplace(false);
1110 : }
1111 : }
1112 : }
1113 :
1114 3272 : bool Read206::readNoteProperties206(Note* note, XmlReader& e, ReadContext& ctx)
1115 : {
1116 3272 : const AsciiStringView tag(e.name());
1117 :
1118 3272 : if (tag == "pitch") {
1119 1425 : note->setPitch(e.readInt());
1120 1847 : } else if (tag == "tpc") {
1121 1425 : const int tpc = e.readInt();
1122 1425 : note->setTpc1(tpc);
1123 1425 : note->setTpc2(tpc);
1124 422 : } else if (tag == "track") { // for performance
1125 43 : note->setTrack(e.readInt());
1126 379 : } else if (tag == "Accidental") {
1127 0 : Accidental* a = Factory::createAccidental(note);
1128 0 : a->setTrack(note->track());
1129 0 : read400::TRead::read(a, e, ctx);
1130 0 : note->add(a);
1131 379 : } else if (tag == "Tie") {
1132 0 : Tie* tie = Factory::createTie(note);
1133 0 : tie->setTrack(note->track());
1134 0 : readTie206(e, ctx, tie);
1135 0 : tie->setStartNote(note);
1136 0 : note->setTieFor(tie);
1137 379 : } else if (tag == "tpc2") {
1138 0 : note->setTpc2(e.readInt());
1139 379 : } else if (tag == "small") {
1140 0 : note->setSmall(e.readInt());
1141 379 : } else if (tag == "mirror") {
1142 0 : read400::TRead::readProperty(note, e, ctx, Pid::MIRROR_HEAD);
1143 379 : } else if (tag == "dotPosition") {
1144 0 : read400::TRead::readProperty(note, e, ctx, Pid::DOT_POSITION);
1145 379 : } else if (tag == "fixed") {
1146 0 : note->setFixed(e.readBool());
1147 379 : } else if (tag == "fixedLine") {
1148 0 : note->setFixedLine(e.readInt());
1149 379 : } else if (tag == "head") {
1150 0 : read400::TRead::readProperty(note, e, ctx, Pid::HEAD_GROUP);
1151 379 : } else if (tag == "velocity") {
1152 : // TODO: convert to MU4
1153 0 : e.skipCurrentElement();
1154 379 : } else if (tag == "play") {
1155 0 : note->setPlay(e.readInt());
1156 379 : } else if (tag == "tuning") {
1157 0 : note->setTuning(e.readDouble());
1158 379 : } else if (tag == "fret") {
1159 0 : note->setFret(e.readInt());
1160 379 : } else if (tag == "string") {
1161 0 : note->setString(e.readInt());
1162 379 : } else if (tag == "ghost") {
1163 0 : note->setGhost(e.readInt());
1164 379 : } else if (tag == "headType") {
1165 0 : read400::TRead::readProperty(note, e, ctx, Pid::HEAD_TYPE);
1166 379 : } else if (tag == "veloType") {
1167 0 : read400::TRead::readProperty(note, e, ctx, Pid::VELO_TYPE);
1168 379 : } else if (tag == "line") {
1169 0 : note->setLine(e.readInt());
1170 379 : } else if (tag == "Fingering") {
1171 4 : Fingering* f = Factory::createFingering(note);
1172 4 : f->setTrack(note->track());
1173 4 : readText206(e, ctx, f, note);
1174 4 : note->add(f);
1175 375 : } else if (tag == "Symbol") {
1176 0 : Symbol* s = new Symbol(note);
1177 0 : s->setTrack(note->track());
1178 0 : read400::TRead::read(s, e, ctx);
1179 0 : if (s->sym() == SymId::noteheadParenthesisLeft) {
1180 0 : note->setParenthesesMode(note->rightParen() ? ParenthesesMode::BOTH : ParenthesesMode::LEFT);
1181 0 : s->deleteLater();
1182 0 : } else if (s->sym() == SymId::noteheadParenthesisRight) {
1183 0 : note->setParenthesesMode(note->leftParen() ? ParenthesesMode::BOTH : ParenthesesMode::RIGHT);
1184 0 : s->deleteLater();
1185 : } else {
1186 0 : note->add(s);
1187 : }
1188 375 : } else if (tag == "Image") {
1189 0 : if (MScore::noImages) {
1190 0 : e.skipCurrentElement();
1191 : } else {
1192 0 : Image* image = new Image(note);
1193 0 : image->setTrack(note->track());
1194 0 : read400::TRead::read(image, e, ctx);
1195 0 : note->add(image);
1196 : }
1197 375 : } else if (tag == "Bend") {
1198 4 : Bend* b = Factory::createBend(note);
1199 4 : b->setTrack(note->track());
1200 4 : read400::TRead::read(b, e, ctx);
1201 4 : note->add(b);
1202 371 : } else if (tag == "NoteDot") {
1203 0 : NoteDot* dot = Factory::createNoteDot(note);
1204 0 : read400::TRead::read(dot, e, ctx);
1205 0 : note->add(dot);
1206 371 : } else if (tag == "Events") {
1207 0 : note->playEvents().clear(); // remove default event
1208 0 : while (e.readNextStartElement()) {
1209 0 : const AsciiStringView etag(e.name());
1210 0 : if (etag == "Event") {
1211 0 : NoteEvent ne;
1212 0 : read400::TRead::read(&ne, e, ctx);
1213 0 : note->playEvents().push_back(ne);
1214 : } else {
1215 0 : e.unknown();
1216 : }
1217 : }
1218 0 : if (Chord* ch = note->chord()) {
1219 0 : ch->setPlayEventType(PlayEventType::User);
1220 : }
1221 371 : } else if (tag == "endSpanner") {
1222 0 : int id = e.intAttribute("id");
1223 0 : Spanner* sp = ctx.findSpanner(id);
1224 0 : if (sp) {
1225 0 : sp->setEndElement(note);
1226 0 : if (sp->isTie()) {
1227 0 : note->setTieBack(toTie(sp));
1228 : } else {
1229 0 : note->addSpannerBack(sp);
1230 : }
1231 0 : ctx.removeSpanner(sp);
1232 : } else {
1233 : // End of a spanner whose start element will appear later;
1234 : // may happen for cross-staff spanner from a lower to a higher staff
1235 : // (for instance a glissando from bass to treble staff of piano).
1236 : // Create a place-holder spanner with end data
1237 : // (a TextLine is used only because both Spanner or SLine are abstract,
1238 : // the actual class does not matter, as long as it is derived from Spanner)
1239 0 : int id1 = e.intAttribute("id", -1);
1240 0 : Staff* staff = note->staff();
1241 0 : if (id1 != -1
1242 0 : && // DISABLE if pasting into a staff with linked staves
1243 : // because the glissando is not properly cloned into the linked staves
1244 0 : staff && (!ctx.pasteMode() || !staff->links() || staff->links()->empty())) {
1245 0 : Spanner* placeholder = new TextLine(ctx.dummy());
1246 0 : placeholder->setEndElement(note);
1247 0 : placeholder->setTrack2(note->track());
1248 0 : placeholder->setTick(Fraction(0, 1));
1249 0 : placeholder->setTick2(ctx.tick());
1250 0 : ctx.addSpanner(id1, placeholder);
1251 : }
1252 : }
1253 0 : e.readNext();
1254 371 : } else if (tag == "TextLine"
1255 371 : || tag == "Glissando") {
1256 0 : Spanner* sp = toSpanner(Factory::createItemByName(tag, ctx.dummy()));
1257 : // check this is not a lower-to-higher cross-staff spanner we already got
1258 0 : int id = e.intAttribute("id");
1259 0 : Spanner* placeholder = ctx.findSpanner(id);
1260 0 : if (placeholder && placeholder->endElement()) {
1261 : // if it is, fill end data from place-holder
1262 0 : sp->setEndElement(placeholder->endElement());
1263 0 : sp->setTrack2(placeholder->track2());
1264 0 : sp->setTick(ctx.tick()); // make sure tick2 will be correct
1265 0 : sp->setTick2(placeholder->tick2());
1266 0 : toNote(placeholder->endElement())->addSpannerBack(sp);
1267 : // remove no longer needed place-holder before reading the new spanner,
1268 : // as reading it also adds it to XML reader list of spanners,
1269 : // which would overwrite the place-holder
1270 0 : ctx.removeSpanner(placeholder);
1271 0 : delete placeholder;
1272 : }
1273 0 : sp->setTrack(note->track());
1274 0 : read400::TRead::readItem(sp, e, ctx);
1275 0 : Staff* staff = note->staff();
1276 : // DISABLE pasting of glissandi into staves with other linked staves
1277 : // because the glissando is not properly cloned into the linked staves
1278 0 : if (ctx.pasteMode() && staff && staff->links() && !staff->links()->empty()) {
1279 0 : ctx.removeSpanner(sp); // read() added the element to the XMLReader: remove it
1280 0 : delete sp;
1281 : } else {
1282 0 : sp->setStartElement(note);
1283 0 : sp->setTick(ctx.tick());
1284 0 : note->addSpannerFor(sp);
1285 0 : sp->setOwnershipParent(note);
1286 0 : adjustPlacement(sp);
1287 : }
1288 371 : } else if (tag == "offset") {
1289 0 : TRead::readItemProperties(note, e, ctx);
1290 371 : } else if (TRead::readItemProperties(note, e, ctx)) {
1291 : } else {
1292 362 : return false;
1293 : }
1294 2910 : return true;
1295 : }
1296 :
1297 : //---------------------------------------------------------
1298 : // ReadStyleName206
1299 : // Retrieve the content of the "style" tag from the
1300 : // String with the content of the whole text tag
1301 : //---------------------------------------------------------
1302 :
1303 127 : static String ReadStyleName206(String xmlTag)
1304 : {
1305 127 : size_t beginIdx = xmlTag.indexOf(u"<style>");
1306 127 : if (beginIdx == muse::nidx) {
1307 20 : return String();
1308 : }
1309 107 : beginIdx += String(u"<style>").size();
1310 :
1311 107 : size_t endIdx = xmlTag.indexOf(u"</style>");
1312 107 : IF_ASSERT_FAILED(endIdx > 0) {
1313 0 : return String();
1314 : }
1315 :
1316 107 : String s = xmlTag.mid(beginIdx, (endIdx - beginIdx));
1317 107 : return s;
1318 107 : }
1319 :
1320 : //---------------------------------------------------------
1321 : // readTextPropertyStyle206
1322 : // This reads only the 'style' tag, so that it can be read
1323 : // before setting anything else.
1324 : //---------------------------------------------------------
1325 :
1326 116 : static bool readTextPropertyStyle206(String xmlTag, ReadContext& ctx, TextBase* t, EngravingItem* be)
1327 : {
1328 116 : String s = ReadStyleName206(xmlTag);
1329 :
1330 116 : if (s.isEmpty()) {
1331 16 : return false;
1332 : }
1333 :
1334 100 : if (!be->isTuplet()) { // Hack
1335 73 : if (excessTextStyles206.find(s) != excessTextStyles206.end()) {
1336 : // Init the text with a style that can't be stored as a user style
1337 : // due to the limit on the number of user styles possible.
1338 : // Use User-1, since it has all the possible user style pids
1339 0 : t->initTextStyleType(TextStyleType::DEFAULT);
1340 0 : std::map<Sid, PropertyValue> styleVals = excessTextStyles206[s];
1341 0 : for (const auto& p : *textStyle(TextStyleType::USER1)) {
1342 0 : if (t->getProperty(p.pid) == t->propertyDefault(p.pid) && styleVals.find(p.sid) != styleVals.end()) {
1343 0 : t->setProperty(p.pid, styleVals[p.sid]);
1344 : }
1345 : }
1346 0 : } else {
1347 : TextStyleType ss;
1348 73 : ss = ctx.lookupUserTextStyle(s);
1349 73 : if (ss == TextStyleType::TEXT_TYPES) {
1350 45 : muse::ByteArray ba = s.toAscii();
1351 45 : ss = TConv::fromXml(ba.constChar(), TextStyleType::DEFAULT);
1352 45 : }
1353 73 : if (ss != TextStyleType::TEXT_TYPES) {
1354 73 : t->initTextStyleType(ss);
1355 : }
1356 : }
1357 : }
1358 :
1359 100 : return true;
1360 116 : }
1361 :
1362 : //---------------------------------------------------------
1363 : // readTextProperties206
1364 : //---------------------------------------------------------
1365 :
1366 292 : static bool readTextProperties206(XmlReader& e, ReadContext& ctx, TextBase* t)
1367 : {
1368 292 : const AsciiStringView tag(e.name());
1369 292 : if (tag == "style") {
1370 100 : e.skipCurrentElement(); // read in readTextPropertyStyle206
1371 192 : } else if (tag == "foregroundColor") { // same as "color" ?
1372 0 : e.skipCurrentElement();
1373 192 : } else if (tag == "frame") {
1374 16 : t->setFrameType(e.readBool() ? FrameType::RECTANGLE : FrameType::NO_FRAME);
1375 16 : t->setPropertyFlags(Pid::FRAME_TYPE, PropertyFlags::UNSTYLED);
1376 176 : } else if (tag == "frameRound") {
1377 0 : read400::TRead::readProperty(t, e, ctx, Pid::FRAME_ROUND);
1378 176 : } else if (tag == "circle") {
1379 0 : if (e.readBool()) {
1380 0 : t->setFrameType(FrameType::CIRCLE);
1381 : } else {
1382 0 : if (t->circle()) {
1383 0 : t->setFrameType(FrameType::RECTANGLE);
1384 : }
1385 : }
1386 0 : t->setPropertyFlags(Pid::FRAME_TYPE, PropertyFlags::UNSTYLED);
1387 176 : } else if (tag == "paddingWidthS") {
1388 0 : read400::TRead::readProperty(t, e, ctx, Pid::FRAME_PADDING);
1389 176 : } else if (tag == "frameWidthS") {
1390 0 : read400::TRead::readProperty(t, e, ctx, Pid::FRAME_WIDTH);
1391 176 : } else if (tag == "frameColor") {
1392 0 : read400::TRead::readProperty(t, e, ctx, Pid::FRAME_FG_COLOR);
1393 176 : } else if (tag == "backgroundColor") {
1394 0 : read400::TRead::readProperty(t, e, ctx, Pid::FRAME_BG_COLOR);
1395 176 : } else if (tag == "halign") {
1396 0 : Align align = t->align();
1397 0 : align.horizontal = TConv::fromXml(e.readAsciiText(), AlignH::LEFT);
1398 0 : t->setAlign(align);
1399 0 : t->setPropertyFlags(Pid::ALIGN, PropertyFlags::UNSTYLED);
1400 0 : t->setPosition(align.horizontal);
1401 0 : t->setPropertyFlags(Pid::POSITION, PropertyFlags::UNSTYLED);
1402 176 : } else if (tag == "valign") {
1403 0 : Align align = t->align();
1404 0 : align.vertical = TConv::fromXml(e.readAsciiText(), AlignV::TOP);
1405 0 : t->setAlign(align);
1406 0 : t->setPropertyFlags(Pid::ALIGN, PropertyFlags::UNSTYLED);
1407 176 : } else if (tag == "pos") {
1408 7 : read400::TRead::readProperty(t, e, ctx, Pid::OFFSET);
1409 7 : if (t->align() == AlignV::TOP) {
1410 2 : t->ryoffset() += .5 * ctx.spatium(); // HACK: bbox is different in 2.x
1411 : }
1412 7 : adjustPlacement(t);
1413 169 : } else if (tag == "subtype") {
1414 16 : e.skipCurrentElement(); // unused
1415 153 : } else if (!read400::TRead::readTextProperties(t, e, ctx)) {
1416 52 : return false;
1417 : }
1418 240 : return true;
1419 : }
1420 :
1421 : //---------------------------------------------------------
1422 : // TextReaderContext206
1423 : // For 2.x files, the style tag could be in a different
1424 : // position with respect to 3.x files. Since seek
1425 : // position is not reliable for readline in QIODevices (for
1426 : // example because of non-single-byte characters in at least
1427 : // one of the fields; some two-byte characters are counted as
1428 : // two single-byte characters and thus the reading could
1429 : // start at the wrong position), a copy of the text tag
1430 : // is created and read in a separate XmlReader, while
1431 : // the text style is extracted from a String containing
1432 : // the whole text xml tag.
1433 : // TextReaderContext206 takes care of this process
1434 : //---------------------------------------------------------
1435 :
1436 : class TextReaderContext206
1437 : {
1438 : XmlReader& origReader;
1439 : XmlReader tagReader;
1440 : String xmlTag;
1441 :
1442 : public:
1443 116 : TextReaderContext206(XmlReader& e)
1444 116 : : origReader(e)
1445 : {
1446 : // Create a new xml document containing only the (text) xml chunk
1447 116 : String name = String::fromAscii(origReader.name().ascii());
1448 116 : String prefix = u"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<" + name + u">";
1449 116 : xmlTag = origReader.readXml();
1450 116 : xmlTag.prepend(prefix);
1451 116 : xmlTag.append(u"</" + name + u">\n");
1452 116 : muse::ByteArray data = xmlTag.toUtf8();
1453 116 : tagReader.setData(data); // Add the xml data to the XmlReader
1454 : // the additional lines are needed to output the correct line number
1455 : // of the original file in case of error
1456 116 : int64_t additionalOffset = origReader.byteOffset() - prefix.toStdString().size(); // Subtracting the 2 new lines that will be added
1457 116 : tagReader.setByteOffsetAdjustment(additionalOffset);
1458 116 : copyProperties(origReader, tagReader);
1459 116 : tagReader.readNextStartElement(); // read up to the first "name" tag
1460 116 : }
1461 :
1462 : // Disable copying the TextReaderContext206
1463 : TextReaderContext206(const TextReaderContext206&) = delete;
1464 : TextReaderContext206& operator=(const TextReaderContext206&) = delete;
1465 :
1466 116 : ~TextReaderContext206()
1467 : {
1468 : // Ensure to copy back the potentially changed properties
1469 : // to the original XmlReader before destruction
1470 116 : copyProperties(tagReader, origReader);
1471 116 : }
1472 :
1473 823 : XmlReader& reader() { return tagReader; }
1474 127 : const String& tag() { return xmlTag; }
1475 : private:
1476 : void copyProperties(XmlReader& original, XmlReader& derived);
1477 : };
1478 :
1479 : //---------------------------------------------------------
1480 : // copyProperties
1481 : // Copy some of the XmlReader properties of an original
1482 : // XmlReader object to a "derived" XmlReader object.
1483 : // This is used for example when using the derived XmlReader
1484 : // to read the element properties of a 2.x text, or to
1485 : // update the base XmlReader object (for example, its
1486 : // link list) after reading the properties of a 2.x text
1487 : //---------------------------------------------------------
1488 :
1489 232 : void TextReaderContext206::copyProperties(XmlReader& original, XmlReader& derived)
1490 : {
1491 232 : derived.setDocName(original.docName());
1492 232 : }
1493 :
1494 : //---------------------------------------------------------
1495 : // convertMScoreFontMarkerSymbols206
1496 : //---------------------------------------------------------
1497 :
1498 12 : static String convertMScoreFontMarkerSymbols206(const String& xmlText)
1499 : {
1500 12 : String s = xmlText;
1501 12 : s.replace(u"\ue177", u"<sym>segno</sym>");
1502 12 : s.replace(u"\ue178", u"<sym>coda</sym>");
1503 12 : s.replace(u"\ue179", u"<sym>codaSquare</sym>");
1504 12 : return s;
1505 0 : }
1506 :
1507 : //---------------------------------------------------------
1508 : // readText206
1509 : //---------------------------------------------------------
1510 :
1511 91 : static void readText206(XmlReader& e, ReadContext& ctx, TextBase* t, EngravingItem* be)
1512 : {
1513 91 : TextReaderContext206 tctx(e);
1514 91 : readTextPropertyStyle206(tctx.tag(), ctx, t, be);
1515 423 : while (tctx.reader().readNextStartElement()) {
1516 241 : if (!readTextProperties206(tctx.reader(), ctx, t)) {
1517 48 : tctx.reader().unknown();
1518 : }
1519 : }
1520 91 : CompatUtils::migrateOffsetPre302(t, ctx.mscVersion());
1521 91 : }
1522 :
1523 : //---------------------------------------------------------
1524 : // read
1525 : //---------------------------------------------------------
1526 :
1527 1 : static void readTempoText(TempoText* t, XmlReader& e, ReadContext& ctx)
1528 : {
1529 1 : TextReaderContext206 tctx(e);
1530 1 : readTextPropertyStyle206(tctx.tag(), ctx, t, t);
1531 4 : while (tctx.reader().readNextStartElement()) {
1532 3 : const AsciiStringView tag(tctx.reader().name());
1533 3 : if (tag == "tempo") {
1534 1 : t->setTempo(tctx.reader().readDouble());
1535 2 : } else if (tag == "followText") {
1536 1 : t->setFollowText(tctx.reader().readInt());
1537 1 : } else if (!readTextProperties206(tctx.reader(), ctx, t)) {
1538 0 : tctx.reader().unknown();
1539 : }
1540 : }
1541 : // check sanity
1542 1 : if (t->xmlText().isEmpty()) {
1543 0 : t->setXmlText(String(u"<sym>metNoteQuarterUp</sym> = %1").arg(int(lrint(t->tempo().toBPM().val))));
1544 0 : t->setVisible(false);
1545 : } else {
1546 1 : t->setXmlText(t->xmlText().replace(u"<sym>unicode", u"<sym>met"));
1547 : }
1548 :
1549 1 : CompatUtils::migrateOffsetPre302(t, ctx.mscVersion());
1550 :
1551 1 : t->resetProperty(Pid::MUSIC_SYMBOL_SIZE);
1552 1 : }
1553 :
1554 : //---------------------------------------------------------
1555 : // readMarker
1556 : //---------------------------------------------------------
1557 :
1558 12 : static void readMarker(Marker* m, XmlReader& e, ReadContext& ctx)
1559 : {
1560 12 : TextReaderContext206 tctx(e);
1561 12 : readTextPropertyStyle206(tctx.tag(), ctx, m, m);
1562 12 : MarkerType mt = MarkerType::SEGNO;
1563 :
1564 48 : while (tctx.reader().readNextStartElement()) {
1565 36 : const AsciiStringView tag(tctx.reader().name());
1566 36 : if (tag == "label") {
1567 12 : AsciiStringView s(tctx.reader().readAsciiText());
1568 12 : m->setLabel(String::fromAscii(s.ascii()));
1569 12 : mt = TConv::fromXml(s, MarkerType::USER);
1570 24 : } else if (!readTextProperties206(tctx.reader(), ctx, m)) {
1571 0 : tctx.reader().unknown();
1572 : }
1573 : }
1574 12 : m->setXmlText(convertMScoreFontMarkerSymbols206(m->xmlText()));
1575 12 : m->setMarkerType(mt);
1576 :
1577 12 : CompatUtils::migrateOffsetPre302(m, ctx.mscVersion());
1578 12 : }
1579 :
1580 : //---------------------------------------------------------
1581 : // readDynamic
1582 : //---------------------------------------------------------
1583 :
1584 1 : static void readDynamic(Dynamic* d, XmlReader& e, ReadContext& ctx)
1585 : {
1586 1 : TextReaderContext206 tctx(e);
1587 1 : readTextPropertyStyle206(tctx.tag(), ctx, d, d);
1588 3 : while (tctx.reader().readNextStartElement()) {
1589 2 : const AsciiStringView tag = tctx.reader().name();
1590 2 : if (tag == "subtype") {
1591 1 : d->setDynamicType(tctx.reader().readText());
1592 1 : } else if (tag == "velocity") {
1593 0 : d->setVelocity(tctx.reader().readInt());
1594 1 : } else if (tag == "dynType") {
1595 0 : d->setVoiceAssignment(Read206::readDynamicRange(tctx.reader().readInt()));
1596 1 : } else if (tag == "size") {
1597 0 : e.skipCurrentElement();
1598 1 : } else if (!readTextProperties206(tctx.reader(), ctx, d)) {
1599 0 : tctx.reader().unknown();
1600 : }
1601 : }
1602 1 : d->setSize(10.0);
1603 1 : if (d->xmlText().contains(u"<sym>") && !d->xmlText().contains(u"<font")) {
1604 1 : d->setAlign(Align(AlignH::HCENTER, AlignV::BASELINE));
1605 : }
1606 1 : CompatUtils::migrateOffsetPre302(d, ctx.mscVersion());
1607 1 : }
1608 :
1609 : //---------------------------------------------------------
1610 : // readTuplet
1611 : //---------------------------------------------------------
1612 :
1613 11 : static void readTuplet206(Tuplet* tuplet, XmlReader& e, ReadContext& ctx)
1614 : {
1615 64 : while (e.readNextStartElement()) {
1616 53 : const AsciiStringView tag(e.name());
1617 53 : if (tag == "Number") {
1618 11 : Text* _number = Factory::createText(tuplet);
1619 11 : _number->setComposition(true);
1620 11 : tuplet->setNumber(_number);
1621 : // _number reads property defaults from parent tuplet as "composition" is set:
1622 11 : tuplet->resetNumberProperty();
1623 11 : readText206(e, ctx, _number, tuplet);
1624 11 : _number->setVisible(tuplet->visible()); //?? override saved property
1625 11 : _number->setColor(tuplet->color());
1626 11 : _number->setTrack(tuplet->track());
1627 : // move property flags from _number
1628 66 : for (auto p : { Pid::FONT_FACE, Pid::FONT_SIZE, Pid::FONT_STYLE, Pid::ALIGN, Pid::SIZE_SPATIUM_DEPENDENT }) {
1629 55 : tuplet->setPropertyFlags(p, _number->propertyFlags(p));
1630 : }
1631 42 : } else if (!Read206::readTupletProperties206(e, ctx, tuplet)) {
1632 0 : e.unknown();
1633 : }
1634 : }
1635 11 : Fraction r = (tuplet->ratio() == Fraction(1, 1)) ? tuplet->ratio() : tuplet->ratio().reduced();
1636 11 : Fraction f(r.denominator(), tuplet->baseLen().fraction().denominator());
1637 11 : tuplet->setTicks(f.reduced());
1638 11 : }
1639 :
1640 : //---------------------------------------------------------
1641 : // readLyrics
1642 : //---------------------------------------------------------
1643 :
1644 1 : static void readLyrics(Lyrics* lyrics, XmlReader& e, ReadContext& ctx)
1645 : {
1646 1 : int iEndTick = 0; // used for backward compatibility
1647 1 : Text* _verseNumber = 0;
1648 :
1649 2 : while (e.readNextStartElement()) {
1650 1 : const AsciiStringView tag(e.name());
1651 1 : if (tag == "endTick") {
1652 : // store <endTick> tag value until a <ticks> tag has been read
1653 : // which positions this lyrics element in the score
1654 0 : iEndTick = e.readInt();
1655 1 : } else if (tag == "Number") {
1656 0 : _verseNumber = Factory::createText(lyrics);
1657 0 : readText206(e, ctx, _verseNumber, lyrics);
1658 0 : _verseNumber->setOwnershipParent(lyrics);
1659 1 : } else if (tag == "style") {
1660 0 : e.readText(); // ignore style
1661 1 : } else if (!read400::TRead::readProperties(lyrics, e, ctx)) {
1662 0 : e.unknown();
1663 : }
1664 : }
1665 :
1666 : // if any endTick, make it relative to current tick
1667 1 : if (iEndTick) {
1668 0 : lyrics->setTicks(Fraction::fromTicks(iEndTick) - ctx.tick());
1669 : }
1670 1 : if (_verseNumber) {
1671 : // TODO: add text to main text
1672 0 : delete _verseNumber;
1673 : }
1674 1 : lyrics->setAutoplace(true);
1675 :
1676 1 : if (!lyrics->offset().isNull() && !ctx.pasteMode()) {
1677 : // fix offset for pre-3.1 scores
1678 : // 2.x and earlier: y offset was relative to staff; x offset was relative to center of notehead
1679 0 : lyrics->rxoffset() -= lyrics->symWidth(SymId::noteheadBlack) * 0.5;
1680 : //lyrics->ryoffset() -= lyrics->placeBelow() && lyrics->staff() ? lyrics->staff()->height() : 0.0;
1681 : // temporarily set placement to above, since the original offset is relative to top of staff
1682 : // depend on adjustPlacement() to change the placement if appropriate
1683 0 : lyrics->setPlacement(PlacementV::ABOVE);
1684 0 : adjustPlacement(lyrics);
1685 : }
1686 1 : CompatUtils::migrateOffsetPre302(lyrics, ctx.mscVersion());
1687 1 : }
1688 :
1689 742 : bool Read206::readDurationProperties206(XmlReader& e, ReadContext& ctx, DurationElement* de)
1690 : {
1691 742 : if (e.name() == "Tuplet") {
1692 136 : int i = e.readInt();
1693 136 : Tuplet* t = ctx.findTuplet(i);
1694 136 : if (!t) {
1695 0 : LOGD("readDurationProperties206(): Tuplet id %d not found", i);
1696 : }
1697 136 : if (t) {
1698 136 : de->setTuplet(t);
1699 136 : if (!ctx.undoStackActive()) { // HACK, also added in Undo::AddElement()
1700 136 : t->add(de);
1701 : }
1702 : }
1703 136 : return true;
1704 606 : } else if (TRead::readItemProperties(de, e, ctx)) {
1705 73 : return true;
1706 : }
1707 533 : return false;
1708 : }
1709 :
1710 116 : bool Read206::readTupletProperties206(XmlReader& e, ReadContext& ctx, Tuplet* de)
1711 : {
1712 116 : const AsciiStringView tag(e.name());
1713 :
1714 116 : if (read400::TRead::readStyledProperty(de, tag, e, ctx)) {
1715 102 : } else if (tag == "normalNotes") {
1716 27 : de->setProperty(Pid::NORMAL_NOTES, e.readInt());
1717 75 : } else if (tag == "actualNotes") {
1718 27 : de->setProperty(Pid::ACTUAL_NOTES, e.readInt());
1719 48 : } else if (tag == "p1") {
1720 0 : de->setProperty(Pid::P1, PropertyValue::fromValue(e.readPoint() * ctx.spatium()));
1721 48 : } else if (tag == "p2") {
1722 0 : de->setProperty(Pid::P2, PropertyValue::fromValue(e.readPoint() * ctx.spatium()));
1723 48 : } else if (tag == "baseNote") {
1724 27 : de->setBaseLen(TDuration(TConv::fromXml(e.readAsciiText(), DurationType::V_INVALID)));
1725 21 : } else if (tag == "Number") {
1726 16 : Text* _number = Factory::createText(de);
1727 16 : de->setNumber(_number);
1728 16 : _number->setComposition(true);
1729 : // _number->setSubStyleId(SubStyleId::TUPLET);
1730 : // initSubStyle(SubStyleId::TUPLET); // hack: initialize number
1731 80 : for (auto p : { Pid::FONT_FACE, Pid::FONT_SIZE, Pid::FONT_STYLE, Pid::ALIGN }) {
1732 64 : _number->resetProperty(p);
1733 : }
1734 16 : readText206(e, ctx, _number, de);
1735 16 : _number->setVisible(de->visible()); //?? override saved property
1736 16 : _number->setTrack(de->track());
1737 : // move property flags from _number
1738 80 : for (auto p : { Pid::FONT_FACE, Pid::FONT_SIZE, Pid::FONT_STYLE, Pid::ALIGN }) {
1739 64 : de->setPropertyFlags(p, _number->propertyFlags(p));
1740 : }
1741 5 : } else if (!readDurationProperties206(e, ctx, de)) {
1742 0 : return false;
1743 : }
1744 116 : return true;
1745 : }
1746 :
1747 3220 : bool Read206::readChordRestProperties206(XmlReader& e, ReadContext& ctx, ChordRest* ch)
1748 : {
1749 3220 : const AsciiStringView tag(e.name());
1750 :
1751 3220 : if (tag == "durationType") {
1752 1945 : ch->setDurationType(TConv::fromXml(e.readAsciiText(), DurationType::V_QUARTER));
1753 1945 : if (ch->actualDurationType().type() != DurationType::V_MEASURE) {
1754 1436 : if (ctx.mscVersion() < 112 && (ch->isRest())
1755 0 : && // for backward compatibility, convert V_WHOLE rests to V_MEASURE
1756 : // if long enough to fill a measure.
1757 : // OTOH, freshly created (un-initialized) rests have numerator == 0 (< 4/4)
1758 : // (see Fraction() constructor in fraction.h; this happens for instance
1759 : // when pasting selection from clipboard): they should not be converted
1760 0 : ch->ticks().numerator() != 0
1761 1436 : && // rest durations are initialized to full measure duration when
1762 : // created upon reading the <Rest> tag (see Measure::read() )
1763 : // so a V_WHOLE rest in a measure of 4/4 or less => V_MEASURE
1764 1436 : (ch->actualDurationType() == DurationType::V_WHOLE && ch->ticks() <= Fraction(4, 4))) {
1765 : // old pre 2.0 scores: convert
1766 0 : ch->setDurationType(DurationType::V_MEASURE);
1767 : } else { // not from old score: set duration fraction from duration type
1768 1436 : ch->setTicks(ch->actualDurationType().fraction());
1769 : }
1770 : }
1771 1275 : } else if (tag == "BeamMode") {
1772 : // 206 used begin32/begin64 for beam mode
1773 : // 410 uses begin16/begin32
1774 2 : auto txt = e.readAsciiText();
1775 2 : if (txt == "begin64") {
1776 0 : txt = "begin32";
1777 2 : } else if (txt == "begin32") {
1778 0 : txt = "begin16";
1779 : }
1780 2 : ch->setBeamMode(TConv::fromXml(txt, BeamMode::AUTO));
1781 1273 : } else if (tag == "Articulation") {
1782 215 : EngravingItem* el = readArticulation(ch, e, ctx);
1783 215 : if (el->isFermata()) {
1784 31 : ch->segment()->add(el);
1785 : } else {
1786 184 : ch->add(el);
1787 : }
1788 1058 : } else if (tag == "leadingSpace" || tag == "trailingSpace") {
1789 0 : LOGD("ChordRest: %s obsolete", tag.ascii());
1790 0 : e.skipCurrentElement();
1791 1058 : } else if (tag == "Beam") {
1792 98 : int id = e.readInt();
1793 98 : Beam* beam = ctx.findBeam(id);
1794 98 : if (beam) {
1795 98 : beam->add(ch); // also calls ch->setBeam(beam)
1796 : } else {
1797 0 : LOGD("Beam id %d not found", id);
1798 : }
1799 960 : } else if (tag == "small") {
1800 0 : ch->setSmall(e.readInt());
1801 960 : } else if (tag == "duration") {
1802 183 : ch->setTicks(e.readFraction());
1803 777 : } else if (tag == "ticklen") { // obsolete (version < 1.12)
1804 0 : int mticks = ctx.compatTimeSigMap()->timesig(ctx.tick()).timesig().ticks();
1805 0 : int i = e.readInt();
1806 0 : if (i == 0) {
1807 0 : i = mticks;
1808 : }
1809 0 : if ((ch->isRest()) && (mticks == i)) {
1810 0 : ch->setDurationType(DurationType::V_MEASURE);
1811 0 : ch->setTicks(Fraction::fromTicks(i));
1812 : } else {
1813 0 : Fraction f = Fraction::fromTicks(i);
1814 0 : ch->setTicks(f);
1815 0 : ch->setDurationType(TDuration(f));
1816 : }
1817 777 : } else if (tag == "dots") {
1818 8 : ch->setDots(e.readInt());
1819 769 : } else if (tag == "move") {
1820 0 : ch->setStaffMove(e.readInt());
1821 769 : } else if (tag == "Slur") {
1822 32 : int id = e.intAttribute("id");
1823 32 : if (id == 0) {
1824 32 : id = e.intAttribute("number"); // obsolete
1825 : }
1826 32 : Spanner* spanner = ctx.findSpanner(id);
1827 32 : String atype(e.attribute("type"));
1828 :
1829 32 : if (!spanner) {
1830 0 : if (atype == "stop") {
1831 0 : SpannerValues sv;
1832 0 : sv.spannerId = id;
1833 0 : sv.track2 = ch->track();
1834 0 : sv.tick2 = ctx.tick();
1835 0 : ctx.addSpannerValues(sv);
1836 0 : } else if (atype == "start") {
1837 0 : LOGD("spanner: start without spanner");
1838 : }
1839 : } else {
1840 32 : if (atype == "start") {
1841 16 : if (spanner->ticks() > Fraction(0, 1) && spanner->tick() == Fraction(-1, 1)) { // stop has been read first
1842 3 : spanner->setTicks(spanner->ticks() - ctx.tick() - Fraction::eps());
1843 : }
1844 16 : spanner->setTick(ctx.tick());
1845 16 : spanner->setTrack(ch->track());
1846 16 : if (spanner->isSlur()) {
1847 16 : spanner->setStartElement(ch);
1848 : }
1849 16 : if (ctx.pasteMode()) {
1850 0 : for (EngravingObject* el : spanner->linkList()) {
1851 0 : if (el == spanner) {
1852 0 : continue;
1853 : }
1854 0 : Spanner* ls = toSpanner(el);
1855 0 : ls->setTick(spanner->tick());
1856 0 : for (EngravingObject* ee : ch->linkList()) {
1857 0 : ChordRest* cr = toChordRest(ee);
1858 0 : if (cr->staffIdx() == ls->staffIdx()) {
1859 0 : ls->setTrack(cr->track());
1860 0 : if (ls->isSlur()) {
1861 0 : ls->setStartElement(cr);
1862 : }
1863 0 : break;
1864 : }
1865 0 : }
1866 0 : }
1867 : }
1868 16 : } else if (atype == "stop") {
1869 16 : spanner->setTick2(ctx.tick());
1870 16 : spanner->setTrack2(ch->track());
1871 16 : if (spanner->isSlur()) {
1872 16 : spanner->setEndElement(ch);
1873 : }
1874 16 : ChordRest* start = toChordRest(spanner->startElement());
1875 16 : if (start) {
1876 13 : spanner->setTrack(start->track());
1877 : }
1878 16 : if (ctx.pasteMode()) {
1879 0 : for (EngravingObject* el : spanner->linkList()) {
1880 0 : if (el == spanner) {
1881 0 : continue;
1882 : }
1883 0 : Spanner* ls = toSpanner(el);
1884 0 : ls->setTick2(spanner->tick2());
1885 0 : for (EngravingObject* ee : ch->linkList()) {
1886 0 : ChordRest* cr = toChordRest(ee);
1887 0 : if (cr->staffIdx() == ls->staffIdx()) {
1888 0 : ls->setTrack2(cr->track());
1889 0 : if (ls->isSlur()) {
1890 0 : ls->setEndElement(cr);
1891 : }
1892 0 : break;
1893 : }
1894 0 : }
1895 0 : }
1896 : }
1897 : } else {
1898 0 : LOGD("readChordRestProperties206(): unknown Slur type <%s>", muPrintable(atype));
1899 : }
1900 : }
1901 32 : e.readNext();
1902 769 : } else if (tag == "Lyrics") {
1903 0 : Lyrics* l = Factory::createLyrics(ch);
1904 0 : l->setTrack(ctx.track());
1905 0 : readLyrics(l, e, ctx);
1906 0 : ch->add(l);
1907 737 : } else if (tag == "pos") {
1908 0 : PointF pt = e.readPoint();
1909 0 : ch->setOffset(pt * ch->spatium());
1910 737 : } else if (ch->isRest() && tag == "Image") {
1911 0 : if (MScore::noImages) {
1912 0 : e.skipCurrentElement();
1913 : } else {
1914 0 : Image* image = new Image(ch);
1915 0 : image->setTrack(ctx.track());
1916 0 : read400::TRead::read(image, e, ctx);
1917 0 : ch->add(image);
1918 : }
1919 737 : } else if (!readDurationProperties206(e, ctx, ch)) {
1920 533 : return false;
1921 : }
1922 2687 : return true;
1923 : }
1924 :
1925 2324 : bool Read206::readChordProperties206(XmlReader& e, ReadContext& ctx, Chord* ch)
1926 : {
1927 2324 : const AsciiStringView tag(e.name());
1928 :
1929 2324 : if (tag == "Note") {
1930 0 : Note* note = Factory::createNote(ch);
1931 : // the note needs to know the properties of the track it belongs to
1932 0 : note->setTrack(ch->track());
1933 0 : readNote206(note, e, ctx);
1934 0 : ch->add(note);
1935 2324 : } else if (readChordRestProperties206(e, ctx, ch)) {
1936 455 : } else if (tag == "Stem") {
1937 1 : Stem* s = Factory::createStem(ch);
1938 1 : read400::TRead::read(s, e, ctx);
1939 1 : ch->add(s);
1940 454 : } else if (tag == "Hook") {
1941 0 : Hook* hook = new Hook(ch);
1942 0 : read400::TRead::read(hook, e, ctx);
1943 0 : ch->add(hook);
1944 454 : } else if (tag == "appoggiatura") {
1945 0 : ch->setNoteType(NoteType::APPOGGIATURA);
1946 0 : e.readNext();
1947 454 : } else if (tag == "acciaccatura") {
1948 0 : ch->setNoteType(NoteType::ACCIACCATURA);
1949 0 : e.readNext();
1950 454 : } else if (tag == "grace4") {
1951 0 : ch->setNoteType(NoteType::GRACE4);
1952 0 : e.readNext();
1953 454 : } else if (tag == "grace16") {
1954 0 : ch->setNoteType(NoteType::GRACE16);
1955 0 : e.readNext();
1956 454 : } else if (tag == "grace32") {
1957 0 : ch->setNoteType(NoteType::GRACE32);
1958 0 : e.readNext();
1959 454 : } else if (tag == "grace8after") {
1960 0 : ch->setNoteType(NoteType::GRACE8_AFTER);
1961 0 : e.readNext();
1962 454 : } else if (tag == "grace16after") {
1963 0 : ch->setNoteType(NoteType::GRACE16_AFTER);
1964 0 : e.readNext();
1965 454 : } else if (tag == "grace32after") {
1966 0 : ch->setNoteType(NoteType::GRACE32_AFTER);
1967 0 : e.readNext();
1968 454 : } else if (tag == "StemSlash") {
1969 0 : StemSlash* ss = Factory::createStemSlash(ch);
1970 0 : read400::TRead::read(ss, e, ctx);
1971 0 : ch->add(ss);
1972 454 : } else if (read400::TRead::readProperty(ch, tag, e, ctx, Pid::STEM_DIRECTION)) {
1973 362 : } else if (tag == "noStem") {
1974 0 : ch->setNoStem(e.readInt());
1975 362 : } else if (tag == "Arpeggio") {
1976 0 : Arpeggio* arpeggio = Factory::createArpeggio(ch);
1977 0 : arpeggio->setTrack(ch->track());
1978 0 : read400::TRead::read(arpeggio, e, ctx);
1979 0 : ch->add(arpeggio);
1980 : }
1981 : // old glissando format, chord-to-chord, attached to its final chord
1982 362 : else if (tag == "Glissando") {
1983 : // the measure we are reading is not inserted in the score yet
1984 : // as well as, possibly, the glissando intended initial chord;
1985 : // then we cannot fully link the glissando right now;
1986 : // temporarily attach the glissando to its final note as a back spanner;
1987 : // after the whole score is read, Score::connectTies() will look for
1988 : // the suitable initial note
1989 0 : Note* finalNote = ch->upNote();
1990 0 : Glissando* gliss = Factory::createGlissando(ctx.dummy());
1991 0 : read400::TRead::read(gliss, e, ctx);
1992 0 : gliss->setStartElement(nullptr);
1993 0 : gliss->setEndElement(nullptr);
1994 : // in TAB, use straight line with no text
1995 0 : if (ctx.staff(static_cast<int>(ctx.track()) >> 2)->isTabStaff(ch->tick())) {
1996 0 : gliss->setGlissandoType(GlissandoType::STRAIGHT);
1997 0 : gliss->setShowText(false);
1998 : }
1999 0 : finalNote->addSpannerBack(gliss);
2000 362 : } else if (tag == "Tremolo") {
2001 0 : read400::TRead::TremoloCompat tcompat;
2002 0 : tcompat.parent = ch;
2003 0 : read400::TRead::read(tcompat, e, ctx);
2004 0 : if (tcompat.two) {
2005 0 : tcompat.two->setOwnershipParent(ch);
2006 0 : tcompat.two->setDurationType(ch->durationType());
2007 0 : ch->setTremoloTwoChord(tcompat.two, false);
2008 0 : } else if (tcompat.single) {
2009 0 : tcompat.single->setOwnershipParent(ch);
2010 0 : tcompat.single->setDurationType(ch->durationType());
2011 0 : ch->setTremoloSingleChord(tcompat.single);
2012 : } else {
2013 0 : UNREACHABLE;
2014 : }
2015 362 : } else if (tag == "tickOffset") { // obsolete
2016 362 : } else if (tag == "ChordLine") {
2017 0 : ChordLine* cl = Factory::createChordLine(ch);
2018 0 : read400::TRead::read(cl, e, ctx);
2019 0 : cl->setOffset(0.0, 0.0);
2020 0 : ch->add(cl);
2021 : } else {
2022 362 : return false;
2023 : }
2024 1962 : return true;
2025 : }
2026 :
2027 : //---------------------------------------------------------
2028 : // convertDoubleArticulations
2029 : // Replace double articulations with proper SMuFL
2030 : // symbols which were not available for use prior to 3.0
2031 : //---------------------------------------------------------
2032 :
2033 906 : static void convertDoubleArticulations(Chord* chord)
2034 : {
2035 906 : std::vector<Articulation*> pairableArticulations;
2036 1090 : for (Articulation* a : chord->articulations()) {
2037 342 : if (a->isStaccato() || a->isTenuto()
2038 342 : || a->isAccent() || a->isMarcato()) {
2039 76 : pairableArticulations.push_back(a);
2040 : }
2041 : }
2042 906 : if (pairableArticulations.size() != 2) {
2043 : // Do not replace triple articulation if this happens
2044 878 : return;
2045 : }
2046 :
2047 28 : SymId newSymId = SymId::noSym;
2048 56 : for (int i = 0; i < 2; ++i) {
2049 56 : if (newSymId != SymId::noSym) {
2050 28 : break;
2051 : }
2052 28 : Articulation* ai = pairableArticulations[i];
2053 28 : Articulation* aj = pairableArticulations[(i == 0) ? 1 : 0];
2054 28 : if (ai->isStaccato()) {
2055 18 : if (aj->isAccent()) {
2056 6 : newSymId = SymId::articAccentStaccatoAbove;
2057 12 : } else if (aj->isMarcato()) {
2058 6 : newSymId = SymId::articMarcatoStaccatoAbove;
2059 6 : } else if (aj->isTenuto()) {
2060 6 : newSymId = SymId::articTenutoStaccatoAbove;
2061 : }
2062 10 : } else if (ai->isTenuto()) {
2063 10 : if (aj->isAccent()) {
2064 4 : newSymId = SymId::articTenutoAccentAbove;
2065 6 : } else if (aj->isMarcato()) {
2066 6 : newSymId = SymId::articMarcatoTenutoAbove;
2067 : }
2068 : }
2069 : }
2070 :
2071 28 : if (newSymId != SymId::noSym) {
2072 : // We reuse old articulation and change symbol ID
2073 : // rather than constructing a new articulation
2074 : // in order to preserve its other properties.
2075 28 : Articulation* newArtic = pairableArticulations[0];
2076 84 : for (Articulation* a : pairableArticulations) {
2077 56 : chord->remove(a);
2078 56 : if (a != newArtic) {
2079 28 : delete a;
2080 : }
2081 : }
2082 :
2083 28 : ArticulationAnchor anchor = newArtic->anchor();
2084 28 : newArtic->setSymId(newSymId);
2085 28 : newArtic->setAnchor(anchor);
2086 28 : chord->add(newArtic);
2087 : }
2088 906 : }
2089 :
2090 : //---------------------------------------------------------
2091 : // fixTies
2092 : //---------------------------------------------------------
2093 :
2094 906 : static void fixTies(Chord* chord)
2095 : {
2096 906 : std::vector<Note*> notes;
2097 1892 : for (Note* note : chord->notes()) {
2098 986 : Tie* tie = note->tieBack();
2099 986 : if (tie && tie->startNote()->pitch() != note->pitch()) {
2100 0 : notes.push_back(tie->startNote());
2101 : }
2102 : }
2103 906 : for (Note* note : notes) {
2104 0 : Note* endNote = chord->findNote(note->pitch());
2105 0 : Note* oldNote = note->tieFor()->endNote();
2106 0 : if (oldNote) {
2107 0 : oldNote->setTieBack(nullptr);
2108 : }
2109 0 : note->tieFor()->setEndNote(endNote);
2110 : }
2111 906 : }
2112 :
2113 : //---------------------------------------------------------
2114 : // readChord
2115 : //---------------------------------------------------------
2116 :
2117 906 : static void readChord(Chord* chord, XmlReader& e, ReadContext& ctx)
2118 : {
2119 3522 : while (e.readNextStartElement()) {
2120 2616 : const AsciiStringView tag(e.name());
2121 2616 : if (tag == "Note") {
2122 986 : Note* note = Factory::createNote(chord);
2123 : // the note needs to know the properties of the track it belongs to
2124 986 : note->setTrack(chord->track());
2125 986 : readNote206(note, e, ctx);
2126 986 : chord->add(note);
2127 1630 : } else if (tag == "Stem") {
2128 0 : Stem* stem = Factory::createStem(chord);
2129 0 : while (e.readNextStartElement()) {
2130 0 : const AsciiStringView t(e.name());
2131 0 : if (t == "subtype") { // obsolete
2132 0 : e.skipCurrentElement();
2133 0 : } else if (!read400::TRead::readProperties(stem, e, ctx)) {
2134 0 : e.unknown();
2135 : }
2136 : }
2137 0 : chord->add(stem);
2138 1630 : } else if (tag == "Lyrics") {
2139 1 : Lyrics* lyrics = Factory::createLyrics(chord);
2140 1 : lyrics->setTrack(ctx.track());
2141 1 : readLyrics(lyrics, e, ctx);
2142 1 : chord->add(lyrics);
2143 1629 : } else if (Read206::readChordProperties206(e, ctx, chord)) {
2144 : } else {
2145 362 : e.unknown();
2146 : }
2147 : }
2148 906 : convertDoubleArticulations(chord);
2149 906 : fixTies(chord);
2150 906 : }
2151 :
2152 : //---------------------------------------------------------
2153 : // readRest
2154 : //---------------------------------------------------------
2155 :
2156 239 : static void readRest(Rest* rest, XmlReader& e, ReadContext& ctx)
2157 : {
2158 985 : while (e.readNextStartElement()) {
2159 507 : if (!Read206::readChordRestProperties206(e, ctx, rest)) {
2160 78 : e.unknown();
2161 : }
2162 : }
2163 239 : }
2164 :
2165 : //---------------------------------------------------------
2166 : // readTextLineProperties
2167 : //---------------------------------------------------------
2168 :
2169 18 : static bool readTextLineProperties(XmlReader& e, ReadContext& ctx, TextLineBase* tl)
2170 : {
2171 18 : const AsciiStringView tag(e.name());
2172 :
2173 18 : if (tag == "beginText") {
2174 5 : Text* text = Factory::createText(ctx.dummy(), TextStyleType::DEFAULT, false);
2175 5 : readText206(e, ctx, text, tl);
2176 5 : tl->setBeginText(text->xmlText());
2177 5 : tl->setPropertyFlags(Pid::BEGIN_TEXT, PropertyFlags::UNSTYLED);
2178 5 : delete text;
2179 13 : } else if (tag == "continueText") {
2180 3 : Text* text = Factory::createText(ctx.dummy(), TextStyleType::DEFAULT, false);
2181 3 : readText206(e, ctx, text, tl);
2182 3 : tl->setContinueText(text->xmlText());
2183 3 : tl->setPropertyFlags(Pid::CONTINUE_TEXT, PropertyFlags::UNSTYLED);
2184 3 : delete text;
2185 10 : } else if (tag == "endText") {
2186 0 : Text* text = Factory::createText(ctx.dummy(), TextStyleType::DEFAULT, false);
2187 0 : readText206(e, ctx, text, tl);
2188 0 : tl->setEndText(text->xmlText());
2189 0 : tl->setPropertyFlags(Pid::END_TEXT, PropertyFlags::UNSTYLED);
2190 0 : delete text;
2191 10 : } else if (tag == "beginHook") {
2192 0 : tl->setBeginHookType(e.readBool() ? HookType::HOOK_90 : HookType::NONE);
2193 10 : } else if (tag == "endHook") {
2194 3 : tl->setEndHookType(e.readBool() ? HookType::HOOK_90 : HookType::NONE);
2195 7 : } else if (tag == "beginHookType") {
2196 0 : tl->setBeginHookType(e.readInt() == 0 ? HookType::HOOK_90 : HookType::HOOK_45);
2197 7 : } else if (tag == "endHookType") {
2198 0 : tl->setEndHookType(e.readInt() == 0 ? HookType::HOOK_90 : HookType::HOOK_45);
2199 7 : } else if (!read400::TRead::readProperties(tl, e, ctx)) {
2200 2 : return false;
2201 : }
2202 :
2203 16 : return true;
2204 : }
2205 :
2206 : //---------------------------------------------------------
2207 : // readVolta206
2208 : //---------------------------------------------------------
2209 :
2210 1 : static void readVolta206(XmlReader& e, ReadContext& ctx, Volta* volta)
2211 : {
2212 4 : while (e.readNextStartElement()) {
2213 3 : const AsciiStringView tag(e.name());
2214 3 : if (tag == "endings") {
2215 1 : String s = e.readText();
2216 1 : StringList sl = s.split(u',', muse::SkipEmptyParts);
2217 1 : volta->endings().clear();
2218 2 : for (const String& l : sl) {
2219 1 : int i = l.simplified().toInt();
2220 1 : volta->endings().push_back(i);
2221 : }
2222 3 : } else if (tag == "lineWidth") {
2223 0 : volta->setLineWidth(Spatium(e.readDouble()));
2224 2 : } else if (!readTextLineProperties(e, ctx, volta)) {
2225 0 : e.unknown();
2226 : }
2227 : }
2228 1 : CompatUtils::resetHookHeightSign(volta);
2229 1 : adjustPlacement(volta);
2230 1 : CompatUtils::migrateOffsetPre302(volta, ctx.mscVersion());
2231 1 : }
2232 :
2233 : //---------------------------------------------------------
2234 : // readPedal
2235 : //---------------------------------------------------------
2236 :
2237 1 : static void readPedal(XmlReader& e, ReadContext& ctx, Pedal* pedal)
2238 : {
2239 1 : bool beginTextTag = false;
2240 1 : bool continueTextTag = false;
2241 1 : bool endTextTag = false;
2242 :
2243 6 : while (e.readNextStartElement()) {
2244 5 : const AsciiStringView tag(e.name());
2245 5 : if (readTextLineProperties(e, ctx, pedal)) {
2246 5 : beginTextTag = beginTextTag || tag == "beginText";
2247 5 : continueTextTag = continueTextTag || tag == "continueText";
2248 5 : endTextTag = endTextTag || tag == "endText";
2249 : } else {
2250 0 : e.unknown();
2251 : }
2252 : }
2253 :
2254 : // Set to the 206 defaults if no value was specified;
2255 : // or follow the new style setting if the specified value matches it
2256 1 : if (!beginTextTag) {
2257 0 : pedal->setBeginText(String());
2258 0 : pedal->setPropertyFlags(Pid::BEGIN_TEXT, PropertyFlags::UNSTYLED);
2259 1 : } else if (pedal->beginText() == pedal->propertyDefault(Pid::BEGIN_TEXT).value<String>()) {
2260 1 : pedal->setPropertyFlags(Pid::BEGIN_TEXT, PropertyFlags::STYLED);
2261 : }
2262 1 : if (!continueTextTag) {
2263 0 : pedal->setContinueText(String());
2264 0 : pedal->setPropertyFlags(Pid::CONTINUE_TEXT, PropertyFlags::UNSTYLED);
2265 1 : } else if (pedal->continueText() == pedal->propertyDefault(Pid::CONTINUE_TEXT).value<String>()) {
2266 1 : pedal->setPropertyFlags(Pid::CONTINUE_TEXT, PropertyFlags::STYLED);
2267 : }
2268 1 : if (!endTextTag) {
2269 1 : pedal->setEndText(String());
2270 1 : pedal->setPropertyFlags(Pid::END_TEXT, PropertyFlags::UNSTYLED);
2271 0 : } else if (pedal->endText() == pedal->propertyDefault(Pid::END_TEXT).value<String>()) {
2272 0 : pedal->setPropertyFlags(Pid::END_TEXT, PropertyFlags::STYLED);
2273 : }
2274 :
2275 1 : CompatUtils::resetHookHeightSign(pedal);
2276 1 : adjustPlacement(pedal);
2277 1 : CompatUtils::migrateOffsetPre302(pedal, ctx.mscVersion());
2278 1 : }
2279 :
2280 : //---------------------------------------------------------
2281 : // readOttava
2282 : //---------------------------------------------------------
2283 :
2284 1 : static void readOttava(XmlReader& e, ReadContext& ctx, Ottava* ottava)
2285 : {
2286 2 : while (e.readNextStartElement()) {
2287 1 : const AsciiStringView tag(e.name());
2288 1 : if (tag == "subtype") {
2289 1 : String s = e.readText();
2290 : bool ok;
2291 1 : int idx = s.toInt(&ok);
2292 1 : if (!ok) {
2293 1 : idx = 0; // OttavaType::OTTAVA_8VA;
2294 1 : int i = 0;
2295 2 : for (auto p : { u"8va", u"8vb", u"15ma", u"15mb", u"22ma", u"22mb" }) {
2296 2 : if (p == s) {
2297 1 : idx = i;
2298 1 : break;
2299 : }
2300 1 : ++i;
2301 : }
2302 : }
2303 1 : ottava->setOttavaType(OttavaType(idx));
2304 1 : } else if (tag == "numbersOnly") {
2305 0 : ottava->setNumbersOnly(e.readBool());
2306 0 : } else if (!readTextLineProperties(e, ctx, ottava)) {
2307 0 : e.unknown();
2308 : }
2309 : }
2310 1 : ottava->styleChanged();
2311 1 : CompatUtils::resetHookHeightSign(ottava);
2312 1 : adjustPlacement(ottava);
2313 1 : CompatUtils::migrateOffsetPre302(ottava, ctx.mscVersion());
2314 1 : }
2315 :
2316 3 : void Read206::readHairpin206(XmlReader& e, ReadContext& ctx, Hairpin* h)
2317 : {
2318 3 : bool useText = false;
2319 13 : while (e.readNextStartElement()) {
2320 10 : const AsciiStringView tag(e.name());
2321 10 : if (tag == "subtype") {
2322 2 : h->setHairpinType(HairpinType(e.readInt()));
2323 8 : } else if (tag == "lineWidth") {
2324 0 : h->setLineWidth(Spatium(e.readDouble()));
2325 : // lineWidthStyle = PropertyFlags::UNSTYLED;
2326 8 : } else if (tag == "hairpinHeight") {
2327 0 : h->setHairpinHeight(Spatium(e.readDouble()));
2328 : // hairpinHeightStyle = PropertyFlags::UNSTYLED;
2329 8 : } else if (tag == "hairpinContHeight") {
2330 0 : h->setHairpinContHeight(Spatium(e.readDouble()));
2331 : // hairpinContHeightStyle = PropertyFlags::UNSTYLED;
2332 8 : } else if (tag == "hairpinCircledTip") {
2333 0 : h->setHairpinCircledTip(e.readInt());
2334 8 : } else if (tag == "veloChange") {
2335 0 : h->setVeloChange(e.readInt());
2336 8 : } else if (tag == "dynType") {
2337 0 : h->setVoiceAssignment(readDynamicRange(e.readInt()));
2338 8 : } else if (tag == "useTextLine") { // < 206
2339 0 : e.readInt();
2340 0 : if (h->hairpinType() == HairpinType::CRESC_HAIRPIN) {
2341 0 : h->setHairpinType(HairpinType::CRESC_LINE);
2342 0 : } else if (h->hairpinType() == HairpinType::DIM_HAIRPIN) {
2343 0 : h->setHairpinType(HairpinType::DIM_LINE);
2344 : }
2345 0 : useText = true;
2346 8 : } else if (!readTextLineProperties(e, ctx, h)) {
2347 2 : e.unknown();
2348 : }
2349 : }
2350 3 : if (!useText) {
2351 3 : h->setBeginText(u"");
2352 3 : h->setContinueText(u"");
2353 3 : h->setEndText(u"");
2354 : }
2355 3 : CompatUtils::resetHookHeightSign(h);
2356 3 : adjustPlacement(h);
2357 3 : CompatUtils::migrateOffsetPre302(h, ctx.mscVersion());
2358 3 : }
2359 :
2360 0 : void Read206::readTrill206(XmlReader& e, ReadContext& ctx, Trill* t)
2361 : {
2362 0 : while (e.readNextStartElement()) {
2363 0 : const AsciiStringView tag(e.name());
2364 0 : if (tag == "subtype") {
2365 0 : t->setTrillType(TConv::fromXml(e.readAsciiText(), TrillType::TRILL_LINE));
2366 0 : } else if (tag == "Accidental") {
2367 0 : Accidental* _accidental = Factory::createAccidental(t);
2368 0 : readAccidental206(_accidental, e, ctx);
2369 0 : t->setAccidental(_accidental);
2370 0 : if (t->ornament()) {
2371 0 : t->ornament()->setTrillOldCompatAccidental(_accidental);
2372 : }
2373 0 : } else if (tag == "ornamentStyle") {
2374 0 : read400::TRead::readProperty(t, e, ctx, Pid::ORNAMENT_STYLE);
2375 0 : } else if (tag == "play") {
2376 0 : t->setPlaySpanner(e.readBool());
2377 0 : } else if (!TRead::readProperties(static_cast<SLine*>(t), e, ctx)) {
2378 0 : e.unknown();
2379 : }
2380 : }
2381 0 : adjustPlacement(t);
2382 0 : CompatUtils::migrateOffsetPre302(t, ctx.mscVersion());
2383 0 : }
2384 :
2385 1 : void Read206::readTextLine206(XmlReader& e, ReadContext& ctx, TextLineBase* tlb)
2386 : {
2387 5 : while (e.readNextStartElement()) {
2388 3 : if (!readTextLineProperties(e, ctx, tlb)) {
2389 0 : e.unknown();
2390 : }
2391 : }
2392 1 : CompatUtils::resetHookHeightSign(tlb);
2393 1 : adjustPlacement(tlb);
2394 1 : CompatUtils::migrateOffsetPre302(tlb, ctx.mscVersion());
2395 1 : }
2396 :
2397 : //---------------------------------------------------------
2398 : // setFermataPlacement
2399 : // set fermata placement from old ArticulationAnchor
2400 : // for backwards compatibility
2401 : //---------------------------------------------------------
2402 :
2403 18 : static void setFermataPlacement(EngravingItem* el, ArticulationAnchor anchor, DirectionV direction)
2404 : {
2405 18 : if (direction == DirectionV::UP) {
2406 6 : el->setPlacement(PlacementV::ABOVE);
2407 12 : } else if (direction == DirectionV::DOWN) {
2408 12 : el->setPlacement(PlacementV::BELOW);
2409 : } else {
2410 0 : switch (anchor) {
2411 0 : case ArticulationAnchor::TOP:
2412 0 : el->setPlacement(PlacementV::ABOVE);
2413 0 : break;
2414 :
2415 0 : case ArticulationAnchor::BOTTOM:
2416 0 : el->setPlacement(PlacementV::BELOW);
2417 0 : break;
2418 :
2419 0 : case ArticulationAnchor::AUTO:
2420 0 : break;
2421 0 : default:
2422 0 : break;
2423 : }
2424 : }
2425 18 : }
2426 :
2427 252 : EngravingItem* Read206::readArticulation(EngravingItem* parent, XmlReader& e, ReadContext& ctx)
2428 : {
2429 252 : EngravingItem* el = nullptr;
2430 252 : SymId sym = SymId::fermataAbove; // default -- backward compatibility (no type = ufermata in 1.2)
2431 252 : ArticulationAnchor anchor = ArticulationAnchor::TOP;
2432 252 : DirectionV direction = DirectionV::AUTO;
2433 252 : track_idx_t track = parent->track();
2434 252 : double timeStretch = 0.0;
2435 252 : bool useDefaultPlacement = true;
2436 :
2437 98 : auto readProperties = [](EngravingItem* el, XmlReader& e, ReadContext& ctx)
2438 : {
2439 98 : if (el->isFermata()) {
2440 4 : return read400::TRead::readProperties(toFermata(el), e, ctx);
2441 94 : } else if (el->isArticulationFamily()) {
2442 94 : return read400::TRead::readProperties(dynamic_cast<Articulation*>(el), e, ctx);
2443 : }
2444 0 : UNREACHABLE;
2445 : return false;
2446 : };
2447 :
2448 665 : while (e.readNextStartElement()) {
2449 413 : const AsciiStringView tag(e.name());
2450 413 : if (tag == "subtype") {
2451 249 : String s = e.readText();
2452 249 : if (s.at(0).isDigit()) {
2453 0 : int oldType = s.toInt();
2454 0 : sym = articulationNames[oldType].id;
2455 : } else {
2456 249 : muse::ByteArray ba = s.toAscii();
2457 249 : sym = articulationNames2SymId206(ba.constChar());
2458 249 : if (sym == SymId::noSym) {
2459 : struct {
2460 : const char* name;
2461 : bool up;
2462 : SymId id;
2463 14 : } al[] =
2464 : {
2465 : { "fadein", true, SymId::guitarFadeIn },
2466 : { "fadeout", true, SymId::guitarFadeOut },
2467 : { "volumeswell", true, SymId::guitarVolumeSwell },
2468 : { "wigglesawtooth", true, SymId::wiggleSawtooth },
2469 : { "wigglesawtoothwide", true, SymId::wiggleSawtoothWide },
2470 : { "wigglevibratolargefaster", true, SymId::wiggleVibratoLargeFaster },
2471 : { "wigglevibratolargeslowest", true, SymId::wiggleVibratoLargeSlowest },
2472 : { "umarcato", true, SymId::articMarcatoAbove },
2473 : { "dmarcato", false, SymId::articMarcatoBelow },
2474 : { "ufermata", true, SymId::fermataAbove },
2475 : { "dfermata", false, SymId::fermataBelow },
2476 : { "ushortfermata", true, SymId::fermataShortAbove },
2477 : { "dshortfermata", false, SymId::fermataShortBelow },
2478 : { "ulongfermata", true, SymId::fermataLongAbove },
2479 : { "dlongfermata", false, SymId::fermataLongBelow },
2480 : { "uverylongfermata", true, SymId::fermataVeryLongAbove },
2481 : { "dverylongfermata", false, SymId::fermataVeryLongBelow },
2482 :
2483 : // watch out, bug in 1.2 uportato and dportato are reversed
2484 : { "dportato", true, SymId::articTenutoStaccatoAbove },
2485 : { "uportato", false, SymId::articTenutoStaccatoBelow },
2486 : { "ustaccatissimo", true, SymId::articStaccatissimoAbove },
2487 : { "dstaccatissimo", false, SymId::articStaccatissimoBelow }
2488 : };
2489 : int i;
2490 14 : int n = sizeof(al) / sizeof(*al);
2491 215 : for (i = 0; i < n; ++i) {
2492 214 : if (s == al[i].name) {
2493 13 : sym = al[i].id;
2494 13 : bool up = al[i].up;
2495 13 : direction = up ? DirectionV::UP : DirectionV::DOWN;
2496 13 : if ((direction == DirectionV::DOWN) != (track & 1)) {
2497 7 : useDefaultPlacement = false;
2498 : }
2499 13 : break;
2500 : }
2501 : }
2502 14 : if (i == n) {
2503 1 : sym = SymNames::symIdByName(s);
2504 1 : if (sym == SymId::noSym) {
2505 1 : LOGD("Articulation: unknown type <%s>", muPrintable(s));
2506 : }
2507 : }
2508 : }
2509 249 : }
2510 249 : switch (sym) {
2511 38 : case SymId::fermataAbove:
2512 : case SymId::fermataBelow:
2513 : case SymId::fermataShortAbove:
2514 : case SymId::fermataShortBelow:
2515 : case SymId::fermataLongAbove:
2516 : case SymId::fermataLongBelow:
2517 : case SymId::fermataVeryLongAbove:
2518 : case SymId::fermataVeryLongBelow: {
2519 38 : Fermata* fe = Factory::createFermata(ctx.dummy());
2520 38 : fe->setSymIdAndTimeStretch(sym);
2521 38 : el = fe;
2522 38 : } break;
2523 211 : default:
2524 211 : Articulation* ar = Factory::createArticulation(ctx.dummy());
2525 211 : ar->setSymId(sym);
2526 211 : ar->setDirection(direction);
2527 211 : el = ar;
2528 211 : break;
2529 : }
2530 413 : } else if (tag == "anchor") {
2531 22 : useDefaultPlacement = false;
2532 22 : if (!el || el->isFermata()) {
2533 0 : anchor = CompatUtils::translateToNewArticulationAnchor(e.readInt());
2534 : } else {
2535 22 : readProperties(el, e, ctx);
2536 : }
2537 142 : } else if (tag == "direction") {
2538 64 : useDefaultPlacement = false;
2539 64 : if (!el || el->isFermata()) {
2540 64 : direction = TConv::fromXml(e.readAsciiText(), DirectionV::AUTO);
2541 : } else {
2542 0 : readProperties(el, e, ctx);
2543 : }
2544 78 : } else if (tag == "timeStretch") {
2545 2 : timeStretch = e.readDouble();
2546 : } else {
2547 76 : if (!el) {
2548 0 : LOGD("not handled <%s>", tag.ascii());
2549 : }
2550 76 : if (!el || !readProperties(el, e, ctx)) {
2551 56 : e.unknown();
2552 : }
2553 : }
2554 : }
2555 : // Special case for "no type" = ufermata, with missing subtype tag
2556 252 : if (!el) {
2557 3 : Fermata* f = Factory::createFermata(ctx.dummy());
2558 3 : f->setSymIdAndTimeStretch(sym);
2559 3 : el = f;
2560 : }
2561 252 : if (el->isFermata()) {
2562 41 : if (!RealIsNull(timeStretch)) {
2563 2 : el->setProperty(Pid::TIME_STRETCH, timeStretch);
2564 : }
2565 41 : if (useDefaultPlacement) {
2566 23 : el->setPlacement(track & 1 ? PlacementV::BELOW : PlacementV::ABOVE);
2567 : } else {
2568 18 : setFermataPlacement(el, anchor, direction);
2569 : }
2570 : }
2571 252 : el->setTrack(track);
2572 252 : return el;
2573 : }
2574 :
2575 : //---------------------------------------------------------
2576 : // readSlurTieProperties
2577 : //---------------------------------------------------------
2578 :
2579 0 : static bool readSlurTieProperties(XmlReader& e, ReadContext& ctx, SlurTie* st)
2580 : {
2581 0 : const AsciiStringView tag(e.name());
2582 :
2583 0 : if (read400::TRead::readProperty(st, tag, e, ctx, Pid::SLUR_DIRECTION)) {
2584 0 : } else if (tag == "lineType") {
2585 0 : st->setStyleType(static_cast<SlurStyleType>(e.readInt()));
2586 0 : } else if (tag == "SlurSegment") {
2587 0 : SlurTieSegment* s = st->newSlurTieSegment();
2588 0 : st->add(s);
2589 0 : read400::TRead::read(s, e, ctx);
2590 0 : } else if (!TRead::readItemProperties(st, e, ctx)) {
2591 0 : return false;
2592 : }
2593 0 : return true;
2594 : }
2595 :
2596 16 : void Read206::readSlur206(XmlReader& e, ReadContext& ctx, Slur* s)
2597 : {
2598 16 : s->setTrack(ctx.track()); // set staff
2599 16 : ctx.addSpanner(e.intAttribute("id"), s);
2600 16 : while (e.readNextStartElement()) {
2601 0 : const AsciiStringView tag(e.name());
2602 0 : if (tag == "track2") {
2603 0 : s->setTrack2(e.readInt());
2604 0 : } else if (tag == "startTrack") { // obsolete
2605 0 : s->setTrack(e.readInt());
2606 0 : } else if (tag == "endTrack") { // obsolete
2607 0 : e.readInt();
2608 0 : } else if (!readSlurTieProperties(e, ctx, s)) {
2609 0 : e.unknown();
2610 : }
2611 : }
2612 16 : if (s->track2() == muse::nidx) {
2613 16 : s->setTrack2(s->track());
2614 : }
2615 16 : }
2616 :
2617 0 : void Read206::readTie206(XmlReader& e, ReadContext& ctx, Tie* t)
2618 : {
2619 0 : ctx.addSpanner(e.intAttribute("id"), t);
2620 0 : while (e.readNextStartElement()) {
2621 0 : if (readSlurTieProperties(e, ctx, t)) {
2622 : } else {
2623 0 : e.unknown();
2624 : }
2625 : }
2626 0 : if (ctx.mscVersion() <= 114 && t->spannerSegments().size() == 1) {
2627 : // ignore manual adjustments to single-segment ties in older scores
2628 0 : TieSegment* ss = t->frontSegment();
2629 0 : PointF zeroP;
2630 0 : ss->ups(Grip::START).off = zeroP;
2631 0 : ss->ups(Grip::BEZIER1).off = zeroP;
2632 0 : ss->ups(Grip::BEZIER2).off = zeroP;
2633 0 : ss->ups(Grip::END).off = zeroP;
2634 0 : ss->setOffset(zeroP);
2635 0 : ss->setUserOff2(zeroP);
2636 : }
2637 0 : }
2638 :
2639 : //---------------------------------------------------------
2640 : // readMeasure
2641 : //---------------------------------------------------------
2642 :
2643 441 : static void readMeasure206(Measure* m, int staffIdx, XmlReader& e, ReadContext& ctx)
2644 : {
2645 441 : Segment* segment = 0;
2646 :
2647 441 : std::vector<Chord*> graceNotes;
2648 441 : ctx.tuplets().clear();
2649 441 : ctx.setTrack(staffIdx * VOICES);
2650 :
2651 441 : m->createStaves(staffIdx);
2652 :
2653 : // tick is obsolete
2654 441 : if (e.hasAttribute("tick")) {
2655 0 : ctx.setTick(Fraction::fromTicks(ctx.fileDivision(e.intAttribute("tick"))));
2656 : }
2657 :
2658 : bool irregular;
2659 441 : if (e.hasAttribute("len")) {
2660 10 : StringList sl = e.attribute("len").split(u'/');
2661 10 : if (sl.size() == 2) {
2662 10 : m->setTicks(Fraction(sl.at(0).toInt(), sl.at(1).toInt()));
2663 : } else {
2664 0 : LOGD("illegal measure size <%s>", muPrintable(e.attribute("len")));
2665 : }
2666 10 : irregular = true;
2667 10 : ctx.compatTimeSigMap()->add(m->tick().ticks(), SigEvent(m->ticks(), m->timesig()));
2668 10 : ctx.compatTimeSigMap()->add(m->endTick().ticks(), SigEvent(m->timesig()));
2669 10 : } else {
2670 431 : irregular = false;
2671 : }
2672 :
2673 441 : Staff* staff = ctx.staff(staffIdx);
2674 441 : Fraction timeStretch(staff->timeStretch(m->tick()));
2675 :
2676 : // keep track of tick of previous element
2677 : // this allows markings that need to apply to previous element to do so
2678 : // even though we may have already advanced to next tick position
2679 441 : Fraction lastTick = ctx.tick();
2680 :
2681 1906 : while (e.readNextStartElement()) {
2682 1465 : const AsciiStringView tag(e.name());
2683 :
2684 1465 : if (tag == "move") {
2685 0 : ctx.setTick(e.readFraction() + m->tick());
2686 1465 : } else if (tag == "tick") {
2687 8 : ctx.setTick(Fraction::fromTicks(ctx.fileDivision(e.readInt())));
2688 8 : lastTick = ctx.tick();
2689 1457 : } else if (tag == "BarLine") {
2690 64 : Fermata* fermataAbove = nullptr;
2691 64 : Fermata* fermataBelow = nullptr;
2692 64 : BarLine* bl = Factory::createBarLine(ctx.dummy());
2693 64 : bl->setTrack(ctx.track());
2694 202 : while (e.readNextStartElement()) {
2695 138 : const AsciiStringView t(e.name());
2696 138 : if (t == "subtype") {
2697 64 : bl->setBarLineType(TConv::fromXml(e.readAsciiText(), BarLineType::NORMAL));
2698 74 : } else if (t == "customSubtype") { // obsolete
2699 0 : e.readInt();
2700 74 : } else if (t == "span") {
2701 64 : const int span = e.readInt();
2702 64 : if (span > 0) {
2703 64 : ctx.setBarLineSpan(bl, static_cast<size_t>(span - 1));
2704 : } else {
2705 0 : if (span < 0) {
2706 0 : LOGW() << "bar line span is negative: " << span;
2707 : }
2708 :
2709 0 : ctx.setBarLineSpan(bl, 0);
2710 : }
2711 10 : } else if (t == "spanFromOffset") {
2712 0 : bl->setSpanFrom(e.readInt());
2713 10 : } else if (t == "spanToOffset") {
2714 0 : bl->setSpanTo(e.readInt());
2715 10 : } else if (t == "Articulation") {
2716 0 : EngravingItem* el = Read206::readArticulation(bl, e, ctx);
2717 0 : if (el->isFermata()) {
2718 0 : if (el->placement() == PlacementV::ABOVE) {
2719 0 : fermataAbove = toFermata(el);
2720 : } else {
2721 0 : fermataBelow = toFermata(el);
2722 0 : const std::optional<size_t> barLineSpan = ctx.getBarLineSpan(bl);
2723 0 : if (barLineSpan) {
2724 0 : fermataBelow->setTrack(staff2track(bl->staffIdx() + *barLineSpan));
2725 : } else {
2726 0 : fermataBelow->setTrack(staff2track(bl->staffIdx() + ctx.getStaffBarLineSpan(staffIdx)));
2727 : }
2728 : }
2729 : } else {
2730 0 : bl->add(el);
2731 : }
2732 10 : } else if (!TRead::readItemProperties(bl, e, ctx)) {
2733 10 : e.unknown();
2734 : }
2735 : }
2736 : //
2737 : // StartRepeatBarLine: always at the beginning tick of a measure, always BarLineType::START_REPEAT
2738 : // BarLine: in the middle of a measure, has no semantic
2739 : // EndBarLine: at the end tick of a measure
2740 : // BeginBarLine: first segment of a measure
2741 :
2742 : SegmentType st;
2743 64 : if ((ctx.tick() != m->tick()) && (ctx.tick() != m->endTick())) {
2744 0 : st = SegmentType::BarLine;
2745 64 : } else if (bl->barLineType() == BarLineType::START_REPEAT && ctx.tick() == m->tick()) {
2746 0 : st = SegmentType::StartRepeatBarLine;
2747 64 : } else if (ctx.tick() == m->tick() && segment == 0) {
2748 0 : st = SegmentType::BeginBarLine;
2749 : } else {
2750 64 : st = SegmentType::EndBarLine;
2751 : }
2752 64 : segment = m->getSegment(st, ctx.tick());
2753 64 : segment->add(bl);
2754 64 : if (fermataAbove) {
2755 0 : segment->add(fermataAbove);
2756 : }
2757 64 : if (fermataBelow) {
2758 0 : segment->add(fermataBelow);
2759 : }
2760 1393 : } else if (tag == "Chord") {
2761 906 : segment = m->getSegment(SegmentType::ChordRest, ctx.tick());
2762 906 : Chord* chord = Factory::createChord(segment);
2763 906 : chord->setTrack(ctx.track());
2764 906 : readChord(chord, e, ctx);
2765 906 : if (chord->noteType() != NoteType::NORMAL) {
2766 0 : graceNotes.push_back(chord);
2767 : } else {
2768 906 : segment->add(chord);
2769 906 : for (size_t i = 0; i < graceNotes.size(); ++i) {
2770 0 : Chord* gc = graceNotes[i];
2771 0 : gc->setGraceIndex(i);
2772 0 : chord->add(gc);
2773 : }
2774 906 : graceNotes.clear();
2775 906 : Fraction crticks = chord->actualTicks();
2776 906 : lastTick = ctx.tick();
2777 906 : ctx.incTick(crticks);
2778 : }
2779 487 : } else if (tag == "Rest") {
2780 241 : if (m->isMMRest()) {
2781 4 : segment = m->getSegment(SegmentType::ChordRest, ctx.tick());
2782 4 : MMRest* mmr = Factory::createMMRest(segment);
2783 4 : mmr->setTrack(ctx.track());
2784 4 : read400::TRead::read(mmr, e, ctx);
2785 4 : mmr->setTicks(m->ticks());
2786 4 : segment->add(mmr);
2787 4 : lastTick = ctx.tick();
2788 4 : ctx.incTick(mmr->actualTicks());
2789 : } else {
2790 237 : segment = m->getSegment(SegmentType::ChordRest, ctx.tick());
2791 237 : Rest* rest = Factory::createRest(segment);
2792 237 : rest->setDurationType(DurationType::V_MEASURE);
2793 237 : rest->setTicks(m->timesig() / timeStretch);
2794 237 : rest->setTrack(ctx.track());
2795 237 : readRest(rest, e, ctx);
2796 237 : segment->add(rest);
2797 :
2798 237 : if (!rest->ticks().isValid()) { // hack
2799 0 : rest->setTicks(m->timesig() / timeStretch);
2800 : }
2801 :
2802 237 : lastTick = ctx.tick();
2803 237 : ctx.incTick(rest->actualTicks());
2804 : }
2805 246 : } else if (tag == "Breath") {
2806 3 : Breath* breath = Factory::createBreath(ctx.dummy());
2807 3 : breath->setTrack(ctx.track());
2808 3 : breath->setPlacement(PlacementV::ABOVE);
2809 3 : Fraction tick = ctx.tick();
2810 3 : read400::TRead::read(breath, e, ctx);
2811 : // older scores placed the breath segment right after the chord to which it applies
2812 : // rather than before the next chordrest segment with an element for the staff
2813 : // result would be layout too far left if there are other segments due to notes in other staves
2814 : // we need to find tick of chord to which this applies, and add its duration
2815 3 : Fraction prevTick;
2816 3 : if (ctx.tick() < tick) {
2817 0 : prevTick = ctx.tick(); // use our own tick if we explicitly reset to earlier position
2818 : } else {
2819 3 : prevTick = lastTick; // otherwise use tick of previous tick/chord/rest tag
2820 : }
2821 : // find segment
2822 3 : Segment* prev = m->findSegment(SegmentType::ChordRest, prevTick);
2823 3 : if (prev) {
2824 : // find chordrest
2825 3 : ChordRest* lastCR = toChordRest(prev->element(ctx.track()));
2826 3 : if (lastCR) {
2827 3 : tick = prevTick + lastCR->actualTicks();
2828 : }
2829 : }
2830 3 : segment = m->getSegment(SegmentType::Breath, tick);
2831 3 : segment->add(breath);
2832 243 : } else if (tag == "endSpanner") {
2833 6 : int id = e.attribute("id").toInt();
2834 6 : Spanner* spanner = ctx.findSpanner(id);
2835 6 : if (spanner) {
2836 6 : spanner->setTicks(ctx.tick() - spanner->tick());
2837 : // if (spanner->track2() == -1)
2838 : // the absence of a track tag [?] means the
2839 : // track is the same as the beginning of the slur
2840 6 : if (spanner->track2() == muse::nidx) {
2841 0 : spanner->setTrack2(spanner->track() ? spanner->track() : ctx.track());
2842 : }
2843 : } else {
2844 : // remember "endSpanner" values
2845 0 : SpannerValues sv;
2846 0 : sv.spannerId = id;
2847 0 : sv.track2 = ctx.track();
2848 0 : sv.tick2 = ctx.tick();
2849 0 : ctx.addSpannerValues(sv);
2850 : }
2851 6 : e.readNext();
2852 237 : } else if (tag == "Slur") {
2853 0 : Slur* sl = Factory::createSlur(ctx.dummy());
2854 0 : sl->setTick(ctx.tick());
2855 0 : Read206::readSlur206(e, ctx, sl);
2856 : //
2857 : // check if we already saw "endSpanner"
2858 : //
2859 0 : int id = ctx.spannerId(sl);
2860 0 : const SpannerValues* sv = ctx.spannerValues(id);
2861 0 : if (sv) {
2862 0 : sl->setTick2(sv->tick2);
2863 0 : sl->setTrack2(sv->track2);
2864 : }
2865 0 : ctx.addSpanner(sl);
2866 237 : } else if (tag == "HairPin"
2867 235 : || tag == "Pedal"
2868 234 : || tag == "Ottava"
2869 233 : || tag == "Trill"
2870 233 : || tag == "TextLine"
2871 472 : || tag == "Volta") {
2872 6 : Spanner* sp = toSpanner(Factory::createItemByName(tag, ctx.dummy()));
2873 6 : sp->setTrack(ctx.track());
2874 6 : sp->setTrack2(sp->track());
2875 6 : sp->setTick(ctx.tick());
2876 6 : sp->eraseSpannerSegments();
2877 6 : ctx.addSpanner(e.intAttribute("id", -1), sp);
2878 :
2879 6 : if (tag == "Volta") {
2880 1 : readVolta206(e, ctx, toVolta(sp));
2881 5 : } else if (tag == "Pedal") {
2882 1 : readPedal(e, ctx, toPedal(sp));
2883 4 : } else if (tag == "Ottava") {
2884 1 : readOttava(e, ctx, toOttava(sp));
2885 3 : } else if (tag == "HairPin") {
2886 2 : Read206::readHairpin206(e, ctx, toHairpin(sp));
2887 1 : } else if (tag == "Trill") {
2888 0 : Ornament* ornament = Factory::createOrnament(m->score()->dummy());
2889 0 : toTrill(sp)->setOrnament(ornament);
2890 0 : Read206::readTrill206(e, ctx, toTrill(sp));
2891 : } else {
2892 1 : Read206::readTextLine206(e, ctx, toTextLineBase(sp));
2893 : }
2894 6 : ctx.addSpanner(sp);
2895 : //
2896 : // check if we already saw "endSpanner"
2897 : //
2898 6 : int id = ctx.spannerId(sp);
2899 6 : const SpannerValues* sv = ctx.spannerValues(id);
2900 6 : if (sv) {
2901 0 : sp->setTicks(sv->tick2 - sp->tick());
2902 0 : sp->setTrack2(sv->track2);
2903 : }
2904 231 : } else if (tag == "RepeatMeasure") {
2905 2 : segment = m->getSegment(SegmentType::ChordRest, ctx.tick());
2906 2 : MeasureRepeat* rm = Factory::createMeasureRepeat(segment);
2907 2 : rm->setTrack(ctx.track());
2908 2 : readRest(rm, e, ctx);
2909 2 : rm->setNumMeasures(1);
2910 2 : m->setMeasureRepeatCount(1, staffIdx);
2911 2 : segment->add(rm);
2912 2 : lastTick = ctx.tick();
2913 2 : ctx.incTick(m->ticks());
2914 229 : } else if (tag == "Clef") {
2915 29 : Clef* clef = Factory::createClef(ctx.dummy());
2916 29 : clef->setTrack(ctx.track());
2917 29 : read400::TRead::read(clef, e, ctx);
2918 29 : clef->setGenerated(false);
2919 29 : if (ctx.tick().isZero()) {
2920 11 : if (ctx.staff(staffIdx)->clef(Fraction(0, 1)) != clef->clefType()) {
2921 5 : ctx.staff(staffIdx)->setDefaultClefType(clef->clefType());
2922 : }
2923 11 : delete clef;
2924 11 : continue;
2925 : }
2926 : // there may be more than one clef segment for same tick position
2927 18 : if (!segment) {
2928 : // this is the first segment of measure
2929 1 : segment = m->getSegment(SegmentType::Clef, ctx.tick());
2930 : } else {
2931 17 : bool firstSegment = false;
2932 : // the first clef may be missing and is added later in layout
2933 17 : for (Segment* s = m->segments().first(); s && s->tick() == ctx.tick(); s = s->next()) {
2934 0 : if (s->segmentType() == SegmentType::Clef
2935 : // hack: there may be other segment types which should
2936 : // generate a clef at current position
2937 0 : || s->segmentType() == SegmentType::StartRepeatBarLine
2938 : ) {
2939 0 : firstSegment = true;
2940 0 : break;
2941 : }
2942 : }
2943 17 : if (firstSegment) {
2944 0 : Segment* ns = 0;
2945 0 : if (segment->next()) {
2946 0 : ns = segment->next();
2947 0 : while (ns && ns->tick() < ctx.tick()) {
2948 0 : ns = ns->next();
2949 : }
2950 : }
2951 0 : segment = 0;
2952 0 : for (Segment* s = ns; s && s->tick() == ctx.tick(); s = s->next()) {
2953 0 : if (s->segmentType() == SegmentType::Clef) {
2954 0 : segment = s;
2955 0 : break;
2956 : }
2957 : }
2958 0 : if (!segment) {
2959 0 : segment = Factory::createSegment(m, SegmentType::Clef, ctx.tick() - m->tick());
2960 0 : m->segments().insert(segment, ns);
2961 : }
2962 : } else {
2963 : // this is the first clef: move to left
2964 17 : segment = m->getSegment(SegmentType::Clef, ctx.tick());
2965 : }
2966 : }
2967 18 : if (ctx.tick() != m->tick()) {
2968 17 : clef->setSmall(true); // TODO: layout does this ?
2969 : }
2970 :
2971 : // Clef segments are sorted on layout now. Previously, clef barline position could be out of sync with segment placement.
2972 18 : if (ctx.tick() != Fraction(0, 1) && ctx.tick() == m->tick() && !(m->prevMeasure() && m->prevMeasure()->repeatEnd())) {
2973 1 : clef->setClefToBarlinePosition(ClefToBarlinePosition::AFTER);
2974 : }
2975 :
2976 18 : segment->add(clef);
2977 200 : } else if (tag == "TimeSig") {
2978 62 : TimeSig* ts = Factory::createTimeSig(ctx.dummy());
2979 62 : ts->setTrack(ctx.track());
2980 62 : read400::TRead::read(ts, e, ctx);
2981 : // if time sig not at beginning of measure => courtesy time sig
2982 62 : Fraction currTick = ctx.tick();
2983 62 : bool courtesySig = (currTick > m->tick());
2984 62 : if (courtesySig) {
2985 : // if courtesy sig., just add it without map processing
2986 0 : segment = m->getSegment(SegmentType::TimeSigAnnounce, currTick);
2987 0 : segment->add(ts);
2988 : } else {
2989 : // if 'real' time sig., do full process
2990 62 : segment = m->getSegment(SegmentType::TimeSig, currTick);
2991 62 : segment->add(ts);
2992 :
2993 62 : timeStretch = ts->stretch().reduced();
2994 62 : m->setTimesig(ts->sig() / timeStretch);
2995 :
2996 62 : if (irregular) {
2997 9 : ctx.compatTimeSigMap()->add(m->tick().ticks(), SigEvent(m->ticks(), m->timesig()));
2998 9 : ctx.compatTimeSigMap()->add(m->endTick().ticks(), SigEvent(m->timesig()));
2999 : } else {
3000 53 : m->setTicks(m->timesig());
3001 53 : ctx.compatTimeSigMap()->add(m->tick().ticks(), SigEvent(m->timesig()));
3002 : }
3003 : }
3004 138 : } else if (tag == "KeySig") {
3005 19 : KeySig* ks = Factory::createKeySig(ctx.dummy());
3006 19 : ks->setTrack(ctx.track());
3007 19 : read400::TRead::read(ks, e, ctx);
3008 19 : Fraction curTick = ctx.tick();
3009 : // if key sig not at beginning of measure => courtesy key sig
3010 19 : bool courtesySig = (curTick == m->endTick());
3011 19 : segment = m->getSegment(courtesySig ? SegmentType::KeySigAnnounce : SegmentType::KeySig, curTick);
3012 19 : segment->add(ks);
3013 19 : staff->setKey(curTick, ks->keySigEvent());
3014 119 : } else if (tag == "Text" || tag == "StaffText") {
3015 : // MuseScore 3 has different types for system text and
3016 : // staff text while MuseScore 2 didn't.
3017 : // We need to decide first which one we should create.
3018 11 : TextReaderContext206 tctx(e);
3019 11 : String styleName = ReadStyleName206(tctx.tag());
3020 : StaffTextBase* t;
3021 18 : if (styleName == "System" || styleName == "Tempo"
3022 6 : || styleName == "Marker" || styleName == "Jump"
3023 18 : || styleName == "Volta") { // TODO: is it possible to get it from style?
3024 5 : t = Factory::createSystemText(ctx.dummy());
3025 : } else {
3026 6 : t = Factory::createStaffText(ctx.dummy());
3027 : }
3028 11 : t->setTrack(ctx.track());
3029 11 : readTextPropertyStyle206(tctx.tag(), ctx, t, t);
3030 47 : while (tctx.reader().readNextStartElement()) {
3031 25 : if (!readTextProperties206(tctx.reader(), ctx, t)) {
3032 4 : tctx.reader().unknown();
3033 : }
3034 : }
3035 11 : CompatUtils::migrateOffsetPre302(t, ctx.mscVersion());
3036 11 : if (t->empty()) {
3037 4 : if (t->links()) {
3038 0 : if (t->links()->size() == 1) {
3039 0 : delete t;
3040 : }
3041 : }
3042 : } else {
3043 7 : segment = m->getSegment(SegmentType::ChordRest, ctx.tick());
3044 7 : segment->add(t);
3045 : }
3046 11 : }
3047 : //----------------------------------------------------
3048 : // Annotation
3049 108 : else if (tag == "Dynamic") {
3050 1 : segment = m->getSegment(SegmentType::ChordRest, ctx.tick());
3051 1 : Dynamic* dyn = Factory::createDynamic(segment);
3052 1 : dyn->setTrack(ctx.track());
3053 1 : readDynamic(dyn, e, ctx);
3054 1 : segment->add(dyn);
3055 107 : } else if (tag == "RehearsalMark") {
3056 1 : segment = m->getSegment(SegmentType::ChordRest, ctx.tick());
3057 1 : RehearsalMark* el = Factory::createRehearsalMark(segment);
3058 1 : el->setTrack(ctx.track());
3059 1 : readText206(e, ctx, el, el);
3060 1 : segment->add(el);
3061 106 : } else if (tag == "Harmony"
3062 103 : || tag == "FretDiagram"
3063 103 : || tag == "TremoloBar"
3064 99 : || tag == "Symbol"
3065 99 : || tag == "InstrumentChange"
3066 98 : || tag == "StaffState"
3067 209 : || tag == "FiguredBass"
3068 : ) {
3069 9 : segment = m->getSegment(SegmentType::ChordRest, ctx.tick());
3070 9 : EngravingItem* el = Factory::createItemByName(tag, segment);
3071 : // hack - needed because tick tags are unreliable in 1.3 scores
3072 : // for symbols attached to anything but a measure
3073 9 : el->setTrack(ctx.track());
3074 9 : read400::TRead::readItem(el, e, ctx);
3075 9 : if (el->staff() && (el->isHarmony() || el->isFretDiagram() || el->isInstrumentChange())) {
3076 4 : adjustPlacement(el);
3077 : }
3078 9 : CompatUtils::migrateOffsetPre302(el, ctx.mscVersion());
3079 :
3080 9 : segment->add(el);
3081 97 : } else if (tag == "Tempo") {
3082 1 : segment = m->getSegment(SegmentType::ChordRest, ctx.tick());
3083 1 : TempoText* tt = Factory::createTempoText(segment);
3084 : // hack - needed because tick tags are unreliable in 1.3 scores
3085 : // for symbols attached to anything but a measure
3086 1 : tt->setTrack(ctx.track());
3087 1 : readTempoText(tt, e, ctx);
3088 1 : segment->add(tt);
3089 96 : } else if (tag == "Marker" || tag == "Jump") {
3090 24 : EngravingItem* el = Factory::createItemByName(tag, ctx.dummy());
3091 24 : el->setTrack(ctx.track());
3092 24 : if (tag == "Marker") {
3093 12 : Marker* ma = toMarker(el);
3094 12 : readMarker(ma, e, ctx);
3095 12 : EngravingItem* markerEl = toEngravingItem(ma);
3096 12 : m->add(markerEl);
3097 : } else {
3098 12 : read400::TRead::readItem(el, e, ctx);
3099 12 : m->add(el);
3100 : }
3101 72 : } else if (tag == "Image") {
3102 0 : if (MScore::noImages) {
3103 0 : e.skipCurrentElement();
3104 : } else {
3105 0 : segment = m->getSegment(SegmentType::ChordRest, ctx.tick());
3106 0 : EngravingItem* el = Factory::createItemByName(tag, segment);
3107 0 : el->setTrack(ctx.track());
3108 0 : read400::TRead::readItem(el, e, ctx);
3109 0 : segment->add(el);
3110 : }
3111 72 : } else if (tag == "stretch") {
3112 : // Ignore measure stretch pre 4.0
3113 4 : e.skipCurrentElement();
3114 68 : } else if (tag == "noOffset") {
3115 0 : m->setMeasureNumberOffset(e.readInt());
3116 68 : } else if (tag == "measureNumberMode") {
3117 0 : m->setMeasureNumberMode(MeasureNumberMode(e.readInt()));
3118 68 : } else if (tag == "irregular") {
3119 0 : m->setExcludeFromNumbering(e.readBool());
3120 68 : } else if (tag == "breakMultiMeasureRest") {
3121 0 : m->setBreakMultiMeasureRest(e.readBool());
3122 68 : } else if (tag == "sysInitBarLineType") {
3123 0 : segment = m->getSegment(SegmentType::BeginBarLine, m->tick());
3124 0 : BarLine* barLine = Factory::createBarLine(segment);
3125 0 : barLine->setTrack(ctx.track());
3126 0 : barLine->setBarLineType(TConv::fromXml(e.readAsciiText(), BarLineType::NORMAL));
3127 0 : segment->add(barLine);
3128 68 : } else if (tag == "Tuplet") {
3129 11 : int tupletId = e.attribute("id").toInt();
3130 11 : Tuplet* tuplet = Factory::createTuplet(m);
3131 11 : tuplet->setTrack(ctx.track());
3132 11 : tuplet->setTick(ctx.tick());
3133 11 : readTuplet206(tuplet, e, ctx);
3134 11 : ctx.addTuplet(tupletId, tuplet);
3135 57 : } else if (tag == "startRepeat") {
3136 3 : m->setRepeatStart(true);
3137 3 : e.readNext();
3138 54 : } else if (tag == "endRepeat") {
3139 3 : m->setRepeatCount(e.readInt());
3140 3 : m->setRepeatEnd(true);
3141 51 : } else if (tag == "vspacer" || tag == "vspacerDown") {
3142 0 : if (!m->vspacerDown(staffIdx)) {
3143 0 : Spacer* spacer = Factory::createSpacer(m);
3144 0 : spacer->setSpacerType(SpacerType::DOWN);
3145 0 : spacer->setTrack(staffIdx * VOICES);
3146 0 : m->add(spacer);
3147 : }
3148 0 : m->vspacerDown(staffIdx)->setGap(Spatium(e.readDouble()));
3149 51 : } else if (tag == "vspacer" || tag == "vspacerUp") {
3150 0 : if (!m->vspacerUp(staffIdx)) {
3151 0 : Spacer* spacer = Factory::createSpacer(m);
3152 0 : spacer->setSpacerType(SpacerType::UP);
3153 0 : spacer->setTrack(staffIdx * VOICES);
3154 0 : m->add(spacer);
3155 : }
3156 0 : m->vspacerUp(staffIdx)->setGap(Spatium(e.readDouble()));
3157 51 : } else if (tag == "visible") {
3158 0 : m->setStaffVisible(staffIdx, e.readInt());
3159 51 : } else if (tag == "slashStyle") {
3160 0 : m->setStaffStemless(staffIdx, e.readInt());
3161 51 : } else if (tag == "Beam") {
3162 2 : int beamId = e.attribute("id").toInt();
3163 2 : Beam* beam = Factory::createBeam(ctx.score());
3164 2 : beam->setTrack(ctx.track());
3165 2 : read400::TRead::read(beam, e, ctx);
3166 2 : ctx.addBeam(beamId, beam);
3167 49 : } else if (tag == "Segment") {
3168 0 : if (segment) {
3169 0 : read400::TRead::read(segment, e, ctx);
3170 : } else {
3171 0 : e.unknown();
3172 : }
3173 49 : } else if (tag == "MeasureNumber") {
3174 0 : MeasureNumber* noText = new MeasureNumber(m);
3175 0 : readText206(e, ctx, noText, m);
3176 0 : noText->setTrack(ctx.track());
3177 0 : m->setMeasureNumber(noText->staffIdx(), noText);
3178 49 : } else if (tag == "SystemDivider") {
3179 0 : SystemDivider* sd = new SystemDivider(ctx.dummy());
3180 0 : read400::TRead::read(sd, e, ctx);
3181 0 : m->add(sd);
3182 49 : } else if (tag == "Ambitus") {
3183 2 : segment = m->getSegment(SegmentType::Ambitus, ctx.tick());
3184 2 : Ambitus* range = Factory::createAmbitus(segment);
3185 2 : readAmbitus(range, e, ctx);
3186 2 : range->setTrack(trackZeroVoice(ctx.track()));
3187 2 : segment->add(range);
3188 47 : } else if (tag == "multiMeasureRest") {
3189 4 : m->setMMRestCount(e.readInt());
3190 : // set tick to previous measure
3191 4 : m->setTick(ctx.lastMeasure()->tick());
3192 4 : ctx.setTick(ctx.lastMeasure()->tick());
3193 43 : } else if (read400::TRead::readProperties(static_cast<MeasureBase*>(m), e, ctx)) {
3194 : } else {
3195 0 : e.unknown();
3196 : }
3197 : }
3198 441 : ctx.checkTuplets();
3199 441 : m->connectTremolo();
3200 441 : }
3201 :
3202 : //---------------------------------------------------------
3203 : // readBox
3204 : //---------------------------------------------------------
3205 :
3206 17 : static void readBox(Box* b, XmlReader& e, ReadContext& ctx)
3207 : {
3208 17 : b->setAutoSizeEnabled(false); // didn't exist in Mu2
3209 :
3210 17 : b->setBoxHeight(0_sp); // override default set in constructor
3211 17 : b->setBoxWidth(0_sp);
3212 :
3213 100 : while (e.readNextStartElement()) {
3214 83 : const AsciiStringView tag(e.name());
3215 83 : if (tag == "HBox") {
3216 0 : HBox* hb = Factory::createHBox(b->score());
3217 0 : read400::TRead::read(hb, e, ctx);
3218 0 : b->add(hb);
3219 83 : } else if (tag == "VBox") {
3220 0 : VBox* vb = Factory::createVBox(b->score());
3221 0 : read400::TRead::read(vb, e, ctx);
3222 0 : b->add(vb);
3223 83 : } else if (tag == "Text") {
3224 : Text* t;
3225 51 : if (b->isTBox()) {
3226 0 : t = toTBox(b)->text();
3227 0 : readText206(e, ctx, t, t);
3228 : } else {
3229 51 : t = Factory::createText(b);
3230 51 : readText206(e, ctx, t, t);
3231 51 : if (t->empty()) {
3232 0 : LOGD("read empty text");
3233 : } else {
3234 51 : b->add(t);
3235 : }
3236 : }
3237 32 : } else if (!read400::TRead::readBoxProperties(b, e, ctx)) {
3238 10 : e.unknown();
3239 : }
3240 : }
3241 17 : }
3242 :
3243 : //---------------------------------------------------------
3244 : // readStaffContent
3245 : //---------------------------------------------------------
3246 :
3247 60 : static void readStaffContent206(Score* score, XmlReader& e, ReadContext& ctx)
3248 : {
3249 60 : int staff = e.intAttribute("id", 1) - 1;
3250 60 : ctx.setTick(Fraction(0, 1));
3251 60 : ctx.setTrack(staff * VOICES);
3252 60 : Box* lastReadBox = nullptr;
3253 60 : bool readMeasureLast = false;
3254 :
3255 60 : if (staff == 0) {
3256 411 : while (e.readNextStartElement()) {
3257 372 : const AsciiStringView tag(e.name());
3258 :
3259 372 : if (tag == "Measure") {
3260 351 : if (lastReadBox) {
3261 15 : lastReadBox->setBottomGap(lastReadBox->bottomGap() + lastReadBox->propertyDefault(Pid::BOTTOM_GAP).value<Spatium>());
3262 15 : lastReadBox = nullptr;
3263 : }
3264 351 : readMeasureLast = true;
3265 :
3266 351 : Measure* measure = nullptr;
3267 351 : measure = Factory::createMeasure(score);
3268 351 : measure->setTick(ctx.tick());
3269 : //
3270 : // inherit timesig from previous measure
3271 : //
3272 351 : Measure* m = ctx.lastMeasure(); // measure->prevMeasure();
3273 351 : Fraction f(m ? m->timesig() : Fraction(4, 4));
3274 351 : measure->setTicks(f);
3275 351 : measure->setTimesig(f);
3276 :
3277 351 : readMeasure206(measure, staff, e, ctx);
3278 351 : measure->checkMeasure(staff);
3279 351 : if (!measure->isMMRest()) {
3280 347 : score->measures()->append(measure);
3281 347 : if (m && m->mmRest()) {
3282 4 : m->mmRest()->setNext(measure);
3283 : }
3284 347 : ctx.setLastMeasure(measure);
3285 347 : ctx.setTick(measure->endTick());
3286 : } else {
3287 : // this is a multi measure rest
3288 : // always preceded by the first measure it replaces
3289 4 : Measure* lm = ctx.lastMeasure();
3290 :
3291 4 : if (lm) {
3292 4 : lm->setMMRest(measure);
3293 4 : measure->setTick(lm->tick());
3294 4 : measure->setPrev(lm->prev());
3295 : }
3296 : }
3297 21 : } else if (tag == "HBox" || tag == "VBox" || tag == "TBox" || tag == "FBox") {
3298 17 : Box* b = toBox(Factory::createItemByName(tag, score->dummy()));
3299 17 : readBox(b, e, ctx);
3300 17 : b->setTick(ctx.tick());
3301 17 : score->measures()->append(b);
3302 :
3303 : // If it's the first box, and comes before any measures, reset to
3304 : // 301 default.
3305 17 : if (!readMeasureLast && !lastReadBox) {
3306 16 : b->setTopGap(b->propertyDefault(Pid::TOP_GAP).value<Spatium>());
3307 16 : b->setPropertyFlags(Pid::TOP_GAP, PropertyFlags::STYLED);
3308 1 : } else if (readMeasureLast) {
3309 0 : b->setTopGap(b->topGap() + b->propertyDefault(Pid::TOP_GAP).value<Spatium>());
3310 : }
3311 :
3312 17 : lastReadBox = b;
3313 17 : readMeasureLast = false;
3314 4 : } else if (tag == "tick") {
3315 4 : ctx.setTick(Fraction::fromTicks(score->fileDivision(e.readInt())));
3316 : } else {
3317 0 : e.unknown();
3318 : }
3319 : }
3320 : } else {
3321 21 : Measure* measure = score->firstMeasure();
3322 111 : while (e.readNextStartElement()) {
3323 90 : const AsciiStringView tag(e.name());
3324 :
3325 90 : if (tag == "Measure") {
3326 90 : if (measure == 0) {
3327 0 : LOGD("Score::readStaff(): missing measure!");
3328 0 : measure = Factory::createMeasure(score);
3329 0 : measure->setTick(ctx.tick());
3330 0 : score->measures()->append(measure);
3331 : }
3332 90 : ctx.setTick(measure->tick());
3333 90 : readMeasure206(measure, staff, e, ctx);
3334 90 : measure->checkMeasure(staff);
3335 90 : if (measure->isMMRest()) {
3336 0 : measure = ctx.lastMeasure()->nextMeasure();
3337 : } else {
3338 90 : ctx.setLastMeasure(measure);
3339 90 : if (measure->mmRest()) {
3340 0 : measure = measure->mmRest();
3341 : } else {
3342 90 : measure = measure->nextMeasure();
3343 : }
3344 : }
3345 0 : } else if (tag == "tick") {
3346 0 : ctx.setTick(Fraction::fromTicks(score->fileDivision(e.readInt())));
3347 : } else {
3348 0 : e.unknown();
3349 : }
3350 : }
3351 : }
3352 60 : }
3353 :
3354 : //---------------------------------------------------------
3355 : // readStyle
3356 : //---------------------------------------------------------
3357 :
3358 39 : static void readStyle206(MStyle* style, XmlReader& e, ReadContext& ctx, ReadChordListHook& readChordListHook)
3359 : {
3360 39 : excessTextStyles206.clear();
3361 292 : while (e.readNextStartElement()) {
3362 253 : AsciiStringView tag = e.name();
3363 253 : if (tag == "TextStyle") {
3364 107 : Read206::readTextStyle206(style, e, ctx, excessTextStyles206);
3365 146 : } else if (tag == "Spatium") {
3366 39 : style->set(Sid::spatium, e.readDouble() * DPMM);
3367 107 : } else if (tag == "page-layout") {
3368 27 : readPageFormat206(style, e);
3369 80 : } else if (tag == "displayInConcertPitch") {
3370 0 : style->set(Sid::concertPitch, bool(e.readInt()));
3371 80 : } else if (tag == "pedalY") {
3372 0 : double y = e.readDouble();
3373 0 : style->set(Sid::pedalPosBelow, PointF(0.0, y));
3374 80 : } else if (tag == "lyricsDistance") {
3375 0 : double y = e.readDouble();
3376 0 : style->set(Sid::lyricsPosBelow, PointF(0.0, y));
3377 80 : } else if (tag == "lyricsMinBottomDistance") {
3378 : // no longer meaningful since it is now measured from skyline rather than staff
3379 : //style->set(Sid::lyricsMinBottomDistance, PointF(0.0, y));
3380 2 : e.skipCurrentElement();
3381 78 : } else if (tag == "ottavaHook") {
3382 1 : double y = std::abs(e.readDouble());
3383 1 : style->set(Sid::ottavaHookAbove, y);
3384 1 : style->set(Sid::ottavaHookBelow, -y);
3385 77 : } else if (tag == "endBarDistance") {
3386 0 : double d = e.readDouble();
3387 0 : d += style->value(Sid::barWidth).toReal();
3388 0 : d += style->value(Sid::endBarWidth).toReal();
3389 0 : style->set(Sid::endBarDistance, d);
3390 77 : } else if (tag == "ChordList") {
3391 0 : readChordListHook.read(e);
3392 77 : } else if (tag == "harmonyY") {
3393 0 : double val = -e.readDouble();
3394 0 : if (val > 0.0) {
3395 0 : style->set(Sid::harmonyPlacement, PlacementV::BELOW);
3396 0 : style->set(Sid::chordSymbolAPosBelow, PointF(.0, val));
3397 : } else {
3398 0 : style->set(Sid::harmonyPlacement, PlacementV::ABOVE);
3399 0 : style->set(Sid::chordSymbolAPosBelow, PointF(.0, val));
3400 : }
3401 77 : } else if (tag == "useStandardNoteNames") { // These settings were collapsed into one enum in 4.6
3402 0 : if (e.readBool()) {
3403 0 : style->set(Sid::chordSymbolSpelling, NoteSpellingType::STANDARD);
3404 : }
3405 77 : } else if (tag == "useGermanNoteNames") {
3406 0 : if (e.readBool()) {
3407 0 : style->set(Sid::chordSymbolSpelling, NoteSpellingType::GERMAN);
3408 : }
3409 77 : } else if (tag == "useFullGermanNoteNames") {
3410 0 : if (e.readBool()) {
3411 0 : style->set(Sid::chordSymbolSpelling, NoteSpellingType::GERMAN_PURE);
3412 : }
3413 77 : } else if (tag == "useSolfeggioNoteNames") {
3414 0 : if (e.readBool()) {
3415 0 : style->set(Sid::chordSymbolSpelling, NoteSpellingType::SOLFEGGIO);
3416 : }
3417 77 : } else if (tag == "useFrenchNoteNames") {
3418 0 : if (e.readBool()) {
3419 0 : style->set(Sid::chordSymbolSpelling, NoteSpellingType::FRENCH);
3420 : }
3421 : } else {
3422 77 : if (!ReadStyleHook::readStyleProperties(style, e)) {
3423 1 : e.skipCurrentElement();
3424 : }
3425 : }
3426 : }
3427 :
3428 39 : readChordListHook.validate();
3429 39 : }
3430 :
3431 39 : bool Read206::readScoreTag(Score* score, XmlReader& e, ReadContext& ctx)
3432 : {
3433 844 : while (e.readNextStartElement()) {
3434 805 : ctx.setTrack(muse::nidx);
3435 805 : const AsciiStringView tag(e.name());
3436 805 : if (tag == "Staff") {
3437 60 : readStaffContent206(score, e, ctx);
3438 745 : } else if (tag == "siglist") {
3439 0 : readTimeSigMap(ctx.compatTimeSigMap(), e, ctx);
3440 745 : } else if (tag == "Omr") {
3441 0 : e.skipCurrentElement();
3442 745 : } else if (tag == "Audio") {
3443 0 : e.skipCurrentElement();
3444 745 : } else if (tag == "showOmr") {
3445 0 : e.skipCurrentElement();
3446 745 : } else if (tag == "playMode") {
3447 0 : e.skipCurrentElement();
3448 745 : } else if (tag == "LayerTag") {
3449 5 : e.skipCurrentElement();
3450 740 : } else if (tag == "Layer") {
3451 0 : e.skipCurrentElement();
3452 740 : } else if (tag == "currentLayer") {
3453 5 : e.skipCurrentElement();
3454 735 : } else if (tag == "Synthesizer") {
3455 25 : score->synthesizerState().read(e);
3456 710 : } else if (tag == "page-offset") {
3457 0 : score->setPageNumberOffset(e.readInt());
3458 710 : } else if (tag == "Division") {
3459 39 : score->setFileDivision(e.readInt());
3460 671 : } else if (tag == "showInvisible") {
3461 39 : score->setShowInvisible(e.readInt());
3462 632 : } else if (tag == "showUnprintable") {
3463 39 : score->setShowUnprintable(e.readInt());
3464 593 : } else if (tag == "showFrames") {
3465 39 : score->setShowFrames(e.readInt());
3466 554 : } else if (tag == "showMargins") {
3467 39 : score->setShowPageborders(e.readInt());
3468 515 : } else if (tag == "Style") {
3469 39 : double sp = score->style().value(Sid::spatium).toReal();
3470 39 : ReadChordListHook clhook(score);
3471 39 : readStyle206(&score->style(), e, ctx, clhook);
3472 39 : if (score->style().styleSt(Sid::musicalTextFont) == "MuseJazz") {
3473 1 : score->style().set(Sid::musicalTextFont, "MuseJazz Text");
3474 : }
3475 39 : if (ctx.overrideSpatium()) {
3476 0 : ctx.setOriginalSpatium(score->style().spatium());
3477 0 : score->style().set(Sid::spatium, sp);
3478 : }
3479 39 : score->setEngravingFont(score->engravingFonts()->fontByName(score->style().styleSt(Sid::musicalSymbolFont).toStdString()));
3480 515 : } else if (tag == "copyright" || tag == "rights") {
3481 0 : Text* text = Factory::createText(score->dummy(), TextStyleType::DEFAULT, false);
3482 0 : readText206(e, ctx, text, text);
3483 0 : score->setMetaTag(u"copyright", text->xmlText());
3484 0 : delete text;
3485 476 : } else if (tag == "movement-number") {
3486 0 : score->setMetaTag(u"movementNumber", e.readText());
3487 476 : } else if (tag == "movement-title") {
3488 0 : score->setMetaTag(u"movementTitle", e.readText());
3489 476 : } else if (tag == "work-number") {
3490 0 : score->setMetaTag(u"workNumber", e.readText());
3491 476 : } else if (tag == "work-title") {
3492 0 : score->setMetaTag(u"workTitle", e.readText());
3493 476 : } else if (tag == "source") {
3494 0 : score->setMetaTag(u"source", e.readText());
3495 476 : } else if (tag == "metaTag") {
3496 381 : String name = e.attribute("name");
3497 381 : score->setMetaTag(name, e.readText());
3498 476 : } else if (tag == "Part") {
3499 55 : Part* part = new Part(score);
3500 55 : Read206::readPart206(part, e, ctx);
3501 55 : score->appendPart(part);
3502 40 : } else if ((tag == "HairPin") // TODO: do this elements exist here?
3503 40 : || (tag == "Ottava")
3504 40 : || (tag == "TextLine")
3505 40 : || (tag == "Volta")
3506 40 : || (tag == "Trill")
3507 40 : || (tag == "Slur")
3508 80 : || (tag == "Pedal")) {
3509 0 : Spanner* s = toSpanner(Factory::createItemByName(tag, score->dummy()));
3510 0 : if (tag == "HairPin") {
3511 0 : readHairpin206(e, ctx, toHairpin(s));
3512 0 : } else if (tag == "Ottava") {
3513 0 : readOttava(e, ctx, toOttava(s));
3514 0 : } else if (tag == "TextLine") {
3515 0 : Read206::readTextLine206(e, ctx, toTextLine(s));
3516 0 : } else if (tag == "Volta") {
3517 0 : readVolta206(e, ctx, toVolta(s));
3518 0 : } else if (tag == "Trill") {
3519 0 : Read206::readTrill206(e, ctx, toTrill(s));
3520 0 : } else if (tag == "Slur") {
3521 0 : readSlur206(e, ctx, toSlur(s));
3522 : } else {
3523 0 : assert(tag == "Pedal");
3524 0 : readPedal(e, ctx, toPedal(s));
3525 : }
3526 0 : score->addSpanner(s);
3527 40 : } else if (tag == "Score") { // recursion
3528 6 : ctx.tracks().clear();
3529 6 : ctx.clearUserTextStyles();
3530 6 : MasterScore* m = score->masterScore();
3531 6 : Score* s = m->createScore();
3532 6 : ReadStyleHook::setupDefaultStyle(s);
3533 6 : Excerpt* ex = new Excerpt(m);
3534 :
3535 6 : ex->setExcerptScore(s);
3536 6 : ctx.setLastMeasure(nullptr);
3537 6 : ReadContext exCtx(s);
3538 :
3539 6 : s->setIsOpen(true);
3540 6 : readScoreTag(s, e, exCtx);
3541 :
3542 6 : ex->setTracksMapping(ctx.tracks());
3543 6 : m->addExcerpt(ex);
3544 40 : } else if (tag == "PageList") {
3545 28 : e.skipCurrentElement();
3546 6 : } else if (tag == "name") {
3547 6 : String n = e.readText();
3548 6 : if (!score->isMaster()) { //ignore the name if it's not a child score
3549 6 : score->excerpt()->setName(n, /*saveAndNotify=*/ false);
3550 : }
3551 6 : } else if (tag == "layoutMode") {
3552 0 : if (ctx.forcePageMode()) {
3553 0 : e.skipCurrentElement();
3554 0 : continue;
3555 : }
3556 0 : String s = e.readText();
3557 0 : if (s == "line") {
3558 0 : score->setLayoutMode(LayoutMode::LINE);
3559 0 : } else if (s == "system") {
3560 0 : score->setLayoutMode(LayoutMode::SYSTEM);
3561 : } else {
3562 0 : LOGD("layoutMode: %s", muPrintable(s));
3563 : }
3564 0 : } else {
3565 0 : e.unknown();
3566 : }
3567 : }
3568 39 : if (e.error() != muse::XmlStreamReader::NoError) {
3569 0 : LOGE() << muse::String(u"XML read error at byte offset %1: %2").arg(e.byteOffset())
3570 0 : .arg(muse::String::fromAscii(e.name().ascii()));
3571 0 : return false;
3572 : }
3573 :
3574 39 : score->setFileDivision(Constants::DIVISION);
3575 :
3576 39 : score->updateTicksAndTimeSigMap();
3577 39 : if (score->isMaster()) {
3578 : // While reading the score, some elements might use `score->repeatList()` (which is incorrect
3579 : // anyway, because the repeatList will be incomplete because the score is incomplete, but some
3580 : // elements still do it).
3581 : // `score->repeatList()` calls `_repeatList->update()`; the repeat list then thinks that it is
3582 : // up-to-date from that point. But we weren't finished reading the score, so the score will still
3583 : // change. We need to tell the repeat list about that, so that it will be updated next time
3584 : // someone uses it.
3585 33 : static_cast<MasterScore*>(score)->invalidateRepeatList();
3586 : }
3587 39 : score->connectTies();
3588 39 : score->undoRemoveStaleTieJumpPoints(false);
3589 :
3590 94 : for (Part* p : score->parts()) {
3591 55 : p->updateHarmonyChannels(false);
3592 : }
3593 :
3594 39 : if (score->isMaster()) {
3595 33 : MasterScore* ms = static_cast<MasterScore*>(score);
3596 33 : ms->rebuildMidiMapping();
3597 33 : ms->updateChannel();
3598 : }
3599 :
3600 39 : if (score->isMaster()) {
3601 33 : CompatUtils::assignInitialPartToExcerpts(score->masterScore()->excerpts());
3602 : }
3603 :
3604 39 : return true;
3605 : }
3606 :
3607 33 : Ret Read206::readScoreFile(Score* score, XmlReader& e, ReadInOutData* out)
3608 : {
3609 33 : ReadContext ctx(score);
3610 33 : if (out) {
3611 33 : if (out->overriddenSpatium.has_value()) {
3612 0 : ctx.setSpatium(out->overriddenSpatium.value());
3613 0 : ctx.setOverrideSpatium(true);
3614 : }
3615 :
3616 33 : ctx.setPropertiesToSkip(out->propertiesToSkip);
3617 33 : ctx.setForcePageMode(out->forcePageMode);
3618 : }
3619 33 : DEFER {
3620 33 : if (out) {
3621 33 : out->settingsCompat = std::move(ctx.settingCompat());
3622 : }
3623 33 : };
3624 :
3625 112 : while (e.readNextStartElement()) {
3626 79 : const AsciiStringView tag(e.name());
3627 79 : if (tag == "programVersion") {
3628 23 : score->setMscoreVersion(e.readText());
3629 56 : } else if (tag == "programRevision") {
3630 23 : score->setMscoreRevision(e.readInt(nullptr, 16));
3631 33 : } else if (tag == "Score") {
3632 33 : if (!readScoreTag(score, e, ctx)) {
3633 0 : if (e.error() == muse::XmlStreamReader::CustomError) {
3634 0 : return make_ret(Err::FileCriticallyCorrupted, e.errorString());
3635 : }
3636 0 : return make_ret(Err::FileBadFormat, e.errorString());
3637 : }
3638 :
3639 33 : if (ctx.overrideSpatium() && out) {
3640 0 : out->originalSpatium = ctx.originalSpatium();
3641 : }
3642 0 : } else if (tag == "Revision") {
3643 0 : e.skipCurrentElement();
3644 : }
3645 : }
3646 :
3647 87 : for (Staff* s : score->staves()) {
3648 54 : s->updateOttava();
3649 : }
3650 :
3651 : // convert int bar line span to bool
3652 :
3653 : // also sets Pid::BARLINE_SPAN to non-generated and affected bar lines
3654 33 : read114::Read114::setBarLineSpanToStaves(score, ctx);
3655 :
3656 : // set local overrides to bar lines
3657 33 : constexpr auto st = SegmentType::BarLineTypes;
3658 33 : const size_t numStaves = score->nstaves();
3659 298 : for (Segment* s = score->firstSegment(st); s; s = s->next1(st)) {
3660 : // optional local bar line span override of this segment
3661 265 : std::optional<size_t> barLineSpan = std::nullopt;
3662 620 : for (staff_idx_t staffIdx = 0; staffIdx < numStaves; ++staffIdx) {
3663 355 : const size_t maxSpan = numStaves - staffIdx - 1;
3664 355 : const track_idx_t trackIdx = staff2track(staffIdx);
3665 355 : EngravingItem* el = s->element(trackIdx);
3666 355 : BarLine* barLine = el && el->isBarLine() ? toBarLine(el) : nullptr;
3667 355 : if (barLine) {
3668 55 : if (const std::optional<size_t> span = ctx.getBarLineSpan(barLine)) {
3669 55 : if (*span > maxSpan) {
3670 0 : LOGW() << "invalid bar line span " << *span << " (max " << maxSpan << ")";
3671 0 : barLineSpan = maxSpan;
3672 : } else {
3673 55 : barLineSpan = std::max(barLineSpan.value_or(0), *span);
3674 : }
3675 : }
3676 : }
3677 :
3678 355 : if (!barLineSpan) {
3679 : // we don't have a local override. Keep the value from staff
3680 288 : continue;
3681 : }
3682 :
3683 67 : const bool shouldBarLineSpan = *barLineSpan != 0;
3684 67 : const bool staffBarLineSpan = score->staff(staffIdx)->barLineSpan();
3685 67 : if (shouldBarLineSpan != staffBarLineSpan) {
3686 : // bar line should have local override
3687 13 : if (!barLine) {
3688 : // clone previous bar line. This is safe because we always have a previous barline when
3689 : // barLineSpan != std::nullopt because it's either the one that was read or the one cloned
3690 : // in the previous iteration
3691 6 : el = s->element(staff2track(staffIdx - 1));
3692 6 : if (el && el->isBarLine()) {
3693 6 : barLine = toBarLine(el)->clone();
3694 6 : barLine->setTrack(trackIdx);
3695 6 : s->add(barLine);
3696 : }
3697 : }
3698 :
3699 13 : if (barLine) {
3700 13 : barLine->setSpanStaff(shouldBarLineSpan);
3701 : }
3702 : }
3703 67 : if (*barLineSpan == 0) {
3704 : // we're done applying the local override
3705 55 : barLineSpan.reset();
3706 : } else {
3707 12 : --(*barLineSpan);
3708 : }
3709 : }
3710 : }
3711 :
3712 33 : return make_ok();
3713 33 : }
3714 :
3715 0 : bool Read206::pasteStaff(XmlReader&, Segment*, staff_idx_t, Fraction)
3716 : {
3717 0 : UNREACHABLE;
3718 : return false;
3719 : }
3720 :
3721 0 : void Read206::pasteSymbols(XmlReader&, ChordRest*)
3722 : {
3723 0 : UNREACHABLE;
3724 : }
3725 :
3726 0 : void Read206::readTremoloCompat(compat::TremoloCompat*, XmlReader&)
3727 : {
3728 0 : UNREACHABLE;
3729 : }
3730 :
3731 0 : void Read206::doReadItem(EngravingItem*, XmlReader&)
3732 : {
3733 0 : UNREACHABLE;
3734 : }
|