Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-Studio-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2021 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 : #include "readstyle.h"
23 :
24 : #include "types/constants.h"
25 :
26 : #include "style/defaultstyle.h"
27 : #include "style/style.h"
28 :
29 : #include "rw/xmlreader.h"
30 :
31 : #include "dom/masterscore.h"
32 :
33 : #include "readchordlisthook.h"
34 :
35 : #include "log.h"
36 :
37 : using namespace mu;
38 : using namespace muse;
39 : using namespace mu::engraving::compat;
40 : using namespace mu::engraving;
41 :
42 473 : static int readStyleDefaultsVersion(MasterScore* score, const ByteArray& scoreData, const String& completeBaseName)
43 : {
44 473 : XmlReader e(scoreData);
45 473 : e.setDocName(completeBaseName);
46 :
47 461739 : while (!e.atEnd()) {
48 461266 : e.readNext();
49 461266 : if (e.name() == "defaultsVersion") {
50 0 : return e.readInt();
51 : }
52 : }
53 :
54 473 : return ReadStyleHook::styleDefaultByMscVersion(score->mscVersion());
55 473 : }
56 :
57 1008 : ReadStyleHook::ReadStyleHook(Score* score, const ByteArray& scoreData, const String& completeBaseName)
58 1008 : : m_score(score), m_scoreData(scoreData), m_completeBaseName(completeBaseName)
59 : {
60 1008 : }
61 :
62 473 : int ReadStyleHook::styleDefaultByMscVersion(const int mscVer)
63 : {
64 473 : constexpr int LEGACY_MSC_VERSION_V400 = 400;
65 473 : constexpr int LEGACY_MSC_VERSION_V302 = 302;
66 473 : constexpr int LEGACY_MSC_VERSION_V3 = 301;
67 473 : constexpr int LEGACY_MSC_VERSION_V2 = 206;
68 473 : constexpr int LEGACY_MSC_VERSION_V1 = 114;
69 :
70 473 : if (mscVer > LEGACY_MSC_VERSION_V3 && mscVer < LEGACY_MSC_VERSION_V400) {
71 7 : return LEGACY_MSC_VERSION_V302;
72 : }
73 466 : if (mscVer > LEGACY_MSC_VERSION_V2 && mscVer <= LEGACY_MSC_VERSION_V3) {
74 412 : return LEGACY_MSC_VERSION_V3;
75 : }
76 :
77 54 : if (mscVer > LEGACY_MSC_VERSION_V1 && mscVer <= LEGACY_MSC_VERSION_V2) {
78 28 : return LEGACY_MSC_VERSION_V2;
79 : }
80 :
81 26 : if (mscVer <= LEGACY_MSC_VERSION_V1) {
82 26 : return LEGACY_MSC_VERSION_V1;
83 : }
84 :
85 0 : return Constants::MSC_VERSION;
86 : }
87 :
88 473 : void ReadStyleHook::setupDefaultStyle()
89 : {
90 473 : IF_ASSERT_FAILED(m_score) {
91 0 : return;
92 : }
93 :
94 473 : int defaultsVersion = -1;
95 473 : if (m_score->isMaster()) {
96 473 : defaultsVersion = readStyleDefaultsVersion(m_score->masterScore(), m_scoreData, m_completeBaseName);
97 : } else {
98 0 : defaultsVersion = m_score->masterScore()->style().defaultStyleVersion();
99 : }
100 :
101 473 : m_score->setStyle(DefaultStyle::resolveStyleDefaults(defaultsVersion));
102 473 : m_score->style().setDefaultStyleVersion(defaultsVersion);
103 : }
104 :
105 108 : void ReadStyleHook::setupDefaultStyle(Score* score)
106 : {
107 108 : IF_ASSERT_FAILED(!score->isMaster()) {
108 0 : return;
109 : }
110 :
111 108 : int defaultsVersion = score->masterScore()->style().defaultStyleVersion();
112 108 : score->setStyle(DefaultStyle::resolveStyleDefaults(defaultsVersion));
113 108 : score->style().setDefaultStyleVersion(defaultsVersion);
114 : }
115 :
116 0 : void ReadStyleHook::readStyleTag(XmlReader& e)
117 : {
118 0 : readStyleTag(m_score, e);
119 0 : }
120 :
121 749 : void ReadStyleHook::readStyleTag(Score* score, XmlReader& e)
122 : {
123 749 : ReadChordListHook clhook(score);
124 749 : score->style().read(e, &clhook, score->mscVersion());
125 749 : }
126 :
127 210 : bool ReadStyleHook::readStyleProperties(MStyle* style, XmlReader& e)
128 : {
129 210 : return style->readProperties(e);
130 : }
|