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 488 : static int readStyleDefaultsVersion(MasterScore* score, const ByteArray& scoreData, const String& completeBaseName)
43 : {
44 488 : XmlReader e(scoreData);
45 488 : e.setDocName(completeBaseName);
46 :
47 469815 : while (!e.atEnd()) {
48 469327 : e.readNext();
49 469327 : if (e.name() == "defaultsVersion") {
50 0 : return e.readInt();
51 : }
52 : }
53 :
54 488 : return ReadStyleHook::styleDefaultByMscVersion(score->mscVersion());
55 488 : }
56 :
57 1103 : ReadStyleHook::ReadStyleHook(Score* score, const ByteArray& scoreData, const String& completeBaseName)
58 1103 : : m_score(score), m_scoreData(scoreData), m_completeBaseName(completeBaseName)
59 : {
60 1103 : }
61 :
62 488 : int ReadStyleHook::styleDefaultByMscVersion(const int mscVer)
63 : {
64 488 : constexpr int LEGACY_MSC_VERSION_V400 = 400;
65 488 : constexpr int LEGACY_MSC_VERSION_V302 = 302;
66 488 : constexpr int LEGACY_MSC_VERSION_V3 = 301;
67 488 : constexpr int LEGACY_MSC_VERSION_V2 = 206;
68 488 : constexpr int LEGACY_MSC_VERSION_V1 = 114;
69 :
70 488 : if (mscVer > LEGACY_MSC_VERSION_V3 && mscVer < LEGACY_MSC_VERSION_V400) {
71 7 : return LEGACY_MSC_VERSION_V302;
72 : }
73 481 : if (mscVer > LEGACY_MSC_VERSION_V2 && mscVer <= LEGACY_MSC_VERSION_V3) {
74 427 : 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 488 : void ReadStyleHook::setupDefaultStyle()
89 : {
90 488 : IF_ASSERT_FAILED(m_score) {
91 0 : return;
92 : }
93 :
94 488 : int defaultsVersion = -1;
95 488 : if (m_score->isMaster()) {
96 488 : defaultsVersion = readStyleDefaultsVersion(m_score->masterScore(), m_scoreData, m_completeBaseName);
97 : } else {
98 0 : defaultsVersion = m_score->masterScore()->style().defaultStyleVersion();
99 : }
100 :
101 488 : m_score->setStyle(DefaultStyle::resolveStyleDefaults(defaultsVersion));
102 488 : m_score->style().setDefaultStyleVersion(defaultsVersion);
103 : }
104 :
105 138 : void ReadStyleHook::setupDefaultStyle(Score* score)
106 : {
107 138 : IF_ASSERT_FAILED(!score->isMaster()) {
108 0 : return;
109 : }
110 :
111 138 : int defaultsVersion = score->masterScore()->style().defaultStyleVersion();
112 138 : score->setStyle(DefaultStyle::resolveStyleDefaults(defaultsVersion));
113 138 : score->style().setDefaultStyleVersion(defaultsVersion);
114 : }
115 :
116 0 : void ReadStyleHook::readStyleTag(XmlReader& e)
117 : {
118 0 : readStyleTag(m_score, e);
119 0 : }
120 :
121 844 : void ReadStyleHook::readStyleTag(Score* score, XmlReader& e)
122 : {
123 844 : ReadChordListHook clhook(score);
124 844 : score->style().read(e, &clhook, score->mscVersion());
125 844 : }
126 :
127 210 : bool ReadStyleHook::readStyleProperties(MStyle* style, XmlReader& e)
128 : {
129 210 : return style->readProperties(e);
130 : }
|