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 "style.h"
24 :
25 : #include "global/modularity/ioc.h"
26 :
27 : #include "iengravingfontsprovider.h"
28 :
29 : #include "types/constants.h"
30 : #include "compat/pageformat.h"
31 : #include "rw/compat/readchordlisthook.h"
32 : #include "rw/compat/compatutils.h"
33 : #include "rw/xmlreader.h"
34 : #include "rw/xmlwriter.h"
35 : #include "types/typesconv.h"
36 :
37 : #include "dom/mscore.h"
38 : #include "dom/pedal.h"
39 :
40 : #include "defaultstyle.h"
41 :
42 : #include "log.h"
43 :
44 : using namespace mu;
45 : using namespace muse::io;
46 : using namespace mu::engraving;
47 :
48 27628261 : const PropertyValue& MStyle::value(Sid idx) const
49 : {
50 27628261 : if (idx == Sid::NOSTYLE) {
51 0 : static PropertyValue dummy;
52 0 : return dummy;
53 : }
54 :
55 27628261 : const PropertyValue& val = m_values[size_t(idx)];
56 27628261 : if (val.isValid()) {
57 9048817 : return val;
58 : }
59 :
60 18579444 : return StyleDef::styleValues[size_t(idx)].defaultValue;
61 : }
62 :
63 2591260 : double MStyle::valueAbsolute(Sid idx) const
64 : {
65 2591260 : if (idx == Sid::NOSTYLE) {
66 0 : return 0.0;
67 : }
68 :
69 2591260 : return m_precomputedValues[size_t(idx)];
70 : }
71 :
72 270351 : void MStyle::set(const Sid t, const PropertyValue& val)
73 : {
74 270351 : if (t == Sid::NOSTYLE) {
75 0 : return;
76 : }
77 :
78 270351 : const size_t idx = size_t(t);
79 270351 : m_values[idx] = val;
80 270351 : if (t == Sid::spatium) {
81 1308 : precomputeValues();
82 : } else {
83 269043 : if (StyleDef::styleValues[idx].valueType() == P_TYPE::SPATIUM) {
84 34273 : double _spatium = value(Sid::spatium).toReal();
85 34273 : m_precomputedValues[idx] = m_values[idx].value<Spatium>().val() * _spatium;
86 : }
87 : }
88 : }
89 :
90 2572238 : double MStyle::defaultSpatium() const
91 : {
92 2572238 : return StyleDef::styleValues[static_cast<size_t>(Sid::spatium)].defaultValue.toDouble();
93 : }
94 :
95 1556 : void MStyle::precomputeValues()
96 : {
97 1556 : double _spatium = value(Sid::spatium).toReal();
98 3236480 : for (const StyleDef::StyleValue& t : StyleDef::styleValues) {
99 3234924 : if (t.valueType() == P_TYPE::SPATIUM) {
100 815344 : m_precomputedValues[t.idx()] = value(t.sid).value<Spatium>().val() * _spatium;
101 : }
102 : }
103 1556 : }
104 :
105 2292062 : bool MStyle::isDefault(Sid idx) const
106 : {
107 2292062 : return value(idx) == DefaultStyle::resolveStyleDefaults(defaultStyleVersion()).value(idx);
108 : }
109 :
110 626 : void MStyle::setDefaultStyleVersion(const int defaultsVersion)
111 : {
112 626 : set(Sid::defaultsVersion, defaultsVersion);
113 626 : }
114 :
115 2292200 : int MStyle::defaultStyleVersion() const
116 : {
117 2292200 : return styleI(Sid::defaultsVersion);
118 : }
119 :
120 106011 : bool MStyle::readProperties(XmlReader& e)
121 : {
122 106011 : const AsciiStringView tag(e.name());
123 :
124 101738182 : for (const StyleDef::StyleValue& t : StyleDef::styleValues) {
125 101737982 : Sid idx = t.sid;
126 101737982 : if (t.xmlName == tag) {
127 105811 : P_TYPE type = t.valueType();
128 105811 : switch (type) {
129 23813 : case P_TYPE::SPATIUM:
130 23813 : set(idx, Spatium(e.readDouble()));
131 23813 : break;
132 14326 : case P_TYPE::REAL:
133 14326 : set(idx, e.readDouble());
134 14326 : break;
135 13758 : case P_TYPE::BOOL:
136 13758 : set(idx, bool(e.readInt()));
137 13758 : break;
138 13418 : case P_TYPE::INT:
139 13418 : set(idx, e.readInt());
140 13418 : break;
141 101 : case P_TYPE::DIRECTION_V:
142 101 : set(idx, DirectionV(e.readInt()));
143 101 : break;
144 10371 : case P_TYPE::STRING:
145 10371 : set(idx, e.readText());
146 10371 : break;
147 4298 : case P_TYPE::ALIGN: {
148 4298 : Align align = TConv::fromXml(e.readText(), Align());
149 4298 : set(idx, align);
150 4298 : } break;
151 447 : case P_TYPE::ALIGN_H: {
152 447 : AlignH align = TConv::fromXml(e.readAsciiText(), AlignH::HCENTER);
153 447 : set(idx, align);
154 447 : } break;
155 7264 : case P_TYPE::POINT: {
156 7264 : double x = e.doubleAttribute("x", 0.0);
157 7264 : double y = e.doubleAttribute("y", 0.0);
158 7264 : set(idx, PointF(x, y));
159 7264 : e.readText();
160 7264 : } break;
161 0 : case P_TYPE::SIZE: {
162 0 : double x = e.doubleAttribute("w", 0.0);
163 0 : double y = e.doubleAttribute("h", 0.0);
164 0 : set(idx, SizeF(x, y));
165 0 : e.readText();
166 0 : } break;
167 51 : case P_TYPE::SCALE: {
168 51 : double sx = e.doubleAttribute("w", 0.0);
169 51 : double sy = e.doubleAttribute("h", 0.0);
170 51 : set(idx, ScaleF(sx, sy));
171 51 : e.readText();
172 51 : } break;
173 14296 : case P_TYPE::COLOR: {
174 14296 : Color c;
175 14296 : c.setRed(e.intAttribute("r"));
176 14296 : c.setGreen(e.intAttribute("g"));
177 14296 : c.setBlue(e.intAttribute("b"));
178 14296 : c.setAlpha(e.intAttribute("a", 255));
179 14296 : set(idx, c);
180 14296 : e.readText();
181 14296 : } break;
182 2590 : case P_TYPE::PLACEMENT_V:
183 2590 : set(idx, PlacementV(e.readText().toInt()));
184 2590 : break;
185 0 : case P_TYPE::PLACEMENT_H:
186 0 : set(idx, PlacementH(e.readText().toInt()));
187 0 : break;
188 2 : case P_TYPE::DIRECTION_H:
189 2 : set(idx, DirectionH(e.readText().toInt()));
190 2 : break;
191 2 : case P_TYPE::ORIENTATION:
192 2 : set(idx, TConv::fromXml(e.readAsciiText(), Orientation::HORIZONTAL));
193 2 : break;
194 2 : case P_TYPE::SHARED_LABEL_ORIENTATION:
195 2 : set(idx, TConv::fromXml(e.readAsciiText(), SharedLabelOrientation::HORIZONTAL));
196 2 : break;
197 163 : case P_TYPE::HOOK_TYPE:
198 163 : set(idx, HookType(e.readText().toInt()));
199 163 : break;
200 595 : case P_TYPE::LINE_TYPE:
201 595 : set(idx, TConv::fromXml(e.readAsciiText(), LineType::SOLID));
202 595 : break;
203 0 : case P_TYPE::CLEF_TO_BARLINE_POS:
204 0 : set(idx, ClefToBarlinePosition(e.readInt()));
205 0 : break;
206 53 : case P_TYPE::TIE_PLACEMENT:
207 53 : set(idx, TConv::fromXml(e.readAsciiText(), TiePlacement::AUTO));
208 53 : break;
209 17 : case P_TYPE::TIE_DOTS_PLACEMENT:
210 17 : set(idx, TConv::fromXml(e.readAsciiText(), TieDotsPlacement::AUTO));
211 17 : break;
212 48 : case P_TYPE::GLISS_STYLE:
213 48 : set(idx, GlissandoStyle(e.readText().toInt()));
214 48 : break;
215 17 : case P_TYPE::GLISS_TYPE:
216 17 : set(idx, GlissandoType(e.readText().toInt()));
217 17 : break;
218 17 : case P_TYPE::TIMESIG_PLACEMENT:
219 17 : set(idx, TConv::fromXml(e.readAsciiText(), TimeSigPlacement::NORMAL));
220 17 : break;
221 51 : case P_TYPE::TIMESIG_STYLE:
222 51 : set(idx, TConv::fromXml(e.readAsciiText(), TimeSigStyle::NORMAL));
223 51 : break;
224 34 : case P_TYPE::TIMESIG_MARGIN:
225 34 : set(idx, TConv::fromXml(e.readAsciiText(), TimeSigVSMargin::RIGHT_ALIGN_TO_BARLINE));
226 34 : break;
227 6 : case P_TYPE::NOTE_SPELLING_TYPE:
228 6 : set(idx, TConv::fromXml(e.readAsciiText(), NoteSpellingType::STANDARD));
229 6 : break;
230 13 : case P_TYPE::CHORD_PRESET_TYPE:
231 13 : set(idx, TConv::fromXml(e.readAsciiText(), ChordStylePreset::STANDARD));
232 13 : break;
233 0 : case P_TYPE::PARENTHESES_MODE:
234 0 : set(idx, TConv::fromXml(e.readAsciiText(), ParenthesesMode::NONE));
235 0 : break;
236 12 : case P_TYPE::LH_TAPPING_SYMBOL:
237 12 : set(idx, TConv::fromXml(e.readAsciiText(), LHTappingSymbol::DOT));
238 12 : break;
239 12 : case P_TYPE::RH_TAPPING_SYMBOL:
240 12 : set(idx, TConv::fromXml(e.readAsciiText(), RHTappingSymbol::T));
241 12 : break;
242 12 : case P_TYPE::TEXT_STYLE:
243 12 : set(idx, TConv::fromXml(e.readAsciiText(), TextStyleType::DEFAULT));
244 12 : break;
245 6 : case P_TYPE::PLAY_COUNT_PRESET:
246 6 : set(idx, TConv::fromXml(e.readAsciiText(), RepeatPlayCountPreset::X_N));
247 6 : break;
248 6 : case P_TYPE::MEASURE_NUMBER_PLACEMENT:
249 6 : set(idx, TConv::fromXml(e.readAsciiText(), MeasureNumberPlacement::ABOVE_SYSTEM));
250 6 : break;
251 4 : case P_TYPE::INSTRUMENT_NAMES_ALIGN:
252 4 : set(idx, TConv::fromXml(e.readAsciiText(), InstrumentNamesAlign::RIGHT_RIGHT));
253 4 : break;
254 4 : case P_TYPE::INSTRUMENT_NAMES_FORMAT:
255 4 : set(idx, TConv::fromXml(e.readAsciiText(), InstrumentNamesFormat::NAME_IN_TRANSP_NUM));
256 4 : break;
257 2 : case P_TYPE::AUTO_ON_OFF:
258 2 : set(idx, TConv::fromXml(e.readAsciiText(), AutoOnOff::AUTO));
259 2 : break;
260 0 : default:
261 0 : ASSERT_X(u"unhandled type " + String::number(int(type)));
262 : }
263 105811 : return true;
264 : }
265 : }
266 200 : if (readStyleValCompat(e)) {
267 8 : return true;
268 : }
269 192 : return false;
270 : }
271 :
272 : //---------------------------------------------------------
273 : // readStyleValCompat
274 : // Read obsolete style values which may appear in files
275 : // produced by older versions of MuseScore.
276 : //---------------------------------------------------------
277 :
278 200 : bool MStyle::readStyleValCompat(XmlReader& e)
279 : {
280 200 : const AsciiStringView tag(e.name());
281 200 : if (tag == "tempoOffset") { // pre-3.0-beta
282 0 : const double x = e.doubleAttribute("x", 0.0);
283 0 : const double y = e.doubleAttribute("y", 0.0);
284 0 : const PointF val(x, y);
285 0 : set(Sid::tempoPosAbove, val);
286 0 : set(Sid::tempoPosBelow, val);
287 0 : e.readText();
288 0 : return true;
289 : }
290 200 : if (readTextStyleValCompat(e)) {
291 8 : return true;
292 : }
293 192 : return false;
294 : }
295 :
296 : //---------------------------------------------------------
297 : // readTextStyleValCompat
298 : // Handle transition from separate bold, underline, strike
299 : // and italic style properties to the single *FontStyle
300 : // property set.
301 : //---------------------------------------------------------
302 :
303 200 : bool MStyle::readTextStyleValCompat(XmlReader& e)
304 : {
305 : static const std::array<std::pair<String, FontStyle>, 4> styleNamesEndings { {
306 0 : { u"FontBold", FontStyle::Bold },
307 0 : { u"FontItalic", FontStyle::Italic },
308 0 : { u"FontUnderline", FontStyle::Underline },
309 6 : { u"FontStrike", FontStyle::Strike }
310 200 : } };
311 :
312 200 : const String tag = String::fromAscii(e.name().ascii());
313 200 : FontStyle readFontStyle = FontStyle::Normal;
314 200 : String typeName;
315 976 : for (auto& fontStyle : styleNamesEndings) {
316 784 : if (tag.endsWith(fontStyle.first)) {
317 8 : readFontStyle = fontStyle.second;
318 8 : typeName = tag.mid(0, tag.size() - fontStyle.first.size());
319 8 : break;
320 : }
321 : }
322 200 : if (readFontStyle == FontStyle::Normal) {
323 192 : return false;
324 : }
325 :
326 8 : const String newFontStyleName = typeName + u"FontStyle";
327 8 : const Sid sid = MStyle::styleIdx(newFontStyleName);
328 8 : if (sid == Sid::NOSTYLE) {
329 0 : LOGW() << "readFontStyleValCompat: couldn't read text readFontStyle value:" << tag;
330 0 : return false;
331 : }
332 :
333 8 : const bool readVal = bool(e.readText().toInt());
334 8 : const PropertyValue& val = value(sid);
335 8 : FontStyle newFontStyle = val.isValid() ? FontStyle(val.toInt()) : FontStyle::Normal;
336 8 : if (readVal) {
337 0 : newFontStyle = newFontStyle + readFontStyle;
338 : } else {
339 8 : newFontStyle = newFontStyle - readFontStyle;
340 : }
341 :
342 8 : set(sid, int(newFontStyle));
343 8 : return true;
344 200 : }
345 :
346 923 : void MStyle::applyCompatStyleVals(int mscVersion)
347 : {
348 923 : if (mscVersion < 500) {
349 638 : set(Sid::windsNameByGroup, false);
350 638 : set(Sid::vocalsNameByGroup, false);
351 638 : set(Sid::maskSlurs, false);
352 638 : set(Sid::maskTies, false);
353 638 : set(Sid::dashBarWidth, value(Sid::barWidth));
354 638 : set(Sid::lyricsStackingOrder, int(LyricsStackingOrder::LYRICS_AFTER_PEDALS));
355 638 : set(Sid::bendAlign, Align(AlignH::LEFT, AlignV::TOP)); // pre-5.0 this had no effect but was set incorrectly
356 : }
357 :
358 923 : if (mscVersion < 470) {
359 632 : set(Sid::dividerLeftAlignToSystemBarline, false);
360 632 : set(Sid::dividerRightAlignToSystemBarline, false);
361 :
362 : // Musical symbol size
363 632 : compat::CompatUtils::setMusicSymbolSize470(*this);
364 :
365 : // Make sure new position styles are initially the same as align values
366 : // Exclude text styles which had align & position separated in 4.6
367 1264 : compat::CompatUtils::setPositionStylesFromAlign(this, { Sid::chordSymbolAAlign, Sid::chordSymbolBAlign, Sid::romanNumeralAlign,
368 : Sid::nashvilleNumberAlign, Sid::repeatLeftAlign, Sid::repeatRightAlign });
369 :
370 632 : if (value(Sid::chordStyle).value<ChordStylePreset>() == ChordStylePreset::JAZZ) {
371 0 : set(Sid::harmonyParenUseSmuflSym, true);
372 : }
373 : }
374 :
375 923 : if (mscVersion < 460) {
376 595 : bool verticalChordAlign = value(Sid::maxChordShiftAbove).value<Spatium>() != 0.0_sp
377 595 : || value(Sid::maxChordShiftBelow).value<Spatium>() != 0.0_sp
378 595 : || value(Sid::maxFretShiftAbove).value<Spatium>() != 0.0_sp
379 1190 : || value(Sid::maxFretShiftBelow).value<Spatium>() != 0.0_sp;
380 595 : set(Sid::verticallyAlignChordSymbols, verticalChordAlign);
381 : // Make sure new position styles are initially the same as align values
382 595 : compat::CompatUtils::setPositionStylesFromAlign(this);
383 :
384 595 : if (value(Sid::measureNumberPosition).value<AlignH>() == AlignH::HCENTER) {
385 447 : set(Sid::measureNumberHPlacement, AlignH::HCENTER);
386 : }
387 :
388 595 : if (value(Sid::pedalPlacement).value<PlacementV>() == PlacementV::BELOW
389 595 : && value(Sid::pedalHookHeight).value<Spatium>().val() < 0) {
390 71 : set(Sid::pedalHookHeight, -value(Sid::pedalHookHeight).value<Spatium>());
391 : }
392 595 : if (value(Sid::ottavaHookBelow).value<Spatium>().val() < 0) {
393 71 : set(Sid::ottavaHookBelow, -value(Sid::ottavaHookBelow).value<Spatium>());
394 : }
395 595 : set(Sid::repeatPlayCountShow, false);
396 :
397 595 : set(Sid::harmonyHarmonyDistance, value(Sid::minHarmonyDistance));
398 : }
399 :
400 923 : if (mscVersion == 450) {
401 : // 450 spacing was a bit narrower
402 14 : set(Sid::spacingDensity, 1.30);
403 : }
404 :
405 923 : if (mscVersion < 450) {
406 : // Didn't exist before 4.5. Default to false for compatibility.
407 581 : set(Sid::scaleRythmicSpacingForSmallNotes, false);
408 581 : set(Sid::maskBarlinesForText, false);
409 581 : set(Sid::showCourtesiesRepeats, false);
410 581 : set(Sid::showCourtesiesOtherJumps, false);
411 581 : set(Sid::showCourtesiesAfterCancellingRepeats, false);
412 581 : set(Sid::showCourtesiesAfterCancellingOtherJumps, false);
413 581 : set(Sid::changesBeforeBarlineRepeats, false);
414 581 : set(Sid::changesBeforeBarlineOtherJumps, false);
415 : }
416 :
417 923 : if (mscVersion < 420 && !MScore::testMode) {
418 : // This style didn't exist before version 4.2. For files older than 4.2, defaults
419 : // to INSIDE for compatibility. For files 4.2 and newer, defaults to OUTSIDE.
420 0 : set(Sid::tiePlacementChord, TiePlacement::INSIDE);
421 : }
422 923 : }
423 :
424 79 : bool MStyle::read(IODevice* device, bool ign)
425 : {
426 : UNUSED(ign);
427 79 : XmlReader e(device);
428 237 : while (e.readNextStartElement()) {
429 79 : if (e.name() == "museScore") {
430 79 : const String versionTag = e.attribute("version").remove(u'.');
431 79 : const int mscVersion = versionTag.toInt();
432 158 : while (e.readNextStartElement()) {
433 79 : if (e.name() == "Style") {
434 79 : read(e, nullptr, mscVersion);
435 : } else {
436 0 : e.unknown();
437 : }
438 : }
439 79 : }
440 : }
441 79 : return true;
442 79 : }
443 :
444 0 : bool MStyle::isValid(IODevice* device)
445 : {
446 0 : XmlReader e(device);
447 0 : while (!e.isError() && e.readNextStartElement()) {
448 0 : if (e.name() == "museScore") {
449 0 : while (e.readNextStartElement()) {
450 0 : if (e.name() == "Style") {
451 0 : return true;
452 : }
453 : }
454 : }
455 : }
456 0 : return false;
457 0 : }
458 :
459 923 : void MStyle::read(XmlReader& e, compat::ReadChordListHook* readChordListHook, int mscVersion)
460 : {
461 923 : TRACEFUNC;
462 :
463 116377 : while (e.readNextStartElement()) {
464 115454 : const AsciiStringView tag(e.name());
465 :
466 115454 : if (tag == "TextStyle") {
467 : //readTextStyle206(this, e); // obsolete
468 0 : e.readText();
469 115454 : } else if (tag == "ottavaHook") { // obsolete, for 3.0dev bw. compatibility, should be removed in final release
470 0 : double y = std::abs(e.readDouble());
471 0 : set(Sid::ottavaHookAbove, y);
472 0 : set(Sid::ottavaHookBelow, -y);
473 115454 : } else if (tag == "Spatium" || tag == "spatium") {
474 918 : set(Sid::spatium, e.readDouble() * DPMM);
475 114536 : } else if (tag == "page-layout") { // obsolete
476 0 : compat::readPageFormat206(this, e);
477 114536 : } else if (tag == "displayInConcertPitch") {
478 0 : set(Sid::concertPitch, e.readBool());
479 114536 : } else if (tag == "ChordList") {
480 1 : if (readChordListHook) {
481 1 : readChordListHook->read(e);
482 : }
483 114535 : } else if (tag == "lyricsDashMaxLegth") { // pre-3.6 typo
484 9 : set(Sid::lyricsDashMaxLength, Spatium(e.readDouble()));
485 114526 : } else if (tag == "dontHidStavesInFirstSystm") { // pre-3.6.3/4.0 typo
486 11 : set(Sid::dontHideStavesInFirstSystem, e.readBool());
487 114515 : } else if (tag == "minSpreadSpread") { // pre-4.4 typo
488 48 : set(Sid::minStaffSpread, Spatium(e.readDouble()));
489 114467 : } else if (tag == "maxSpreadSpread") { // pre-4.4 typo
490 48 : set(Sid::maxStaffSpread, Spatium(e.readDouble()));
491 114419 : } else if (tag == "beamDistance") { // beamDistance maps to useWideBeams in 4.0
492 19 : set(Sid::useWideBeams, e.readDouble() > 0.75);
493 114400 : } else if (tag == "hairpinWidth") { // pre-4.4 typo
494 58 : set(Sid::hairpinLineWidth, Spatium(e.readDouble()));
495 114342 : } else if (tag == "chordSymbolPosAbove") { // pre-4.4 typo
496 57 : set(Sid::chordSymbolAPosAbove, e.readPoint());
497 114285 : } else if (tag == "chordSymbolPosBelow") { // pre-4.4 typo
498 57 : set(Sid::chordSymbolAPosBelow, e.readPoint());
499 114228 : } else if (tag == "dontHidStavesInFirstSystm") { // pre-3.6.3/4.0 typo
500 0 : set(Sid::dontHideStavesInFirstSystem, e.readBool());
501 114228 : } else if (tag == "firstSystemInsNameVisibility") { // pre-4.4 typo
502 0 : set(Sid::firstSystemInstNameVisibility, e.readInt());
503 114228 : } else if ((tag == "articulationMinDistance"
504 114149 : || tag == "propertyDistanceHead"
505 114070 : || tag == "propertyDistanceStem"
506 113990 : || tag == "propertyDistance"
507 113911 : || tag == "bracketDistance")
508 228377 : && mscVersion < 400) {
509 : // Ignoring pre-4.0 articulation style and brackets distance settings. Using the new defaults instead
510 62 : e.skipCurrentElement();
511 114166 : } else if (tag == "pedalListStyle") { // pre-3.6.3/4.0 typo
512 52 : set(Sid::pedalLineStyle, TConv::fromXml(e.readAsciiText(), LineType::SOLID));
513 114114 : } else if (tag == "chordlineThickness" && mscVersion < 410) {
514 : // Ignoring pre-4.1 value as it was wrong (it wasn't user-editable anyway)
515 4 : e.skipCurrentElement();
516 114110 : } else if (tag == "pedalText" && mscVersion < 420) {
517 : // Ignore old default
518 1 : String pedText = e.readText();
519 1 : if (!pedText.empty()) {
520 0 : set(Sid::pedalText, pedText);
521 : }
522 114110 : } else if (tag == "pedalContinueText" && mscVersion < 420) {
523 : // Ignore old default
524 1 : String pedContText = e.readText();
525 1 : if (!pedContText.empty()) {
526 0 : set(Sid::pedalText, pedContText);
527 : }
528 114109 : } else if (tag == "ArpeggioNoteDistance") { // pre-4.4 typo
529 57 : set(Sid::arpeggioNoteDistance, Spatium(e.readDouble()));
530 114051 : } else if (tag == "ArpeggioAccidentalDistance") { // pre-4.4 typo
531 46 : set(Sid::arpeggioAccidentalDistance, Spatium(e.readDouble()));
532 114005 : } else if (tag == "ArpeggioAccidentalDistanceMin") { // pre-4.4 typo
533 46 : set(Sid::arpeggioAccidentalDistanceMin, Spatium(e.readDouble()));
534 113959 : } else if (tag == "ArpeggioLineWidth") { // pre-x.4 typo
535 57 : set(Sid::arpeggioLineWidth, Spatium(e.readDouble()));
536 113902 : } else if (tag == "ArpeggioHookLen") { // pre-x.4 typo
537 57 : set(Sid::arpeggioHookLen, Spatium(e.readDouble()));
538 113845 : } else if (tag == "ArpeggioHiddenInStdIfTab") { // pre-x.4 typo
539 57 : set(Sid::arpeggioHiddenInStdIfTab, e.readBool());
540 113788 : } else if ((tag == "slurEndWidth"
541 113705 : || tag == "slurMidWidth"
542 113621 : || tag == "slurDottedWidth"
543 113542 : || tag == "slurMinDistance")
544 227493 : && mscVersion < 430) {
545 : // Pre-4.3 scores used identical style values for slurs and ties.
546 : // When opening older scores, use the same values for both.
547 229 : double _val = e.readDouble();
548 229 : if (tag == "slurEndWidth") {
549 57 : set(Sid::tieEndWidth, Spatium(_val));
550 57 : set(Sid::slurEndWidth, Spatium(_val));
551 172 : } else if (tag == "slurMidWidth") {
552 58 : set(Sid::tieMidWidth, Spatium(_val));
553 58 : set(Sid::slurMidWidth, Spatium(_val));
554 114 : } else if (tag == "slurDottedWidth") {
555 57 : set(Sid::tieDottedWidth, Spatium(_val));
556 57 : set(Sid::slurDottedWidth, Spatium(_val));
557 57 : } else if (tag == "slurMinDistance") {
558 57 : set(Sid::tieMinDistance, Spatium(_val));
559 57 : set(Sid::slurMinDistance, Spatium(_val));
560 : }
561 113559 : } else if (tag == "measureNumberOffset" && mscVersion < 440) { // pre-4.4 typo
562 57 : set(Sid::measureNumberPosAbove, PointF(e.readPoint()));
563 113502 : } else if (tag == "measureNumberPosAbove" && mscVersion < 440) { // pre-4.4 typo
564 48 : set(Sid::mmRestRangePosAbove, PointF(e.readPoint()));
565 113454 : } else if (tag == "ottavaTextAlign") {
566 : // Pre-x.x (?) scores used identical style values for Above and Below
567 : // apparently the old default was "VCENTER",
568 : // so better ignore and take the new defaults
569 39 : e.skipCurrentElement(); // obsolete
570 113415 : } else if (tag == "tremoloStrokeStyle") { // pre-4.4 typo
571 57 : set(Sid::tremoloStyle, e.readInt());
572 113358 : } else if (tag == "systemFontFace") { // pre-4.4 typo
573 58 : set(Sid::systemTextFontFace, e.readText());
574 113300 : } else if (tag == "systemFontSize") { // pre-4.4 typo
575 57 : set(Sid::systemTextFontSize, e.readDouble());
576 113243 : } else if (tag == "systemFontSpatiumDependent") { // pre-4.4 typo
577 57 : set(Sid::systemTextFontSpatiumDependent, bool(e.readInt()));
578 113186 : } else if (tag == "systemFontStyle") { // pre-4.4 typo
579 57 : set(Sid::systemTextFontStyle, e.readInt());
580 113129 : } else if (tag == "systemAlign") { // pre-4.4 typo
581 48 : set(Sid::systemTextAlign, TConv::fromXml(e.readText(), Align()));
582 113081 : } else if (tag == "systemOffsetType") { // pre-4.4 typo
583 114 : set(Sid::systemTextOffsetType, e.readInt());
584 112967 : } else if (tag == "systemPlacement") { // pre-4.4 typo
585 57 : set(Sid::systemTextPlacement, PlacementV(e.readText().toInt()));
586 112910 : } else if (tag == "systemPosAbove") { // pre-4.4 typo
587 57 : set(Sid::systemTextPosAbove, PointF(e.readPoint()));
588 112853 : } else if (tag == "systemPosBelow") { // pre-4.4 typo
589 57 : set(Sid::systemTextPosBelow, PointF(e.readPoint()));
590 112796 : } else if (tag == "systemMinDistance") { // pre-4.4 typo
591 57 : set(Sid::systemTextMinDistance, Spatium(e.readDouble()));
592 112739 : } else if (tag == "systemFrameType") { // pre-4.4 typo
593 57 : set(Sid::systemTextFrameType, e.readInt());
594 112682 : } else if (tag == "systemFramePadding") { // pre-4.4 typo
595 59 : set(Sid::systemTextFramePadding, e.readDouble());
596 112623 : } else if (tag == "systemFrameWidth") { // pre-4.4 typo
597 59 : set(Sid::systemTextFrameWidth, e.readDouble());
598 112564 : } else if (tag == "systemFrameRound") { // pre-4.4 typo
599 59 : set(Sid::systemTextFrameRound, e.readDouble());
600 112505 : } else if (tag == "systemFrameFgColor") { // pre-4.4 typo
601 57 : set(Sid::systemTextFrameFgColor, e.readColor());
602 112448 : } else if (tag == "systemFrameBgColor") { // pre-4.4 typo
603 57 : set(Sid::systemTextFrameBgColor, e.readColor());
604 112391 : } else if (tag == "staffFontFace") { // pre-4.4 typo
605 58 : set(Sid::staffTextFontFace, e.readText());
606 112333 : } else if (tag == "staffFontSize") { // pre-4.4 typo
607 57 : set(Sid::staffTextFontSize, e.readDouble());
608 112276 : } else if (tag == "staffFontSpatiumDependent") { // pre-4.4 typo
609 57 : set(Sid::staffTextFontSpatiumDependent, e.readBool());
610 112219 : } else if (tag == "staffFontStyle") { // pre-4.4 typo
611 57 : set(Sid::staffTextFontStyle, e.readInt());
612 112162 : } else if (tag == "staffAlign") { // pre-4.4 typo
613 50 : set(Sid::staffTextAlign, TConv::fromXml(e.readText(), Align()));
614 112112 : } else if (tag == "staffOffsetType") { // pre-4.4 typo
615 0 : set(Sid::staffTextOffsetType, e.readInt());
616 112112 : } else if (tag == "staffPlacement") { // pre-4.4 typo
617 57 : set(Sid::staffTextPlacement, PlacementV(e.readText().toInt()));
618 112055 : } else if (tag == "staffTextPosAbove" // pre-4.4 typo, certainly before 3.6, even before 3.5
619 112055 : && mscVersion <= 410) { // so we might test for < 302, however m_version seems set to 410 here?!?
620 0 : double staffTextPosAboveY = e.readDouble();
621 0 : set(Sid::staffTextPosAbove, PointF(0.0, staffTextPosAboveY));
622 112055 : } else if (tag == "staffPosAbove") { // pre-4.4 typo
623 57 : set(Sid::staffTextPosAbove, e.readPoint());
624 111998 : } else if (tag == "staffPosBelow") { // pre-4.4 typo
625 57 : set(Sid::staffTextPosBelow, e.readPoint());
626 111941 : } else if (tag == "staffTextMinDistance" // pre-4.4 typo, certainly before 3.6, even before 3.5
627 111941 : && mscVersion <= 410) { // so we might test for < 302, however m_version seems set to 410 here?!?
628 0 : set(Sid::staffTextMinDistance, Spatium(e.readDouble()));
629 111941 : } else if (tag == "staffMinDistance") { // pre-4.4 typo
630 57 : set(Sid::staffTextMinDistance, Spatium(e.readDouble()));
631 111884 : } else if (tag == "staffFrameType") { // pre-4.4 typo
632 57 : set(Sid::staffTextFrameType, e.readInt());
633 111827 : } else if (tag == "staffFramePadding") { // pre-4.4 typo
634 59 : set(Sid::staffTextFramePadding, e.readDouble());
635 111768 : } else if (tag == "staffFrameWidth") { // pre-4.4 typo
636 59 : set(Sid::staffTextFrameWidth, e.readDouble());
637 111709 : } else if (tag == "staffFrameRound") { // pre-4.4 typo
638 59 : set(Sid::staffTextFrameRound, e.readDouble());
639 111650 : } else if (tag == "staffFrameFgColor") { // pre-4.4 typo
640 57 : set(Sid::staffTextFrameFgColor, e.readColor());
641 111593 : } else if (tag == "staffFrameBgColor") { // pre-4.4 typo
642 57 : set(Sid::staffTextFrameBgColor, e.readColor());
643 111536 : } else if (tag == "dymanicsShowTabCommon") { // pre-4.4 typo in gp-style.mss
644 0 : set(Sid::dynamicsShowTabCommon, bool(e.readInt()));
645 111536 : } else if (tag == "tupletOufOfStaff") {
646 63 : set(Sid::tupletOutOfStaff, bool(e.readInt()));
647 111473 : } else if (tag == "pedalBeginTextOffset"
648 111425 : || tag == "letRingBeginTextOffset"
649 111377 : || tag == "palmMuteBeginTextOffset"
650 111329 : || tag == "defaultFontSpatiumDependent"
651 222898 : || tag == "usePre_3_6_defaults") {
652 225 : e.skipCurrentElement(); // obsolete
653 111248 : } else if (tag == "articulationAnchorDefault" && mscVersion < 410) {
654 52 : set(Sid::articulationAnchorDefault, (int)compat::CompatUtils::translateToNewArticulationAnchor(e.readInt()));
655 111196 : } else if (tag == "articulationAnchorLuteFingering" && mscVersion < 410) {
656 52 : set(Sid::articulationAnchorLuteFingering, (int)compat::CompatUtils::translateToNewArticulationAnchor(e.readInt()));
657 111144 : } else if (tag == "articulationAnchorOther" && mscVersion < 410) {
658 52 : set(Sid::articulationAnchorOther, (int)compat::CompatUtils::translateToNewArticulationAnchor(e.readInt()));
659 111092 : } else if (tag == "lineEndToSystemEndDistance") { // renamed in 4.5
660 0 : set(Sid::lineEndToBarlineDistance, Spatium(e.readDouble()));
661 111092 : } else if (tag == "useStandardNoteNames") { // These settings were collapsed into one enum in 4.6
662 76 : if (e.readBool()) {
663 72 : set(Sid::chordSymbolSpelling, NoteSpellingType::STANDARD);
664 : }
665 111016 : } else if (tag == "useGermanNoteNames") {
666 73 : if (e.readBool()) {
667 0 : set(Sid::chordSymbolSpelling, NoteSpellingType::GERMAN);
668 : }
669 110943 : } else if (tag == "useFullGermanNoteNames") {
670 73 : if (e.readBool()) {
671 0 : set(Sid::chordSymbolSpelling, NoteSpellingType::GERMAN_PURE);
672 : }
673 110870 : } else if (tag == "useSolfeggioNoteNames") {
674 73 : if (e.readBool()) {
675 0 : set(Sid::chordSymbolSpelling, NoteSpellingType::SOLFEGGIO);
676 : }
677 110797 : } else if (tag == "useFrenchNoteNames") {
678 73 : if (e.readBool()) {
679 0 : set(Sid::chordSymbolSpelling, NoteSpellingType::FRENCH);
680 : }
681 110724 : } else if (tag == "chordModifierAdjust" && mscVersion < 460) {
682 71 : set(Sid::chordModifierAdjust, compat::CompatUtils::convertChordExtModUnits(e.readDouble()));
683 110653 : } else if (tag == "chordExtensionAdjust" && mscVersion < 460) {
684 71 : set(Sid::chordExtensionAdjust, compat::CompatUtils::convertChordExtModUnits(e.readDouble()));
685 110582 : } else if (tag == "chordDescriptionFile" && mscVersion < 460) {
686 72 : AsciiStringView val = e.readAsciiText();
687 72 : if (val == "chords_std.xml") {
688 60 : set(Sid::chordDescriptionFile, String(u"chords_legacy.xml"));
689 : } else {
690 12 : set(Sid::chordDescriptionFile, String::fromAscii(val.ascii()));
691 : }
692 110510 : } else if (tag == "chordStyle" && mscVersion < 460) {
693 72 : AsciiStringView val = e.readAsciiText();
694 72 : if (val == "std") {
695 60 : set(Sid::chordStyle, ChordStylePreset::LEGACY);
696 : } else {
697 12 : set(Sid::chordStyle, TConv::fromXml(val, ChordStylePreset::STANDARD));
698 : }
699 110438 : } else if (tag == "fretFrets" && mscVersion < 460) {
700 71 : e.skipCurrentElement();
701 110367 : } else if (tag == "measureNumberHPlacement" && mscVersion < 460) {
702 : // Before 460 PlacementH was used instead of AlignH, and was written as integer.
703 : // We can't directly map the integer to AlignH because it's enumerated differently.
704 71 : PlacementH hPlacement = PlacementH(e.readInt());
705 71 : AlignH hAlign = hPlacement == PlacementH::LEFT ? AlignH::LEFT
706 0 : : hPlacement == PlacementH::CENTER ? AlignH::HCENTER : AlignH::RIGHT;
707 71 : set(Sid::measureNumberHPlacement, hAlign);
708 :
709 71 : if (value(Sid::measureNumberHPlacement).value<AlignH>() != AlignH::LEFT) {
710 : // In this case it was assumed to be centered on the measure
711 0 : set(Sid::measureNumberAlignToBarline, false);
712 : }
713 110296 : } else if (tag == "mmRestRangeHPlacement" && mscVersion < 460) {
714 : // Before 460 PlacementH was used instead of AlignH, and was written as integer.
715 : // We can't directly map the integer to AlignH because it's enumerated differently.
716 62 : PlacementH hPlacement = PlacementH(e.readInt());
717 124 : AlignH hAlign = hPlacement == PlacementH::LEFT ? AlignH::LEFT
718 62 : : hPlacement == PlacementH::CENTER ? AlignH::HCENTER : AlignH::RIGHT;
719 62 : set(Sid::mmRestRangeHPlacement, hAlign);
720 110234 : } else if (tag == "measureNumberAllStaves" || tag == "measureNumberAllStaffs" /*old typo*/) {
721 73 : bool allStaves = e.readBool();
722 73 : set(Sid::measureNumberPlacementMode, allStaves ? MeasureNumberPlacement::ON_ALL_STAVES : MeasureNumberPlacement::ABOVE_SYSTEM);
723 110161 : } else if (String sTag = String::fromAscii(tag.ascii()); mscVersion < 470 && sTag.contains(u"FrameRound")) {
724 4360 : auto i = std::find_if(StyleDef::styleValues.begin(), StyleDef::styleValues.end(), [&](const StyleDef::StyleValue& s) {
725 4908301 : return s.xmlName == tag;
726 : });
727 4360 : if (i != StyleDef::styleValues.end()) {
728 4360 : const StyleDef::StyleValue& s = *i;
729 4360 : set(s.sid, compat::CompatUtils::convertPre470FrameRadius(e.readDouble()));
730 : }
731 105801 : } else if (!readProperties(e)) {
732 143 : e.unknown();
733 110161 : }
734 : }
735 :
736 923 : applyCompatStyleVals(mscVersion);
737 :
738 923 : if (readChordListHook) {
739 844 : readChordListHook->validate();
740 : }
741 923 : }
742 :
743 3 : bool MStyle::write(IODevice* device)
744 : {
745 3 : XmlWriter xml(device);
746 3 : xml.startDocument();
747 9 : xml.startElement("museScore", { { "version", Constants::MSC_VERSION_STR } });
748 3 : save(xml, false);
749 3 : xml.endElement();
750 3 : return true;
751 6 : }
752 :
753 1106 : void MStyle::save(XmlWriter& xml, bool optimize)
754 : {
755 1106 : xml.startElement("Style");
756 :
757 2300480 : for (const StyleDef::StyleValue& st : StyleDef::styleValues) {
758 2299374 : Sid idx = st.sid;
759 2299374 : if (idx == Sid::spatium) { // special handling for spatium
760 1106 : continue;
761 : }
762 2298268 : if (optimize && isDefault(idx)) {
763 2283394 : continue;
764 : }
765 14874 : P_TYPE type = st.valueType();
766 14874 : if (P_TYPE::SPATIUM == type) {
767 2588 : xml.tag(st.xmlName, value(idx).value<Spatium>().val());
768 12286 : } else if (P_TYPE::DIRECTION_V == type) {
769 6 : xml.tag(st.xmlName, int(value(idx).value<DirectionV>()));
770 12280 : } else if (P_TYPE::ORIENTATION == type) {
771 3 : xml.tag(st.xmlName, TConv::toXml(value(idx).value<Orientation>()));
772 12277 : } else if (P_TYPE::SHARED_LABEL_ORIENTATION == type) {
773 3 : xml.tag(st.xmlName, TConv::toXml(value(idx).value<SharedLabelOrientation>()));
774 12274 : } else if (P_TYPE::ALIGN == type) {
775 304 : Align a = value(idx).value<Align>();
776 : // Don't write if it's the default value
777 304 : if (optimize && a == st.defaultValue.value<Align>()) {
778 21 : continue;
779 : }
780 283 : xml.tag(st.xmlName, TConv::toXml(a));
781 11970 : } else if (P_TYPE::ALIGN_H == type) {
782 265 : xml.tag(st.xmlName, TConv::toXml(value(idx).value<AlignH>()));
783 11705 : } else if (P_TYPE::LINE_TYPE == type) {
784 39 : xml.tagProperty(st.xmlName, value(idx));
785 11666 : } else if (P_TYPE::TIE_PLACEMENT == type) {
786 8 : xml.tag(st.xmlName, TConv::toXml(value(idx).value<TiePlacement>()));
787 11658 : } else if (P_TYPE::TIE_DOTS_PLACEMENT == type) {
788 3 : xml.tag(st.xmlName, TConv::toXml(value(idx).value<TieDotsPlacement>()));
789 11655 : } else if (P_TYPE::TIMESIG_PLACEMENT == type) {
790 3 : xml.tag(st.xmlName, TConv::toXml(value(idx).value<TimeSigPlacement>()));
791 11652 : } else if (P_TYPE::TIMESIG_STYLE == type) {
792 9 : xml.tag(st.xmlName, TConv::toXml(value(idx).value<TimeSigStyle>()));
793 11643 : } else if (P_TYPE::TIMESIG_MARGIN == type) {
794 6 : xml.tag(st.xmlName, TConv::toXml(value(idx).value<TimeSigVSMargin>()));
795 11637 : } else if (P_TYPE::CHORD_PRESET_TYPE == type) {
796 9 : xml.tag(st.xmlName, TConv::toXml(value(idx).value<ChordStylePreset>()));
797 11628 : } else if (P_TYPE::NOTE_SPELLING_TYPE == type) {
798 3 : xml.tag(st.xmlName, TConv::toXml(value(idx).value<NoteSpellingType>()));
799 11625 : } else if (P_TYPE::LH_TAPPING_SYMBOL == type) {
800 6 : xml.tag(st.xmlName, TConv::toXml(value(idx).value<LHTappingSymbol>()));
801 11619 : } else if (P_TYPE::RH_TAPPING_SYMBOL == type) {
802 6 : xml.tag(st.xmlName, TConv::toXml(value(idx).value<RHTappingSymbol>()));
803 11613 : } else if (P_TYPE::TEXT_STYLE == type) {
804 6 : xml.tag(st.xmlName, TConv::toXml(value(idx).value<TextStyleType>()));
805 11607 : } else if (P_TYPE::PARENTHESES_MODE == type) {
806 0 : xml.tag(st.xmlName, TConv::toXml(value(idx).value<ParenthesesMode>()));
807 11607 : } else if (P_TYPE::PLAY_COUNT_PRESET == type) {
808 3 : xml.tag(st.xmlName, TConv::toXml(value(idx).value<RepeatPlayCountPreset>()));
809 11604 : } else if (P_TYPE::MEASURE_NUMBER_PLACEMENT == type) {
810 3 : xml.tag(st.xmlName, TConv::toXml(value(idx).value<MeasureNumberPlacement>()));
811 11601 : } else if (P_TYPE::INSTRUMENT_NAMES_ALIGN == type) {
812 6 : xml.tag(st.xmlName, TConv::toXml(value(idx).value<InstrumentNamesAlign>()));
813 11595 : } else if (P_TYPE::INSTRUMENT_NAMES_FORMAT == type) {
814 6 : xml.tag(st.xmlName, TConv::toXml(value(idx).value<InstrumentNamesFormat>()));
815 11589 : } else if (P_TYPE::AUTO_ON_OFF == type) {
816 3 : xml.tag(st.xmlName, TConv::toXml(value(idx).value<AutoOnOff>()));
817 : } else {
818 11586 : PropertyValue val = value(idx);
819 : //! NOTE for compatibility
820 11586 : if (val.isEnum()) {
821 151 : val = val.value<int>();
822 : }
823 11586 : xml.tagProperty(st.xmlName, val);
824 11586 : }
825 : }
826 :
827 1106 : xml.tag("spatium", value(Sid::spatium).toReal() / DPMM);
828 1106 : xml.endElement();
829 1106 : }
830 :
831 : // ====================================================
832 : // Static
833 : // ====================================================
834 :
835 19414839 : P_TYPE MStyle::valueType(const Sid i)
836 : {
837 19414839 : return StyleDef::styleValues[size_t(i)].valueType();
838 : }
839 :
840 0 : const char* MStyle::valueName(const Sid i)
841 : {
842 0 : if (i == Sid::NOSTYLE) {
843 : static const char* no_style = "no style";
844 0 : return no_style;
845 : }
846 0 : return StyleDef::styleValues[size_t(i)].xmlName.ascii();
847 : }
848 :
849 8 : Sid MStyle::styleIdx(const String& name)
850 : {
851 8 : muse::ByteArray ba = name.toAscii();
852 8496 : for (const StyleDef::StyleValue& st : StyleDef::styleValues) {
853 8496 : if (st.xmlName == ba.constChar()) {
854 8 : return st.sid;
855 : }
856 : }
857 0 : return Sid::NOSTYLE;
858 8 : }
|