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 "abstractimagewriter.h"
23 :
24 : #include "log.h"
25 :
26 : using namespace muse;
27 : using namespace mu::iex::imagesexport;
28 : using namespace mu::project;
29 : using namespace mu::notation;
30 :
31 0 : std::vector<INotationWriter::UnitType> AbstractImageWriter::supportedUnitTypes() const
32 : {
33 0 : return { UnitType::PER_PART };
34 : }
35 :
36 0 : bool AbstractImageWriter::supportsUnitType(UnitType unitType) const
37 : {
38 0 : std::vector<UnitType> unitTypes = supportedUnitTypes();
39 0 : return std::find(unitTypes.cbegin(), unitTypes.cend(), unitType) != unitTypes.cend();
40 0 : }
41 :
42 0 : Ret AbstractImageWriter::write(INotationPtr, io::IODevice&, const Options& options)
43 : {
44 0 : IF_ASSERT_FAILED(unitTypeFromOptions(options) != UnitType::MULTI_PART) {
45 0 : return Ret(Ret::Code::NotSupported);
46 : }
47 :
48 0 : if (supportsUnitType(muse::value(options, OptionKey::UNIT_TYPE, Val(UnitType::PER_PAGE)).toEnum<UnitType>())) {
49 0 : NOT_IMPLEMENTED;
50 0 : return Ret(Ret::Code::NotImplemented);
51 : }
52 :
53 0 : NOT_SUPPORTED;
54 0 : return Ret(Ret::Code::NotSupported);
55 : }
56 :
57 0 : Ret AbstractImageWriter::writeList(const INotationPtrList&, io::IODevice&, const Options& options)
58 : {
59 0 : IF_ASSERT_FAILED(unitTypeFromOptions(options) == UnitType::MULTI_PART) {
60 0 : return Ret(Ret::Code::NotSupported);
61 : }
62 :
63 0 : if (supportsUnitType(muse::value(options, OptionKey::UNIT_TYPE, Val(UnitType::PER_PAGE)).toEnum<UnitType>())) {
64 0 : NOT_IMPLEMENTED;
65 0 : return Ret(Ret::Code::NotImplemented);
66 : }
67 :
68 0 : NOT_SUPPORTED;
69 0 : return Ret(Ret::Code::NotSupported);
70 : }
71 :
72 0 : INotationWriter::UnitType AbstractImageWriter::unitTypeFromOptions(const Options& options) const
73 : {
74 0 : std::vector<UnitType> supported = supportedUnitTypes();
75 0 : IF_ASSERT_FAILED(!supported.empty()) {
76 0 : return UnitType::PER_PART;
77 : }
78 :
79 0 : UnitType defaultUnitType = supported.front();
80 0 : UnitType unitType = muse::value(options, OptionKey::UNIT_TYPE, Val(defaultUnitType)).toEnum<UnitType>();
81 0 : if (!supportsUnitType(unitType)) {
82 0 : return defaultUnitType;
83 : }
84 :
85 0 : return unitType;
86 0 : }
|