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 "beambase.h"
26 : #include "engravingitem.h"
27 : #include "property.h"
28 :
29 : namespace mu::engraving {
30 : class Chord;
31 : class ChordRest;
32 : class Factory;
33 : class Skyline;
34 : class System;
35 : class Transaction;
36 : enum class ActionIconType : signed char;
37 : enum class SpannerSegmentType : unsigned char;
38 :
39 : struct TremAnchor {
40 : ChordRest* chord1 = nullptr;
41 : double y1 = 0.;
42 : double y2 = 0.;
43 : };
44 :
45 : //---------------------------------------------------------
46 : // @@ Beam
47 : //---------------------------------------------------------
48 :
49 : class Beam final : public BeamBase
50 : {
51 5342 : OBJECT_ALLOCATOR(engraving, Beam)
52 2376 : DECLARE_CLASSOF(ElementType::BEAM)
53 :
54 : public:
55 : ~Beam();
56 :
57 18 : Beam* clone() const override { return new Beam(*this); }
58 :
59 0 : bool isEditable() const override { return true; }
60 : void startEdit(EditData&) override;
61 : void dragGrip(EditData&) override;
62 :
63 : Fraction tick() const override;
64 : Fraction rtick() const override;
65 : Fraction ticks() const;
66 :
67 : void spatiumChanged(double /*oldValue*/, double /*newValue*/) override;
68 :
69 : void reset() override;
70 :
71 : //! A beam has no owner: its lifetime is managed by the chord/rests it beams,
72 : //! which drop it through ChordRest::removeDeleteBeam() once it runs empty.
73 : //! The system it is drawn on is that of its first chord/rest.
74 : System* system() const;
75 : EngravingItem* layoutParent() const override;
76 : EngravingItem* accessibleParentItem() const override;
77 :
78 30071 : const std::vector<ChordRest*>& elements() const { return m_elements; }
79 321205 : std::vector<ChordRest*>& elements() { return m_elements; }
80 18 : void clear() { m_elements.clear(); }
81 249 : bool empty() const { return m_elements.empty(); }
82 : bool contains(const ChordRest* cr) const
83 : {
84 : return std::find(m_elements.begin(), m_elements.end(), cr) != m_elements.end();
85 : }
86 :
87 : void add(EngravingItem*) override;
88 : void remove(EngravingItem*) override;
89 :
90 : void move(const PointF&) override;
91 :
92 : void setDirection(DirectionV d) override;
93 :
94 : void calcBeamBreaks(const ChordRest* chord, const ChordRest* prevChord, int level, bool& isBroken32, bool& isBroken64) const;
95 :
96 : //!Note Unfortunately we have no FEATHERED_BEAM_MODE for now int BeamMode enum, so we'll handle this locally
97 : void setAsFeathered(const bool slower);
98 : bool acceptDrop(EditData&) const override;
99 : EngravingItem* drop(Transaction& tx, EditData&) override;
100 :
101 12649 : double growLeft() const { return m_growLeft; }
102 5489 : double growRight() const { return m_growRight; }
103 1 : void setGrowLeft(double val) { m_growLeft = val; }
104 1 : void setGrowRight(double val) { m_growRight = val; }
105 :
106 : PairF beamPos() const;
107 : void setBeamPos(const PairF& bp);
108 3889 : double beamDist() const { return m_beamDist; }
109 17809 : void setBeamDist(double d) { m_beamDist = d; }
110 30032 : double beamWidth() const { return m_beamWidth; }
111 9054 : void setBeamWidth(double w) { m_beamWidth = w; }
112 8778 : int beamSpacing() const { return m_beamSpacing; }
113 8778 : void setBeamSpacing(int val) { m_beamSpacing = val; }
114 :
115 14237 : bool noSlope() const { return m_noSlope; }
116 : void setNoSlope(bool b);
117 :
118 24682 : double slope() const { return m_slope; }
119 : void computeAndSetSlope();
120 13124 : void setSlope(double val) { m_slope = val; }
121 :
122 : PropertyValue getProperty(Pid propertyId) const override;
123 : bool setProperty(Pid propertyId, const PropertyValue&) override;
124 : PropertyValue propertyDefault(Pid id) const override;
125 :
126 92 : void setIsGrace(bool val) { m_isGrace = val; }
127 12175 : bool isGrace() const { return m_isGrace; }
128 :
129 222368 : bool cross() const { return m_cross; }
130 4346 : void setCross(bool val) { m_cross = val; }
131 :
132 0 : bool fullCross() const { return m_fullCross; }
133 4346 : void setFullCross(bool v) { m_fullCross = v; }
134 :
135 70164 : int minCRMove() const override { return m_minCRMove; }
136 19163 : void setMinMove(int val) { m_minCRMove = val; }
137 74587 : int maxCRMove() const override { return m_maxCRMove; }
138 19163 : void setMaxMove(int val) { m_maxCRMove = val; }
139 :
140 : void addSkyline(Skyline&);
141 :
142 : void triggerLayout() const override;
143 :
144 0 : bool needStartEditingAfterSelecting() const override { return true; }
145 0 : int gripsCount() const override { return 3; }
146 0 : Grip initialEditModeGrip() const override { return Grip::END; }
147 0 : Grip defaultGrip() const override { return Grip::MIDDLE; }
148 : std::vector<PointF> gripsPositions(const EditData&) const override;
149 :
150 : static ActionIconType actionIconTypeForBeamMode(BeamMode);
151 :
152 : RectF drag(EditData&) override;
153 : bool isMovable() const override;
154 : void startDrag(EditData&) override;
155 :
156 : bool hasAllRests();
157 :
158 120 : const std::vector<TremAnchor>& tremAnchors() const { return m_tremAnchors; }
159 17398 : std::vector<TremAnchor>& tremAnchors() { return m_tremAnchors; }
160 :
161 1620 : const std::vector<BeamFragment*>& beamFragments() const { return m_fragments; }
162 29257 : std::vector<BeamFragment*>& beamFragments() { return m_fragments; }
163 6 : void addBeamFragment(BeamFragment* f) { m_fragments.push_back(f); }
164 :
165 : void clearBeamSegments() override;
166 :
167 4436 : const StaffType* tab() const { return m_tab; }
168 4432 : void setTab(const StaffType* t) { m_tab = t; }
169 13187 : bool isBesideTabStaff() const { return m_isBesideTabStaff; }
170 4432 : void setIsBesideTabStaff(bool val) { m_isBesideTabStaff = val; }
171 :
172 : const std::vector<NotePosition>& notePositions() const { return m_notePositions; }
173 83846 : std::vector<NotePosition>& notePositions() { return m_notePositions; }
174 :
175 : const Chord* findChordWithCustomStemDirection() const;
176 :
177 : const BeamSegment* topLevelSegmentForElement(const ChordRest* element) const;
178 :
179 : private:
180 :
181 : friend class Factory;
182 : friend class BeamSegment;
183 : Beam(Score* parent);
184 : Beam(const Beam&);
185 :
186 : void initBeamEditData(EditData& ed);
187 :
188 : static constexpr std::array MAX_SLOPES = { 0, 1, 2, 3, 4, 5, 6, 7 };
189 :
190 : void addChordRest(ChordRest* a);
191 : void removeChordRest(ChordRest* a);
192 :
193 : std::vector<ChordRest*> m_elements; // must be sorted by tick
194 :
195 : bool m_isGrace = false;
196 : bool m_cross = false;
197 : bool m_fullCross = false;
198 :
199 : double m_growLeft = 1.0; // define "feather" beams
200 : double m_growRight = 1.0;
201 : double m_beamDist = 0.0;
202 : int m_beamSpacing = 3; // how far apart beams are spaced in quarter spaces
203 : double m_beamWidth = 0.0; // how wide each beam is
204 :
205 : // for tabs
206 : bool m_isBesideTabStaff = false;
207 : const StaffType* m_tab = nullptr;
208 :
209 : std::vector<BeamFragment*> m_fragments; // beam splits across systems
210 :
211 : int m_minCRMove = 0; // set in layout1()
212 : int m_maxCRMove = 0;
213 : int m_crossBeamPos = 0;
214 :
215 : bool m_noSlope = false;
216 : real_t m_slope = 0.0;
217 :
218 : std::vector<NotePosition> m_notePositions;
219 : std::vector<TremAnchor> m_tremAnchors;
220 : };
221 : } // namespace mu::engraving
|