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 : #ifndef MU_ENGRAVING_IWRITER_H
23 : #define MU_ENGRAVING_IWRITER_H
24 :
25 : #include <memory>
26 : #include <variant>
27 : #include <vector>
28 :
29 : #include "global/io/iodevice.h"
30 : #include "global/types/bytearray.h"
31 : #include "xmlwriter.h"
32 :
33 : namespace mu::engraving {
34 : class Score;
35 : class EngravingItem;
36 : class Segment;
37 : class SelectionFilter;
38 : struct SelectedSymbol;
39 : }
40 :
41 : namespace mu::engraving::write {
42 : class WriteContext;
43 : }
44 :
45 : namespace mu::engraving::rw {
46 : struct WriteInOutData;
47 :
48 : class IWriter
49 : {
50 : public:
51 1938 : virtual ~IWriter() = default;
52 :
53 : virtual bool writeScore(Score* score, muse::io::IODevice* device, WriteInOutData* out = nullptr) = 0;
54 :
55 : virtual muse::ByteArray writeStaffSelection(Score* score, const SelectionFilter& filter, staff_idx_t staffStart, staff_idx_t staffEnd,
56 : const Fraction& tickStart, const Fraction& tickEnd, Segment* startSegment,
57 : Segment* endSegment) = 0;
58 :
59 : virtual muse::ByteArray writeSymbolListSelection(track_idx_t fromTrack, track_idx_t toTrack,
60 : const std::vector<SelectedSymbol>& symbols) = 0;
61 :
62 : using Supported = std::variant<std::monostate
63 : >;
64 :
65 : template<typename T>
66 597 : static void check_supported_static(T item)
67 : {
68 : if constexpr (std::is_same<T, const EngravingItem*>::value || std::is_same<T, EngravingItem*>::value) {
69 : // supported
70 : } else {
71 : Supported check(item);
72 : (void)check;
73 : }
74 597 : }
75 :
76 : template<typename T>
77 597 : void writeItem(const T item, XmlWriter& xml)
78 : {
79 : #ifndef NDEBUG
80 597 : check_supported_static(item);
81 : #endif
82 597 : doWriteItem(static_cast<const EngravingItem*>(item), xml);
83 597 : }
84 :
85 : private:
86 : virtual void doWriteItem(const EngravingItem* item, XmlWriter& xml) = 0;
87 : virtual void writeSegments(XmlWriter& xml, write::WriteContext& ctx, track_idx_t st, track_idx_t et, Segment* sseg, Segment* eseg, bool,
88 : bool) = 0;
89 : };
90 :
91 : using IWriterPtr = std::shared_ptr<IWriter>;
92 : }
93 :
94 : #endif // MU_ENGRAVING_IWRITER_H
|