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
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 : #pragma once
24 :
25 : #include <vector>
26 :
27 : #include "iengravingfontsprovider.h"
28 :
29 : #include "../types/types.h"
30 :
31 : #include "dom/interval.h"
32 : #include "dom/location.h"
33 : #include "../infrastructure/eid.h"
34 :
35 : namespace mu::engraving {
36 : class Beam;
37 : class DummyParent;
38 : class EngravingObject;
39 : class LinkedObjects;
40 : class Measure;
41 : class MStyle;
42 : class Score;
43 : class Spanner;
44 : class Staff;
45 : class Tuplet;
46 : }
47 :
48 : namespace mu::engraving::read500 {
49 : struct TextStyleMap {
50 : String name;
51 : TextStyleType ss;
52 : };
53 :
54 : class ReadContext
55 : {
56 : public:
57 :
58 : ReadContext(Score* score, bool pasteMode = false);
59 : ~ReadContext();
60 :
61 : Score* score() const;
62 : void setScore(Score* score);
63 :
64 : const MStyle& style() const;
65 : std::shared_ptr<IEngravingFontsProvider> engravingFonts() const;
66 :
67 22765 : bool pasteMode() const { return _pasteMode; }
68 :
69 : String mscoreVersion() const;
70 : int mscVersion() const;
71 :
72 : int fileDivision() const;
73 : int fileDivision(int t) const;
74 :
75 : double spatium() const;
76 : void setSpatium(double v);
77 170 : void setPropertiesToSkip(const PropertyIdSet& propertiesToSkip) { m_propertiesToSkip = propertiesToSkip; }
78 1657 : bool shouldSkipProperty(Pid pid) const { return muse::contains(m_propertiesToSkip, pid); }
79 :
80 0 : bool forcePageMode() const { return m_forcePageMode; }
81 170 : void setForcePageMode(bool v) { m_forcePageMode = v; }
82 :
83 : DummyParent* dummy() const;
84 :
85 : Staff* staff(staff_idx_t n);
86 :
87 : bool isSameScore(const EngravingObject* obj) const;
88 :
89 27820 : Fraction tick() const { return _tick + _tickOffset; }
90 : Fraction rtick() const;
91 396 : Fraction tickOffset() const { return _tickOffset; }
92 : void setTick(const Fraction& f);
93 : void incTick(const Fraction& f);
94 42 : void setTickOffset(const Fraction& val) { _tickOffset = val; }
95 :
96 11267 : track_idx_t track() const { return _track + _trackOffset; }
97 45 : void setTrackOffset(int val) { _trackOffset = val; }
98 977 : int trackOffset() const { return _trackOffset; }
99 17710 : void setTrack(track_idx_t val) { _track = val; }
100 :
101 13012 : void setCurrentMeasure(Measure* m) { _curMeasure = m; }
102 2 : Measure* currentMeasure() const { return _curMeasure; }
103 6560 : void setLastMeasure(Measure* m) { _lastMeasure = m; }
104 4544 : Measure* lastMeasure() const { return _lastMeasure; }
105 6895 : void setCurrentMeasureIndex(int idx) { _curMeasureIdx = idx; }
106 4 : int currentMeasureIndex() const { return _curMeasureIdx; }
107 :
108 : Interval transpose() const { return _transpose; }
109 48 : void setTransposeChromatic(int8_t v) { _transpose.chromatic = v; }
110 48 : void setTransposeDiatonic(int8_t v) { _transpose.diatonic = v; }
111 :
112 136 : TracksMap& tracks() { return _tracks; }
113 :
114 : void addPartAudioSettingCompat(PartAudioSettingsCompat partAudioSetting);
115 170 : const SettingsCompat& settingCompat() { return _settingsCompat; }
116 :
117 4488 : Fraction timeSigForNextMeasure() { return m_timeSigForNextMeasure; }
118 4488 : void setTimeSigForNextMeasure(Fraction timeSig) { m_timeSigForNextMeasure = timeSig; }
119 :
120 : Location location(bool forceAbsFrac = false) const;
121 : void fillLocation(Location&, bool forceAbsFrac = false) const;
122 : void setLocation(const Location&); // sets a new reading point, taking into account its type (absolute or relative).
123 :
124 : void addMMRestEndMeasureEID(Measure* mmrest, EID lastMeasureEID);
125 : void setMMRestEndMeasures();
126 :
127 : void registerPastedEID(const EID& clipboardEid, const EID& fileEid);
128 : EID resolvePastedEID(const EID& clipboardEid) const;
129 :
130 : void addNoteAnchoredSpannerStartEl(Spanner* spanner, EID startElementEID);
131 : void addNoteAnchoredSpannerEndEl(Spanner* spanner, EID endElementEID);
132 : void connectNoteAnchoredSpanners();
133 :
134 : private:
135 : Score* m_score = nullptr;
136 :
137 : bool _pasteMode = false; // modifies read behaviour on paste operation
138 : bool m_forcePageMode = false;
139 :
140 : Fraction _tick { Fraction(0, 1) };
141 : Fraction _tickOffset { Fraction(0, 1) };
142 : int _intTick = 0;
143 :
144 : int _trackOffset = 0;
145 : track_idx_t _track = 0;
146 :
147 : Measure* _curMeasure = nullptr;
148 : Measure* _lastMeasure = nullptr;
149 : int _curMeasureIdx = 0;
150 :
151 : Interval _transpose;
152 : TracksMap _tracks;
153 :
154 : SettingsCompat _settingsCompat;
155 :
156 : PropertyIdSet m_propertiesToSkip;
157 :
158 : Fraction m_timeSigForNextMeasure = Fraction(0, 1);
159 :
160 : std::unordered_map<Measure*, EID> m_mmRestEndMeasures;
161 :
162 : // On pasting we must create new EIDs for the elements, as the serialized EIDs could be used elsewhere in the score
163 : // This map preserves the link between the old EID used to reference items within the section of the score which was copied and the newly created EID
164 : std::unordered_map<EID, EID> m_pastedEIDs;
165 :
166 : std::map<Spanner*, std::pair<EID, EID> > m_incompleteNoteAnchoredSpanners;
167 : };
168 : }
|