LCOV - code coverage report
Current view: top level - src/engraving/dom - sharedpart.h Coverage Total Hit
Test: filtered_coverage.info Lines: 70.6 % 17 12
Test Date: 2026-11-19 04:14:36

            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 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 <optional>
      25              : 
      26              : #include "part.h"
      27              : 
      28              : namespace mu::engraving {
      29              : // Map from origin track to shared track
      30              : using SharedTrackMap = std::map<track_idx_t, track_idx_t>;
      31              : std::string dump(const SharedTrackMap& map);
      32              : 
      33              : struct StaveSharingState {
      34              :     // User data
      35           76 :     const std::optional<SharedTrackMap>& userTrackMap() const { return m_userTrackMap; }
      36           23 :     void setUserTrackMap(std::optional<SharedTrackMap> map) { m_userTrackMap = map; }
      37              : 
      38         2330 :     bool isUserModified() const { return m_userTrackMap.has_value(); }
      39              : 
      40           23 :     void setIsReset(bool val) { m_isReset = val; }
      41           98 :     bool isReset() const { return m_isReset; }
      42              : 
      43              :     // Data calculated at layout
      44        26837 :     const SharedTrackMap& sharedTrackMap() const { return m_sharedTrackMap; }
      45          641 :     void setSharedTrackMap(SharedTrackMap map) { m_sharedTrackMap = map; }
      46              : 
      47           51 :     void setIsUserMapValid(bool val) { m_isUserMapValid = val; }
      48            5 :     bool isUserMapValid() const { return m_isUserMapValid; }
      49              : 
      50            0 :     bool operator==(const StaveSharingState& other) const
      51              :     {
      52            0 :         return m_sharedTrackMap == other.m_sharedTrackMap
      53            0 :                && m_userTrackMap == other.m_userTrackMap
      54            0 :                && m_isReset == other.m_isReset
      55            0 :                && m_isUserMapValid == other.m_isUserMapValid;
      56              :     }
      57              : 
      58              :     bool operator!=(const StaveSharingState& other) const { return !(*this == other); }
      59              : 
      60              : private:
      61              :     // User data
      62              :     std::optional<SharedTrackMap> m_userTrackMap;
      63              :     bool m_isReset = false;
      64              : 
      65              :     // Data calculated at layout
      66              :     SharedTrackMap m_sharedTrackMap;
      67              :     bool m_isUserMapValid = false;
      68              : };
      69              : 
      70              : class SharedPart;
      71              : using StaveSharingStatesByPart = std::map<SharedPart*, std::map<Fraction, StaveSharingState> >;
      72              : 
      73              : class SharedPart final : public Part
      74              : {
      75           75 :     OBJECT_ALLOCATOR(engraving, SharedPart)
      76              :     DECLARE_CLASSOF(ElementType::SHARED_PART)
      77              : 
      78              : public:
      79              :     SharedPart(Score* score);
      80              : 
      81              :     void addOriginPart(Part* p);
      82              :     void removeOriginPart(Part* p);
      83         1815 :     const std::vector<Part*>& originParts() const { return m_originParts; }
      84              : 
      85              :     const Part* originPart(track_idx_t sharedTrack, const Fraction& tick) const override;
      86              :     using Part::originPart;
      87              :     Part* originPartForStaff(staff_idx_t sharedStaffIdx, const Fraction& tick) const;
      88              : 
      89              :     String partName() const override;
      90              : 
      91              :     PropertyValue getProperty(Pid pid) const override;
      92              :     PropertyValue propertyDefault(Pid pid) const override;
      93              :     bool setProperty(Pid pid, const PropertyValue& v) override;
      94              : 
      95              :     bool enabled() const;
      96              :     bool show() const override;
      97              : 
      98              :     void insertTime(const Fraction& tick, const Fraction& len) override;
      99              : 
     100              :     const StaveSharingState& staveSharingStateAtTick(const Fraction& tick) const;
     101              :     StaveSharingState& staveSharingStateAtTick(const Fraction& tick);
     102              :     std::optional<StaveSharingState> exactStaveSharingStateAtTick(const Fraction& tick) const;
     103              :     void setStaveSharingStateAtTick(const StaveSharingState& state, const Fraction& tick);
     104              :     void removeStaveSharingStateAtTick(const Fraction& tick);
     105              :     void removeStaveSharingStatesBetweenTicks(const Fraction& startTick, const Fraction& endTick, bool removeUserChanges);
     106              :     std::map<Fraction, StaveSharingState> staveSharingStatesBetweenTicks(const Fraction& startTick, const Fraction& endTick) const;
     107              :     Fraction nextUserModifiedStaveSharingTick(const Fraction& tick) const;
     108              : 
     109              :     bool isSameInstrumentsAtTick(const Fraction& tick);
     110              : 
     111          553 :     bool isSameInstruments() const { return m_isSameInstruments; }
     112              : 
     113              : private:
     114              :     Part* mappedOriginPart(track_idx_t sharedTrack, const Fraction& tick) const;
     115              : 
     116              :     void computeIsSameInstruments();
     117              :     bool m_isSameInstruments = true;
     118              : 
     119              :     bool m_enabled = true;
     120              :     std::vector<Part*> m_originParts;
     121              :     std::map<Fraction, StaveSharingState> m_staveSharingStateByTick { { Fraction(0, 1), StaveSharingState() } };
     122              : };
     123              : }
        

Generated by: LCOV version 2.0-1