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 <functional>
26 :
27 : #include "../types/types.h"
28 :
29 : #include "durationelement.h"
30 : #include "fermata.h"
31 :
32 : namespace mu::engraving {
33 : enum class CrossMeasure : signed char {
34 : UNKNOWN = -1,
35 : NONE = 0,
36 : FIRST,
37 : SECOND
38 : };
39 :
40 : class Articulation;
41 : class BeamBase;
42 : class BeamSegment;
43 : class JianpuDurationLine;
44 : class Lyrics;
45 : class Measure;
46 : class Score;
47 : class Segment;
48 : class Slur;
49 : class TabDurationSymbol;
50 : class Transaction;
51 : enum class SegmentType;
52 :
53 : //-------------------------------------------------------------------
54 : // ChordRest
55 : // Virtual base class. Chords and rests can be part of a beam
56 : //-------------------------------------------------------------------
57 :
58 : class ChordRest : public DurationElement
59 : {
60 0 : OBJECT_ALLOCATOR(engraving, ChordRest)
61 3910 : DECLARE_CLASSOF(ElementType::INVALID) // dummy
62 :
63 : public:
64 : ChordRest(const ElementType& type, DummyParentOr<Segment, Chord> parent);
65 : ChordRest(const ChordRest&, bool link = false);
66 : ChordRest& operator=(const ChordRest&) = delete;
67 : ~ChordRest();
68 7349 : void setOwnershipParent(DummyParentOr<Segment, Chord> parent) { EngravingItem::setOwnershipParent(parent); }
69 :
70 : virtual void scanElements(std::function<void(EngravingItem*)> func) override;
71 :
72 : bool acceptDrop(EditData&) const override;
73 : virtual EngravingItem* drop(Transaction& tx, EditData&) override;
74 : virtual void undoUnlink() override;
75 :
76 107844 : virtual Segment* segment() const { return (Segment*)ownershipParent(); }
77 :
78 14799 : void setBeamMode(BeamMode m) { m_beamMode = m; }
79 610507 : BeamMode beamMode() const { return m_beamMode; }
80 :
81 : void setBeam(Beam* b);
82 : void setBeamlet(BeamSegment* b);
83 283027 : BeamSegment* beamlet() const { return m_beamlet; }
84 :
85 : virtual Beam* beam() const final;
86 625488 : int beams() const { return m_durationType.hooks(); }
87 : virtual double upPos() const = 0;
88 : virtual double downPos() const = 0;
89 :
90 : virtual double rightEdge() const = 0;
91 :
92 7429389 : bool isSmall() const { return m_isSmall; }
93 7170 : void setSmall(bool val) { m_isSmall = val; }
94 :
95 806025 : int staffMove() const { return m_staffMove; }
96 9398 : void setStaffMove(int val) { m_staffMove = val; }
97 99954 : int storedStaffMove() const { return m_storedStaffMove; }
98 2993657 : staff_idx_t vStaffIdx() const override { return staffIdx() + m_staffMove; }
99 : void checkStaffMoveValidity();
100 :
101 2428672 : const TDuration durationType() const
102 : {
103 2428672 : return m_crossMeasure == CrossMeasure::FIRST ? m_crossMeasureTDur : m_durationType;
104 : }
105 :
106 220656 : const TDuration actualDurationType() const { return m_durationType; }
107 : void setDurationType(DurationType t);
108 : void setDurationType(const Fraction& ticks);
109 : void setDurationType(TDuration v);
110 282 : void setDots(int n) { m_durationType.setDots(n); }
111 612150 : int dots() const
112 : {
113 612150 : return m_crossMeasure == CrossMeasure::FIRST
114 1224251 : ? m_crossMeasureTDur.dots()
115 1224251 : : (m_crossMeasure == CrossMeasure::SECOND ? 0 : m_durationType.dots());
116 : }
117 :
118 : int actualDots() const { return m_durationType.dots(); }
119 699 : Fraction durationTypeTicks() const
120 : {
121 699 : return m_crossMeasure == CrossMeasure::FIRST ? m_crossMeasureTDur.ticks() : m_durationType.ticks();
122 : }
123 :
124 : String durationUserName() const;
125 :
126 282543 : const std::vector<JianpuDurationLine*>& jianpuDurationLines() const { return m_jianpuDurationLines; }
127 214675 : std::vector<JianpuDurationLine*>& jianpuDurationLines() { return m_jianpuDurationLines; }
128 : void setJianpuDurationLineCount(size_t count);
129 :
130 : void setTrack(track_idx_t val) override;
131 :
132 667031 : const std::vector<Lyrics*>& lyrics() const { return m_lyrics; }
133 517115 : std::vector<Lyrics*>& lyrics() { return m_lyrics; }
134 : Lyrics* lyrics(int verse) const;
135 : Lyrics* lyrics(int verse, PlacementV) const;
136 : int lastVerse(PlacementV) const;
137 : bool isMelismaEnd() const;
138 : void setMelismaEnd(bool v);
139 :
140 : virtual void add(EngravingItem*) override;
141 : virtual void remove(EngravingItem*) override;
142 : void removeDeleteBeam(bool beamed);
143 : void replaceBeam(Beam* newBeam);
144 :
145 2194339 : const ElementList& el() const { return m_el; }
146 :
147 : //! TODO Look like a hack, see using
148 4 : void addFermata(Fermata* f) { addEl(f); }
149 4 : void removeFermata(Fermata* f) { removeEl(f); }
150 : //! --------------------------------
151 :
152 : Slur* slur(const ChordRest* secondChordRest = nullptr) const;
153 :
154 78128 : CrossMeasure crossMeasure() const { return m_crossMeasure; }
155 1999 : void setCrossMeasure(CrossMeasure val) { m_crossMeasure = val; }
156 :
157 : // the following two functions should not be used, unless absolutely necessary;
158 : // the cross-measure duration is best managed through setDuration() and crossMeasureSetup()
159 1977 : TDuration crossMeasureDurationType() const { return m_crossMeasureTDur; }
160 1979 : void setCrossMeasureDurationType(TDuration v) { m_crossMeasureTDur = v; }
161 :
162 : void undoChangeProperty(Pid id, const PropertyValue& newValue, PropertyFlags ps = PropertyFlags::NOSTYLE) override;
163 : void localSpatiumChanged(double oldValue, double newValue) override;
164 : PropertyValue getProperty(Pid propertyId) const override;
165 : bool setProperty(Pid propertyId, const PropertyValue&) override;
166 : PropertyValue propertyDefault(Pid) const override;
167 : bool isGrace() const;
168 : bool isGraceBefore() const;
169 : bool isGraceAfter() const;
170 : Breath* hasBreathMark() const;
171 :
172 : Segment* nextSegmentAfterCR(SegmentType types) const;
173 :
174 : void setScore(Score* s) override;
175 : EngravingItem* nextArticulationOrLyric(EngravingItem* e);
176 : EngravingItem* prevArticulationOrLyric(EngravingItem* e);
177 : virtual EngravingItem* nextElement() override;
178 : virtual EngravingItem* prevElement() override;
179 : EngravingItem* lastElementBeforeSegment();
180 : virtual EngravingItem* nextSegmentElement() override;
181 : virtual EngravingItem* prevSegmentElement() override;
182 : virtual String accessibleExtraInfo() const override;
183 : virtual void computeUp();
184 :
185 706291 : bool isFullMeasureRest() const { return m_durationType == DurationType::V_MEASURE; }
186 : virtual void removeMarkings(bool keepTremolo = false);
187 :
188 : bool isBefore(const EngravingItem*) const override;
189 :
190 : virtual double intrinsicMag() const = 0;
191 :
192 393119 : TabDurationSymbol* tabDur() const { return m_tabDur; }
193 55795 : void setTabDur(TabDurationSymbol* s) { m_tabDur = s; }
194 :
195 : bool isBelowCrossBeam(const BeamBase* beamBase) const;
196 :
197 : bool hasFollowingJumpItem() const;
198 : bool hasPrecedingJumpItem() const;
199 :
200 : struct LayoutData : public DurationElement::LayoutData {
201 : ld_field<bool> up = { "[ChordRest] up", true }; // actual stem direction
202 : };
203 4297656 : DECLARE_LAYOUTDATA_METHODS(ChordRest)
204 :
205 : //! DEPRECATED ------
206 550 : void setUp(bool val) { mutldata()->up = val; }
207 3053938 : bool up() const { return ldata()->up; }
208 : //! -----------------
209 :
210 : protected:
211 :
212 162 : void addEl(EngravingItem* e) { m_el.push_back(e); }
213 16 : bool removeEl(EngravingItem* e) { return m_el.remove(e); }
214 133 : void clearEls() { m_el.clear(); }
215 :
216 : std::vector<Lyrics*> m_lyrics;
217 : TabDurationSymbol* m_tabDur = nullptr; // stores a duration symbol in tablature staves
218 :
219 : Beam* m_beam = nullptr;
220 : BeamSegment* m_beamlet = nullptr;
221 : BeamMode m_beamMode = BeamMode::INVALID;
222 : bool m_isSmall = false;
223 : bool m_melismaEnd = false;
224 :
225 : // CrossMeasure: combine 2 tied notes if across a bar line and can be combined in a single duration
226 : CrossMeasure m_crossMeasure = CrossMeasure::UNKNOWN; ///< 0: no cross-measure modification; 1: 1st note of a mod.; -1: 2nd note
227 : TDuration m_crossMeasureTDur; ///< the total Duration type of the combined notes
228 :
229 : private:
230 :
231 : void processSiblings(std::function<void(EngravingItem*)> func);
232 :
233 : ElementList m_el;
234 : TDuration m_durationType;
235 : int m_staffMove = 0; // -1, 0, +1, used for crossbeaming
236 : int m_storedStaffMove = 0; // used to remember and re-apply staff move if needed
237 :
238 : std::vector<JianpuDurationLine*> m_jianpuDurationLines;
239 : };
240 : }
|