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 : #pragma once
23 :
24 : #include <memory>
25 : #include <variant>
26 :
27 : #include "types/ret.h"
28 :
29 : #include "../types/types.h"
30 : #include "xmlreader.h"
31 :
32 : namespace mu::engraving {
33 : class Score;
34 : class EngravingItem;
35 :
36 : class Accidental;
37 : class ChordRest;
38 : class Harmony;
39 : class Segment;
40 : class Spanner;
41 : class StaffTypeChange;
42 : class Symbol;
43 : class Text;
44 : class Tuplet;
45 :
46 : class Chord;
47 : class TremoloSingleChord;
48 : class TremoloTwoChord;
49 : }
50 :
51 : namespace mu::engraving::compat {
52 : struct TremoloCompat;
53 : }
54 :
55 : namespace mu::engraving::rw {
56 : struct ReadInOutData;
57 : class IReader
58 : {
59 : public:
60 1654 : virtual ~IReader() = default;
61 :
62 : virtual muse::Ret readScoreFile(Score* score, XmlReader& xml, rw::ReadInOutData* out) = 0;
63 :
64 : using Supported = std::variant<std::monostate,
65 : Accidental*,
66 : ChordRest*,
67 : Harmony*,
68 : Spanner*,
69 : StaffTypeChange*,
70 : Symbol*,
71 : Text*,
72 : Tuplet*
73 : >;
74 :
75 : template<typename T>
76 582 : static void check_supported_static(T item)
77 : {
78 : if constexpr (std::is_same<T, EngravingItem*>::value) {
79 : // supported
80 : } else {
81 0 : Supported check(item);
82 : (void)check;
83 : }
84 582 : }
85 :
86 : template<typename T>
87 582 : void readItem(T item, XmlReader& xml)
88 : {
89 : #ifndef NDEBUG
90 582 : check_supported_static(item);
91 : #endif
92 582 : doReadItem(static_cast<EngravingItem*>(item), xml);
93 582 : }
94 :
95 : //! NOTE Needs refactoring - reading should be separated from insertion
96 : //! (we read the elements into some structure, then inserted them)
97 : virtual bool pasteStaff(XmlReader& e, Segment* dst, staff_idx_t dstStaff, Fraction scale) = 0;
98 : virtual void pasteSymbols(XmlReader& e, ChordRest* dst) = 0;
99 :
100 : // compat
101 : virtual void readTremoloCompat(engraving::compat::TremoloCompat* item, XmlReader& xml) = 0;
102 :
103 : private:
104 : virtual void doReadItem(EngravingItem* item, XmlReader& xml) = 0;
105 : };
106 :
107 : using IReaderPtr = std::shared_ptr<IReader>;
108 : }
|