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 "meiwriter.h"
24 :
25 : #include "meiexporter.h"
26 :
27 : #include "io/file.h"
28 : #include "log.h"
29 :
30 : #include "engraving/engravingerrors.h"
31 : #include "engraving/dom/score.h"
32 :
33 : #include "notation/inotation.h"
34 : #include "notation/inotationelements.h" // IWYU pragma: keep
35 :
36 : using namespace mu;
37 : using namespace muse;
38 : using namespace mu::iex::mei;
39 : using namespace mu::project;
40 :
41 0 : std::vector<INotationWriter::UnitType> MeiWriter::supportedUnitTypes() const
42 : {
43 0 : return { UnitType::PER_PART };
44 : }
45 :
46 0 : bool MeiWriter::supportsUnitType(UnitType unitType) const
47 : {
48 0 : std::vector<UnitType> unitTypes = supportedUnitTypes();
49 0 : return std::find(unitTypes.cbegin(), unitTypes.cend(), unitType) != unitTypes.cend();
50 0 : }
51 :
52 0 : Ret MeiWriter::write(notation::INotationPtr notation, io::IODevice& destinationDevice, const Options&)
53 : {
54 0 : IF_ASSERT_FAILED(notation) {
55 0 : return make_ret(Ret::Code::UnknownError);
56 : }
57 :
58 0 : mu::engraving::Score* score = notation->elements()->msScore();
59 0 : IF_ASSERT_FAILED(score) {
60 0 : return make_ret(Ret::Code::UnknownError);
61 : }
62 :
63 0 : MeiExporter exporter(score);
64 0 : std::string meiData;
65 0 : if (exporter.write(meiData)) {
66 0 : ByteArray data = ByteArray::fromRawData(meiData.c_str(), meiData.size());
67 0 : destinationDevice.write(data);
68 0 : return muse::make_ok();
69 0 : } else {
70 0 : return make_ret(Ret::Code::UnknownError);
71 : }
72 0 : }
73 :
74 64 : mu::engraving::Err MeiWriter::writeScore(mu::engraving::Score* score, const muse::io::path_t& path)
75 : {
76 64 : MeiExporter exporter(score);
77 : // Force no layout option in this case
78 64 : exporter.configuration()->setMeiExportLayout(false);
79 64 : std::string meiData;
80 64 : if (exporter.write(meiData) && io::File::writeFile(path, ByteArray(meiData.c_str(), meiData.size()))) {
81 64 : return engraving::Err::NoError;
82 : } else {
83 0 : return engraving::Err::UnknownError;
84 : }
85 64 : }
86 :
87 0 : Ret MeiWriter::writeList(const notation::INotationPtrList&, io::IODevice&, const Options&)
88 : {
89 0 : NOT_SUPPORTED;
90 0 : return Ret(Ret::Code::NotSupported);
91 : }
|