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 "musicxmlconfiguration.h"
23 :
24 : #include "settings.h"
25 : #include "translation.h"
26 :
27 : using namespace mu;
28 : using namespace muse;
29 : using namespace mu::iex::musicxml;
30 :
31 : static const std::string module_name("iex_musicxml");
32 :
33 : static const Settings::Key MUSICXML_IMPORT_BREAKS_KEY(module_name, "import/musicXml/importBreaks");
34 : static const Settings::Key MUSICXML_IMPORT_LAYOUT_KEY(module_name, "import/musicXml/importLayout");
35 : static const Settings::Key MUSICXML_EXPORT_LAYOUT_KEY(module_name, "export/musicXml/exportLayout");
36 : static const Settings::Key MUSICXML_EXPORT_MU3_COMPAT_KEY(module_name, "export/musicXml/exportMu3Compat");
37 : static const Settings::Key MUSICXML_EXPORT_BREAKS_TYPE_KEY(module_name, "export/musicXml/exportBreaks");
38 : static const Settings::Key MUSICXML_EXPORT_INVISIBLE_ELEMENTS_KEY(module_name, "export/musicXml/exportInvisibleElements");
39 : static const Settings::Key MIGRATION_APPLY_EDWIN_FOR_XML(module_name, "import/compatibility/apply_edwin_for_xml");
40 : static const Settings::Key MIGRATION_NOT_ASK_AGAIN_KEY(module_name, "import/compatibility/do_not_ask_me_again");
41 : static const Settings::Key MUSICXML_IMPORT_INFER_TEXT_TYPE(module_name, "import/musicXml/importInferTextType");
42 :
43 1 : void MusicXmlConfiguration::init()
44 : {
45 1 : settings()->setDefaultValue(MUSICXML_IMPORT_BREAKS_KEY, Val(true));
46 1 : settings()->valueChanged(MUSICXML_IMPORT_BREAKS_KEY).onReceive(this, [this](const Val& val) {
47 0 : m_importBreaksChanged.send(val.toBool());
48 0 : });
49 :
50 1 : settings()->setDefaultValue(MUSICXML_IMPORT_LAYOUT_KEY, Val(true));
51 1 : settings()->valueChanged(MUSICXML_IMPORT_LAYOUT_KEY).onReceive(this, [this](const Val& val) {
52 0 : m_importLayoutChanged.send(val.toBool());
53 0 : });
54 :
55 1 : settings()->setDefaultValue(MUSICXML_EXPORT_LAYOUT_KEY, Val(true));
56 1 : settings()->setDefaultValue(MUSICXML_EXPORT_MU3_COMPAT_KEY, Val(false));
57 2 : settings()->setDescription(MUSICXML_EXPORT_MU3_COMPAT_KEY,
58 : //: Means that less information will be included in exported MusicXML files,
59 : //: to prevent errors when importing them into MuseScore 3
60 2 : muse::trc("iex_musicxml", "Limit MusicXML export for compatibility with MuseScore 3"));
61 1 : settings()->setCanBeManuallyEdited(MUSICXML_EXPORT_MU3_COMPAT_KEY, true);
62 1 : settings()->setDefaultValue(MUSICXML_EXPORT_BREAKS_TYPE_KEY, Val(MusicXmlExportBreaksType::All));
63 1 : settings()->setDefaultValue(MUSICXML_EXPORT_INVISIBLE_ELEMENTS_KEY, Val(false));
64 2 : settings()->setDescription(MUSICXML_EXPORT_INVISIBLE_ELEMENTS_KEY,
65 2 : muse::trc("iex_musicxml", "Export invisible elements to MusicXML"));
66 1 : settings()->setCanBeManuallyEdited(MUSICXML_EXPORT_INVISIBLE_ELEMENTS_KEY, true);
67 :
68 1 : settings()->setDefaultValue(MIGRATION_APPLY_EDWIN_FOR_XML, Val(false));
69 1 : settings()->valueChanged(MIGRATION_APPLY_EDWIN_FOR_XML).onReceive(this, [this](const Val& val) {
70 0 : m_needUseDefaultFontChanged.send(val.toBool());
71 0 : });
72 :
73 1 : settings()->setDefaultValue(MIGRATION_NOT_ASK_AGAIN_KEY, Val(false));
74 1 : settings()->valueChanged(MIGRATION_NOT_ASK_AGAIN_KEY).onReceive(this, [this](const Val& val) {
75 0 : m_needAskAboutApplyingNewStyleChanged.send(val.toBool());
76 0 : });
77 :
78 1 : settings()->setDefaultValue(MUSICXML_IMPORT_INFER_TEXT_TYPE, Val(false));
79 1 : settings()->valueChanged(MUSICXML_IMPORT_INFER_TEXT_TYPE).onReceive(this, [this](const Val& val) {
80 3 : m_inferTextTypeChanged.send(val.toBool());
81 3 : });
82 1 : }
83 :
84 90 : bool MusicXmlConfiguration::importBreaks() const
85 : {
86 90 : return settings()->value(MUSICXML_IMPORT_BREAKS_KEY).toBool();
87 : }
88 :
89 0 : void MusicXmlConfiguration::setImportBreaks(bool value)
90 : {
91 0 : settings()->setSharedValue(MUSICXML_IMPORT_BREAKS_KEY, Val(value));
92 0 : }
93 :
94 0 : async::Channel<bool> MusicXmlConfiguration::importBreaksChanged() const
95 : {
96 0 : return m_importBreaksChanged;
97 : }
98 :
99 477 : bool MusicXmlConfiguration::importLayout() const
100 : {
101 477 : return settings()->value(MUSICXML_IMPORT_LAYOUT_KEY).toBool();
102 : }
103 :
104 0 : void MusicXmlConfiguration::setImportLayout(bool value)
105 : {
106 0 : settings()->setSharedValue(MUSICXML_IMPORT_LAYOUT_KEY, Val(value));
107 0 : }
108 :
109 0 : async::Channel<bool> MusicXmlConfiguration::importLayoutChanged() const
110 : {
111 0 : return m_importLayoutChanged;
112 : }
113 :
114 13500 : bool MusicXmlConfiguration::exportLayout() const
115 : {
116 13500 : return settings()->value(MUSICXML_EXPORT_LAYOUT_KEY).toBool();
117 : }
118 :
119 0 : void MusicXmlConfiguration::setExportLayout(bool value)
120 : {
121 0 : settings()->setSharedValue(MUSICXML_EXPORT_LAYOUT_KEY, Val(value));
122 0 : }
123 :
124 186 : bool MusicXmlConfiguration::exportMu3Compat() const
125 : {
126 186 : return settings()->value(MUSICXML_EXPORT_MU3_COMPAT_KEY).toBool();
127 : }
128 :
129 0 : void MusicXmlConfiguration::setExportMu3Compat(bool value)
130 : {
131 0 : settings()->setSharedValue(MUSICXML_EXPORT_MU3_COMPAT_KEY, Val(value));
132 0 : }
133 :
134 3132 : MusicXmlConfiguration::MusicXmlExportBreaksType MusicXmlConfiguration::exportBreaksType() const
135 : {
136 3132 : return settings()->value(MUSICXML_EXPORT_BREAKS_TYPE_KEY).toEnum<MusicXmlExportBreaksType>();
137 : }
138 :
139 0 : void MusicXmlConfiguration::setExportBreaksType(MusicXmlExportBreaksType breaksType)
140 : {
141 0 : settings()->setSharedValue(MUSICXML_EXPORT_BREAKS_TYPE_KEY, Val(breaksType));
142 0 : }
143 :
144 708 : bool MusicXmlConfiguration::exportInvisibleElements() const
145 : {
146 708 : return settings()->value(MUSICXML_EXPORT_INVISIBLE_ELEMENTS_KEY).toBool();
147 : }
148 :
149 0 : void MusicXmlConfiguration::setExportInvisibleElements(bool value)
150 : {
151 0 : settings()->setSharedValue(MUSICXML_EXPORT_INVISIBLE_ELEMENTS_KEY, Val(value));
152 0 : }
153 :
154 5599 : bool MusicXmlConfiguration::needUseDefaultFont() const
155 : {
156 5599 : if (m_needUseDefaultFontOverride.has_value()) {
157 0 : return m_needUseDefaultFontOverride.value();
158 : }
159 :
160 5599 : return settings()->value(MIGRATION_APPLY_EDWIN_FOR_XML).toBool();
161 : }
162 :
163 0 : void MusicXmlConfiguration::setNeedUseDefaultFont(bool value)
164 : {
165 0 : settings()->setSharedValue(MIGRATION_APPLY_EDWIN_FOR_XML, Val(value));
166 0 : }
167 :
168 0 : async::Channel<bool> MusicXmlConfiguration::needUseDefaultFontChanged() const
169 : {
170 0 : return m_needUseDefaultFontChanged;
171 : }
172 :
173 0 : void MusicXmlConfiguration::setNeedUseDefaultFontOverride(std::optional<bool> value)
174 : {
175 0 : m_needUseDefaultFontOverride = value;
176 0 : }
177 :
178 0 : bool MusicXmlConfiguration::needAskAboutApplyingNewStyle() const
179 : {
180 0 : return !settings()->value(MIGRATION_NOT_ASK_AGAIN_KEY).toBool();
181 : }
182 :
183 0 : void MusicXmlConfiguration::setNeedAskAboutApplyingNewStyle(bool value)
184 : {
185 0 : settings()->setSharedValue(MIGRATION_NOT_ASK_AGAIN_KEY, Val(!value));
186 0 : }
187 :
188 0 : async::Channel<bool> MusicXmlConfiguration::needAskAboutApplyingNewStyleChanged() const
189 : {
190 0 : return m_needAskAboutApplyingNewStyleChanged;
191 : }
192 :
193 10334 : bool MusicXmlConfiguration::inferTextType() const
194 : {
195 10334 : if (m_inferTextTypeOverride.has_value()) {
196 0 : return m_inferTextTypeOverride.value();
197 : }
198 :
199 10334 : return settings()->value(MUSICXML_IMPORT_INFER_TEXT_TYPE).toBool();
200 : }
201 :
202 0 : void MusicXmlConfiguration::setInferTextType(bool value)
203 : {
204 0 : settings()->setSharedValue(MUSICXML_IMPORT_INFER_TEXT_TYPE, Val(value));
205 0 : }
206 :
207 0 : async::Channel<bool> MusicXmlConfiguration::inferTextTypeChanged() const
208 : {
209 0 : return m_inferTextTypeChanged;
210 : }
211 :
212 0 : void MusicXmlConfiguration::setInferTextTypeOverride(std::optional<bool> value)
213 : {
214 0 : m_inferTextTypeOverride = value;
215 0 : }
|