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 "part.h"
25 :
26 : namespace mu::engraving {
27 : // Map from origin track to shared track
28 : using SharedTrackMap = std::map<track_idx_t, track_idx_t>;
29 : std::string dump(const SharedTrackMap& map);
30 :
31 : class SharedPart final : public Part
32 : {
33 21 : OBJECT_ALLOCATOR(engraving, SharedPart)
34 : DECLARE_CLASSOF(ElementType::SHARED_PART)
35 :
36 : public:
37 : SharedPart(Score* score);
38 :
39 : void addOriginPart(Part* p);
40 : void removeOriginPart(Part* p);
41 844 : const std::vector<Part*>& originParts() const { return m_originParts; }
42 :
43 : const Part* originPart(track_idx_t sharedTrack, const Fraction& tick) const override;
44 : using Part::originPart;
45 : Part* originPartForStaff(staff_idx_t sharedStaffIdx, const Fraction& tick) const;
46 :
47 : String partName() const override;
48 :
49 : PropertyValue getProperty(Pid pid) const override;
50 : PropertyValue propertyDefault(Pid pid) const override;
51 : bool setProperty(Pid pid, const PropertyValue& v) override;
52 :
53 : bool enabled() const;
54 : bool show() const override;
55 :
56 : const SharedTrackMap& trackMapAtTick(const Fraction& tick) const;
57 : void setTrackMapAtTick(const SharedTrackMap& map, const Fraction& tick);
58 : void removeMapsBetweenTicks(const Fraction& startTick, const Fraction& endTick);
59 :
60 : bool isSameInstrumentsAtTick(const Fraction& tick);
61 :
62 123 : bool isSameInstruments() const { return m_isSameInstruments; }
63 :
64 : private:
65 : Part* mappedOriginPart(track_idx_t sharedTrack, const Fraction& tick) const;
66 :
67 : void computeIsSameInstruments();
68 : bool m_isSameInstruments = true;
69 :
70 : bool m_enabled = true;
71 : std::vector<Part*> m_originParts;
72 : std::map<Fraction, SharedTrackMap> m_trackMapsByTick { { Fraction(0, 1), SharedTrackMap() } };
73 : };
74 : }
|