LCOV - code coverage report
Current view: top level - src/engraving/rw/read400 - readcontext.h Coverage Total Hit
Test: filtered_coverage.info Lines: 67.7 % 31 21
Test Date: 2026-11-05 04:07:02

            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 <map>
      26              : #include <optional>
      27              : #include <unordered_map>
      28              : 
      29              : #include "global/modularity/ioc.h"
      30              : 
      31              : #include "../../iengravingfontsprovider.h"
      32              : 
      33              : #include "../../types/types.h"
      34              : 
      35              : #include "../../dom/connector.h"
      36              : #include "../../dom/interval.h"
      37              : #include "../../dom/location.h"
      38              : #include "../../dom/sig.h"
      39              : 
      40              : #include "../linksindexer.h"
      41              : #include "../inoutdata.h"
      42              : 
      43              : #include "connectorinforeader.h"
      44              : 
      45              : namespace mu::engraving {
      46              : class BarLine;
      47              : class Beam;
      48              : class DummyParent;
      49              : class EngravingObject;
      50              : class LinkedObjects;
      51              : class Measure;
      52              : class Score;
      53              : class Spanner;
      54              : class Staff;
      55              : class Tuplet;
      56              : class MStyle;
      57              : }
      58              : 
      59              : namespace mu::engraving::read400 {
      60              : struct SpannerValues {
      61              :     int spannerId;
      62              :     Fraction tick2;
      63              :     track_idx_t track2;
      64              : };
      65              : 
      66              : struct TextStyleMap {
      67              :     String name;
      68              :     TextStyleType ss;
      69              : };
      70              : 
      71              : class ReadContext : public muse::Contextable
      72              : {
      73              : public:
      74              :     muse::GlobalInject<IEngravingFontsProvider> engravingFonts;
      75              : 
      76              : public:
      77              :     ReadContext(const muse::modularity::ContextPtr& iocCtx);
      78              :     ReadContext(Score* score);
      79              :     ~ReadContext();
      80              : 
      81              :     void setScore(Score* score);
      82              :     Score* score() const;
      83              : 
      84              :     const MStyle& style() const;
      85              : 
      86        17556 :     bool pasteMode() const { return _pasteMode; }
      87            0 :     void setPasteMode(bool v) { _pasteMode = v; }
      88              : 
      89              :     String mscoreVersion() const;
      90              :     int mscVersion() const;
      91              : 
      92              :     int fileDivision() const;
      93              :     int fileDivision(int t) const;
      94              : 
      95              :     double spatium() const;
      96              :     void setSpatium(double v);
      97          546 :     void setPropertiesToSkip(const PropertyIdSet& propertiesToSkip) { m_propertiesToSkip = propertiesToSkip; }
      98         4306 :     bool shouldSkipProperty(Pid pid) const { return muse::contains(m_propertiesToSkip, pid); }
      99            0 :     double originalSpatium() const { return m_originalSpatium; }
     100            0 :     void setOriginalSpatium(double v) { m_originalSpatium = v; }
     101         1026 :     bool overrideSpatium() const { return m_overrideSpatium; }
     102            0 :     void setOverrideSpatium(bool v) { m_overrideSpatium = v; }
     103              : 
     104            0 :     bool forcePageMode() const { return m_forcePageMode; }
     105          546 :     void setForcePageMode(bool v) { m_forcePageMode = v; }
     106              : 
     107              :     DummyParent* dummy() const;
     108              : 
     109              :     Staff* staff(staff_idx_t n);
     110              : 
     111              :     void appendStaff(Staff* staff);
     112              :     void addSpanner(Spanner* s);
     113              : 
     114              :     bool undoStackActive() const;
     115              : 
     116              :     bool isSameScore(const EngravingObject* obj) const;
     117              : 
     118        43432 :     Fraction tick()  const { return _tick + _tickOffset; }
     119              :     Fraction rtick()  const;
     120              :     Fraction tickOffset() const { return _tickOffset; }
     121              :     void setTick(const Fraction& f);
     122              :     void incTick(const Fraction& f);
     123            0 :     void setTickOffset(const Fraction& val) { _tickOffset = val; }
     124              : 
     125        20638 :     track_idx_t track() const { return _track + _trackOffset; }
     126            0 :     void setTrackOffset(int val) { _trackOffset = val; }
     127           59 :     int trackOffset() const { return _trackOffset; }
     128        23708 :     void setTrack(track_idx_t val) { _track = val; }
     129              : 
     130        10224 :     void setCurrentMeasure(Measure* m) { _curMeasure = m; }
     131           81 :     Measure* currentMeasure() const { return _curMeasure; }
     132         5987 :     void setLastMeasure(Measure* m) { _lastMeasure = m; }
     133         4407 :     Measure* lastMeasure() const { return _lastMeasure; }
     134         5990 :     void setCurrentMeasureIndex(int idx) { _curMeasureIdx = idx; }
     135         3224 :     int currentMeasureIndex() const { return _curMeasureIdx; }
     136              : 
     137              :     void addBeam(int beamId, Beam* s);
     138           98 :     Beam* findBeam(int id) const { return muse::value(_beams, id, nullptr); }
     139              : 
     140              :     void addTuplet(int tupletId, Tuplet* s);
     141          136 :     Tuplet* findTuplet(int id) const { return muse::value(_tuplets, id, nullptr); }
     142         3569 :     std::unordered_map<int, Tuplet*>& tuplets() { return _tuplets; }
     143              :     void checkTuplets();
     144              : 
     145              :     void removeSpanner(const Spanner*);
     146              :     void addSpanner(int id, Spanner*);
     147              :     Spanner* findSpanner(int id);
     148              : 
     149              :     int spannerId(const Spanner*);        // returns spanner id, allocates new one if none exists
     150              : 
     151            0 :     void addSpannerValues(const SpannerValues& sv) { _spannerValues.push_back(sv); }
     152              :     const SpannerValues* spannerValues(int id) const;
     153              : 
     154              :     Interval transpose() const { return _transpose; }
     155            0 :     void setTransposeChromatic(int8_t v) { _transpose.chromatic = v; }
     156            0 :     void setTransposeDiatonic(int8_t v) { _transpose.diatonic = v; }
     157              : 
     158           44 :     TracksMap& tracks() { return _tracks; }
     159              : 
     160              :     TextStyleType addUserTextStyle(const String& name);
     161              :     TextStyleType lookupUserTextStyle(const String& name) const;
     162            6 :     void clearUserTextStyles() { userTextStyles.clear(); }
     163              : 
     164              :     void addPartAudioSettingCompat(PartAudioSettingsCompat partAudioSetting);
     165          546 :     const SettingsCompat& settingCompat() { return _settingsCompat; }
     166              : 
     167              :     TimeSigMap* compatTimeSigMap();
     168              : 
     169              :     Location location(bool forceAbsFrac = false) const;
     170              :     void fillLocation(Location&, bool forceAbsFrac = false) const;
     171              :     void setLocation(const Location&);   // sets a new reading point, taking into account its type (absolute or relative).
     172              : 
     173              :     size_t getStaffBarLineSpan(staff_idx_t) const;
     174              :     void setStaffBarLineSpan(staff_idx_t, size_t barLineSpan);
     175              : 
     176              :     std::optional<size_t> getBarLineSpan(const BarLine*);
     177              :     void setBarLineSpan(const BarLine*, size_t barLineSpan);
     178              : 
     179              :     rw::ReadLinks readLinks() const;
     180              :     void initLinks(const rw::ReadLinks& l);
     181              :     void addLink(Staff* staff, LinkedObjects* link, const Location& location);
     182              :     LinkedObjects* getLink(bool isMasterScore, const Location& location, int localIndexDiff);
     183              : 
     184              :     void addConnectorInfoLater(std::shared_ptr<read400::ConnectorInfoReader> c);   // add connector info to be checked after calling checkConnectors()
     185              :     void checkConnectors();
     186              :     void reconnectBrokenConnectors();
     187              :     void clearOrphanedConnectors();
     188              : 
     189              : private:
     190              :     void addConnectorInfo(std::shared_ptr<read400::ConnectorInfoReader>);
     191              :     void removeConnector(const read400::ConnectorInfoReader*);   // Removes the whole ConnectorInfo chain from the connectors list.
     192              : 
     193              :     Score* m_score = nullptr;
     194              : 
     195              :     bool _pasteMode = false;  // modifies read behaviour on paste operation
     196              : 
     197              :     std::unordered_map<staff_idx_t, size_t> m_staffBarLineSpanValues;
     198              :     std::unordered_map<const BarLine*, size_t> m_barLineSpanValues;
     199              : 
     200              :     std::map<int /*staffIndex*/, std::vector<std::pair<LinkedObjects*, Location> > > m_staffLinkedElements; // one list per staff
     201              :     LinksIndexer m_linksIndexer;
     202              : 
     203              :     std::vector<std::shared_ptr<read400::ConnectorInfoReader> > _connectors;
     204              :     std::vector<std::shared_ptr<read400::ConnectorInfoReader> > _pendingConnectors;  // connectors that are pending to be updated and added to _connectors. That will happen when checkConnectors() is called.
     205              : 
     206              :     Fraction _tick             { Fraction(0, 1) };
     207              :     Fraction _tickOffset       { Fraction(0, 1) };
     208              :     int _intTick = 0;
     209              : 
     210              :     track_idx_t _track = 0;
     211              :     int _trackOffset = 0;
     212              : 
     213              :     Measure* _curMeasure = nullptr;
     214              :     Measure* _lastMeasure = nullptr;
     215              :     int _curMeasureIdx = 0;
     216              : 
     217              :     std::unordered_map<int, Beam*> _beams;
     218              :     std::unordered_map<int, Tuplet*> _tuplets;
     219              : 
     220              :     std::vector<SpannerValues> _spannerValues;
     221              :     std::vector<std::pair<int, Spanner*> > _spanner;
     222              : 
     223              :     Interval _transpose;
     224              :     TracksMap _tracks;
     225              : 
     226              :     std::vector<TextStyleMap> userTextStyles;
     227              : 
     228              :     SettingsCompat _settingsCompat;
     229              : 
     230              :     TimeSigMap m_compatTimeSigMap;
     231              :     bool m_overrideSpatium = false;
     232              :     double m_originalSpatium = 0;
     233              :     PropertyIdSet m_propertiesToSkip;
     234              :     bool m_forcePageMode = false;
     235              : };
     236              : }
        

Generated by: LCOV version 2.0-1