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) 2026 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 <algorithm>
24 :
25 : #include "export/mnxexporter.h"
26 : #include "notationmnxwriter.h"
27 :
28 : #include "engraving/dom/score.h"
29 :
30 : #include "notation/inotation.h"
31 : #include "notation/inotationelements.h" // IWYU pragma: keep
32 :
33 : #include "log.h"
34 :
35 : using namespace mu::iex::mnxio;
36 : using namespace mu::project;
37 : using namespace muse;
38 : using namespace muse::io;
39 :
40 0 : std::vector<INotationWriter::UnitType> NotationMnxWriter::supportedUnitTypes() const
41 : {
42 0 : return { UnitType::PER_PART };
43 : }
44 :
45 0 : bool NotationMnxWriter::supportsUnitType(UnitType unitType) const
46 : {
47 0 : std::vector<UnitType> unitTypes = supportedUnitTypes();
48 0 : return std::find(unitTypes.cbegin(), unitTypes.cend(), unitType) != unitTypes.cend();
49 0 : }
50 :
51 0 : Ret NotationMnxWriter::write(notation::INotationPtr notation, io::IODevice& destinationDevice, const Options&)
52 : {
53 0 : IF_ASSERT_FAILED(notation) {
54 0 : return make_ret(Ret::Code::UnknownError);
55 : }
56 0 : mu::engraving::Score* score = notation->elements()->msScore();
57 0 : IF_ASSERT_FAILED(score) {
58 0 : return make_ret(Ret::Code::UnknownError);
59 : }
60 :
61 0 : const bool exportBeams = mnxConfiguration()->mnxExportBeams();
62 0 : const bool exportRestPositions = mnxConfiguration()->mnxExportRestPositions();
63 0 : MnxExporter exporter(score, exportBeams, exportRestPositions);
64 :
65 : try {
66 0 : Ret exportResult = exporter.exportMnx();
67 0 : if (!exportResult) {
68 0 : return exportResult;
69 : }
70 0 : const int indentSpaces = mnxConfiguration()->mnxIndentSpaces();
71 : std::string json = indentSpaces >= 0
72 0 : ? exporter.mnxDocument().root()->dump(indentSpaces)
73 0 : : exporter.mnxDocument().root()->dump();
74 0 : ByteArray data = ByteArray::fromRawData(json.data(), json.size());
75 0 : destinationDevice.write(data);
76 0 : return muse::make_ok();
77 0 : } catch (const std::exception& ex) {
78 0 : LOGE() << String::fromStdString(ex.what());
79 0 : return make_ret(Ret::Code::InternalError);
80 0 : }
81 0 : }
82 :
83 0 : Ret NotationMnxWriter::writeList(const notation::INotationPtrList&, io::IODevice&, const Options&)
84 : {
85 0 : NOT_SUPPORTED;
86 0 : return Ret(Ret::Code::NotSupported);
87 : }
|