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 : #ifndef MU_ENGRAVING_EXCERPT_H
24 : #define MU_ENGRAVING_EXCERPT_H
25 :
26 : #include "../types/fraction.h"
27 : #include "../types/types.h"
28 : #include "types/string.h"
29 :
30 : #include "async/notification.h"
31 :
32 : namespace mu::engraving {
33 : class MasterScore;
34 : class Measure;
35 : class Part;
36 : class Score;
37 : class Staff;
38 : class Spanner;
39 : class TieMap;
40 :
41 : class Excerpt
42 : {
43 : public:
44 164 : Excerpt(MasterScore* masterScore = nullptr) { m_masterScore = masterScore; }
45 : Excerpt(const Excerpt& ex, bool copyContents = true);
46 :
47 : ~Excerpt();
48 :
49 : bool inited() const;
50 :
51 : bool custom() const;
52 : void markAsCustom();
53 :
54 : const ID& initialPartId() const;
55 : void setInitialPartId(const ID& id);
56 :
57 595 : MasterScore* masterScore() const { return m_masterScore; }
58 4464 : Score* excerptScore() const { return m_excerptScore; }
59 : void setExcerptScore(Score* s);
60 :
61 : const String& name() const;
62 : void setName(const String& name, bool saveAndNotify = true);
63 : muse::async::Notification nameChanged() const;
64 :
65 : // The name used to store this excerpt in the msc file/folder.
66 : // When reading/writing, the engraving module sets this value, so that other
67 : // modules can also read/write data about this excerpt using the correct name.
68 : bool hasFileName() const;
69 : const String& fileName() const;
70 : void setFileName(const String& fileName);
71 : void updateFileName(size_t index = muse::nidx);
72 :
73 166 : std::vector<Part*>& parts() { return m_parts; }
74 : const std::vector<Part*>& parts() const { return m_parts; }
75 55 : void setParts(const std::vector<Part*>& parts) { m_parts = parts; }
76 :
77 : bool containsPart(const Part* part) const;
78 :
79 : void removePart(const ID& id);
80 :
81 : size_t nstaves() const;
82 : bool isEmpty() const;
83 :
84 : const TracksMap& tracksMapping();
85 : void setTracksMapping(const TracksMap& tracksMapping);
86 :
87 : void setVoiceVisible(Staff* staff, voice_idx_t voiceIndex, bool visible);
88 :
89 : static std::vector<Excerpt*> createExcerptsFromParts(const std::vector<Part*>& parts, MasterScore* score);
90 :
91 : static void createExcerpt(Excerpt*);
92 : static void cloneStaves(Score* sourceScore, Score* dstScore, const std::vector<staff_idx_t>& sourceStavesIndexes,
93 : const TracksMap& allTracks);
94 : static void cloneMeasures(Score* oscore, Score* score);
95 : static void linkMeasures(Score* excerptScore, Score* masterScore);
96 : static void cloneStaff(Staff* ostaff, Staff* nstaff, bool cloneSpanners = true);
97 : static void cloneStaff2(Staff* ostaff, Staff* nstaff, const Fraction& startTick, const Fraction& endTick);
98 : static void cloneSpanner(Spanner* s, Score* score, track_idx_t dstTrack, track_idx_t dstTrack2);
99 : static void createLinkedTabs(MasterScore* score);
100 :
101 : private:
102 : friend class MasterScore;
103 :
104 : static void promoteGapRestsToRealRests(const Measure* measure, staff_idx_t staffIdx);
105 : static void cloneMMRests(Score* sourceScore, Score* dstScore, const std::vector<staff_idx_t>& sourceStavesIndexes,
106 : const TracksMap& trackList, TieMap& tieMap);
107 :
108 : void setInited(bool inited);
109 : void writeNameToMetaTags();
110 :
111 : void updateTracksMapping();
112 :
113 : MasterScore* m_masterScore = nullptr;
114 : Score* m_excerptScore = nullptr;
115 : String m_name;
116 : String m_fileName;
117 : muse::async::Notification m_nameChanged;
118 : std::vector<Part*> m_parts;
119 : TracksMap m_tracksMapping;
120 : bool m_inited = false;
121 : ID m_initialPartId;
122 : };
123 : }
124 :
125 : #endif // MU_ENGRAVING_EXCERPT_H
|