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 : #pragma once
24 :
25 : #include <vector>
26 :
27 : #include "iengravingfontsprovider.h"
28 :
29 : #include "../types/types.h"
30 :
31 : #include "dom/connector.h"
32 : #include "dom/interval.h"
33 : #include "dom/location.h"
34 :
35 : #include "connectorinforeader.h"
36 :
37 : namespace mu::engraving {
38 : class Beam;
39 : class DummyParent;
40 : class EngravingObject;
41 : class LinkedObjects;
42 : class Measure;
43 : class Score;
44 : class Spanner;
45 : class Staff;
46 : class Tuplet;
47 : class MStyle;
48 : }
49 :
50 : namespace mu::engraving::read460 {
51 : struct TextStyleMap {
52 : String name;
53 : TextStyleType ss;
54 : };
55 :
56 : class ReadContext
57 : {
58 : public:
59 :
60 : ReadContext() = default;
61 : ReadContext(Score* score);
62 : ~ReadContext();
63 :
64 : Score* score() const;
65 : void setScore(Score* score);
66 :
67 : const MStyle& style() const;
68 : std::shared_ptr<IEngravingFontsProvider> engravingFonts() const;
69 :
70 5233 : bool pasteMode() const { return _pasteMode; }
71 0 : void setPasteMode(bool v) { _pasteMode = v; }
72 :
73 : String mscoreVersion() const;
74 : int mscVersion() const;
75 :
76 : int fileDivision() const;
77 : int fileDivision(int t) const;
78 :
79 : double spatium() const;
80 : void setSpatium(double v);
81 117 : void setPropertiesToSkip(const PropertyIdSet& propertiesToSkip) { m_propertiesToSkip = propertiesToSkip; }
82 760 : bool shouldSkipProperty(Pid pid) const { return muse::contains(m_propertiesToSkip, pid); }
83 :
84 0 : bool forcePageMode() const { return m_forcePageMode; }
85 117 : void setForcePageMode(bool v) { m_forcePageMode = v; }
86 :
87 : DummyParent* dummy() const;
88 :
89 : Staff* staff(staff_idx_t n);
90 :
91 : bool isSameScore(const EngravingObject* obj) const;
92 :
93 12663 : Fraction tick() const { return _tick + _tickOffset; }
94 : Fraction rtick() const;
95 : Fraction tickOffset() const { return _tickOffset; }
96 : void setTick(const Fraction& f);
97 : void incTick(const Fraction& f);
98 0 : void setTickOffset(const Fraction& val) { _tickOffset = val; }
99 :
100 6604 : track_idx_t track() const { return _track + _trackOffset; }
101 0 : void setTrackOffset(int val) { _trackOffset = val; }
102 0 : int trackOffset() const { return _trackOffset; }
103 6250 : void setTrack(track_idx_t val) { _track = val; }
104 :
105 3390 : void setCurrentMeasure(Measure* m) { _curMeasure = m; }
106 50 : Measure* currentMeasure() const { return _curMeasure; }
107 1692 : void setLastMeasure(Measure* m) { _lastMeasure = m; }
108 1119 : Measure* lastMeasure() const { return _lastMeasure; }
109 1869 : void setCurrentMeasureIndex(int idx) { _curMeasureIdx = idx; }
110 432 : int currentMeasureIndex() const { return _curMeasureIdx; }
111 :
112 : Interval transpose() const { return _transpose; }
113 0 : void setTransposeChromatic(int8_t v) { _transpose.chromatic = v; }
114 0 : void setTransposeDiatonic(int8_t v) { _transpose.diatonic = v; }
115 :
116 14 : TracksMap& tracks() { return _tracks; }
117 :
118 : void addPartAudioSettingCompat(PartAudioSettingsCompat partAudioSetting);
119 117 : const SettingsCompat& settingCompat() { return _settingsCompat; }
120 :
121 1084 : Fraction timeSigForNextMeasure() { return m_timeSigForNextMeasure; }
122 1084 : void setTimeSigForNextMeasure(Fraction timeSig) { m_timeSigForNextMeasure = timeSig; }
123 :
124 : Location location(bool forceAbsFrac = false) const;
125 : void fillLocation(Location&, bool forceAbsFrac = false) const;
126 : void setLocation(const Location&); // sets a new reading point, taking into account its type (absolute or relative).
127 :
128 : void addConnectorInfoLater(std::shared_ptr<ConnectorInfoReader> c); // add connector info to be checked after calling checkConnectors()
129 : void checkConnectors();
130 : void reconnectBrokenConnectors();
131 : void clearOrphanedConnectors();
132 :
133 : private:
134 : void addConnectorInfo(std::shared_ptr<ConnectorInfoReader>);
135 : void removeConnector(const ConnectorInfoReader*); // Removes the whole ConnectorInfo chain from the connectors list.
136 :
137 : Score* m_score = nullptr;
138 :
139 : bool _pasteMode = false; // modifies read behaviour on paste operation
140 : bool m_forcePageMode = false;
141 :
142 : std::vector<std::shared_ptr<ConnectorInfoReader> > _connectors;
143 : std::vector<std::shared_ptr<ConnectorInfoReader> > _pendingConnectors; // connectors that are pending to be updated and added to _connectors. That will happen when checkConnectors() is called.
144 :
145 : Fraction _tick { Fraction(0, 1) };
146 : Fraction _tickOffset { Fraction(0, 1) };
147 : int _intTick = 0;
148 :
149 : int _trackOffset = 0;
150 : track_idx_t _track = 0;
151 :
152 : Measure* _curMeasure = nullptr;
153 : Measure* _lastMeasure = nullptr;
154 : int _curMeasureIdx = 0;
155 :
156 : Interval _transpose;
157 : TracksMap _tracks;
158 :
159 : SettingsCompat _settingsCompat;
160 :
161 : PropertyIdSet m_propertiesToSkip;
162 :
163 : Fraction m_timeSigForNextMeasure = Fraction(0, 1);
164 : };
165 : }
|