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 : #pragma once
23 :
24 : #include "engravingitem.h"
25 : #include "line.h"
26 : #include "property.h"
27 : #include "textbase.h"
28 :
29 : namespace mu::engraving {
30 : enum class GuitarBendType : unsigned char {
31 : BEND,
32 : PRE_BEND,
33 : GRACE_NOTE_BEND,
34 : SLIGHT_BEND,
35 :
36 : DIVE,
37 : PRE_DIVE,
38 : DIP,
39 : SCOOP,
40 : };
41 :
42 : enum class GuitarBendShowHoldLine : unsigned char {
43 : AUTO,
44 : SHOW,
45 : HIDE,
46 : };
47 :
48 : enum class ActionIconType : signed char;
49 :
50 : class GuitarBend final : public SLine
51 : {
52 740 : OBJECT_ALLOCATOR(engraving, GuitarBend)
53 : DECLARE_CLASSOF(ElementType::GUITAR_BEND)
54 :
55 1399 : M_PROPERTY2(DirectionV, direction, setDirection, DirectionV::AUTO)
56 9591 : M_PROPERTY2(int, bendAmountInQuarterTones, setBendAmountInQuarterTones, 4)
57 391 : M_PROPERTY2(GuitarBendShowHoldLine, showHoldLine, setShowHoldLine, GuitarBendShowHoldLine::AUTO)
58 1112 : M_PROPERTY2(float, startTimeFactor, setStartTimeFactor, 0.f)
59 1121 : M_PROPERTY2(float, endTimeFactor, setEndTimeFactor, 1.f)
60 :
61 : public:
62 : GuitarBend(DummyParentOr<Note> parent);
63 : GuitarBend(const GuitarBend&);
64 : ~GuitarBend() override;
65 :
66 4 : GuitarBend* clone() const override { return new GuitarBend(*this); }
67 292 : void setOwnershipParent(DummyParentOr<Note> parent) { EngravingItem::setOwnershipParent(parent); }
68 :
69 : LineSegment* createLineSegment() override;
70 :
71 1600 : Anchor anchor() const override { return Anchor::NOTE; }
72 :
73 0 : bool allowTimeAnchor() const override { return false; }
74 :
75 : Note* startNote() const;
76 : Note* startNoteOfChain() const;
77 :
78 : Note* endNote() const;
79 : void changeBendAmount(int bendAmount, int startBendAmount);
80 : void setEndNotePitch(int pitch, int quarterToneOffset);
81 :
82 : bool isReleaseBend() const;
83 : bool isFullRelease() const;
84 : bool angledPreBend() const;
85 : bool isDive() const;
86 : bool isFullReleaseDive() const;
87 :
88 : static void fixNotesFrettingForGraceBend(Note* grace, Note* main);
89 : static void fixNotesFrettingForStandardBend(Note* startNote, Note* endNote);
90 : static Note* createEndNote(Note* startNote, GuitarBendType bendType = GuitarBendType::BEND);
91 :
92 : PropertyValue getProperty(Pid id) const override;
93 : bool setProperty(Pid propertyId, const PropertyValue& v) override;
94 : PropertyValue propertyDefault(Pid id) const override;
95 :
96 : static constexpr int SLACK_BEND_AMOUNT = -33;
97 : void computeBendAmount();
98 : int totBendAmountIncludingPrecedingBends() const;
99 : void computeBendText();
100 : void computeIsInvalidOrNeedsWarning();
101 : bool isInvalid() const { return m_isInvalid; }
102 : bool isBorderlineUnplayable() const { return m_isBorderlineUnplayable; }
103 : GuitarBend* overlappingBendOrDive() const;
104 :
105 : GuitarBend* findPrecedingBend() const;
106 : GuitarBend* findFollowingPreBendOrDive() const;
107 : WhammyBar* findOverlappingWhammyBar(Fraction startTick, Fraction endTick) const;
108 :
109 : void updateHoldLine();
110 3 : void setHoldLine(GuitarBendHold* hold) { m_holdLine = hold; }
111 1640 : GuitarBendHold* holdLine() const { return m_holdLine; }
112 :
113 : double lineWidth() const;
114 :
115 : Color curColor(const rendering::PaintOptions& opt) const override;
116 :
117 0 : DirectionV diveTabPos() const { return m_diveTabPos; }
118 0 : void setDiveTabPos(DirectionV v) { m_diveTabPos = v; }
119 :
120 : static void adaptBendsFromTabToStandardStaff(const Staff* staff);
121 :
122 : static GuitarBendType bendTypeFromActionIcon(ActionIconType actionIconType);
123 107818 : GuitarBendType bendType() const { return m_bendType; }
124 : void setBendType(GuitarBendType t);
125 :
126 154 : VibratoType dipVibratoType() const { return m_dipVibratoType; }
127 0 : void setDipVibratoType(VibratoType v) { m_dipVibratoType = v; }
128 :
129 3846 : bool isSlack() const { return m_isSlack; }
130 0 : void setIsSlack(bool v) { m_isSlack = v; }
131 :
132 324 : std::optional<float> targetTimeFactor() const { return m_targetTimeFactor; }
133 : void setTargetTimeFactor(float v);
134 :
135 : struct LayoutData : public SLine::LayoutData
136 : {
137 : public:
138 6631 : bool up() const { return m_up; }
139 1095 : void setUp(bool v) { m_up = v; }
140 :
141 2190 : bool isInside() const { return m_isInside; }
142 1095 : void setIsInside(bool v) { m_isInside = v; }
143 :
144 106 : const String& bendDigit() const { return m_bendDigit; }
145 1537 : void setBendDigit(const String& s) { m_bendDigit = s; }
146 :
147 0 : const std::set<int>& diveLevels() const { return m_diveLevels; }
148 0 : void resetDiveLevels() { m_diveLevels.clear(); }
149 0 : void setDiveLevels(const std::set<int>& v) { m_diveLevels = v; }
150 :
151 0 : bool aboveStaff() const { return m_aboveStaff; }
152 0 : void setAboveStaff(bool v) { m_aboveStaff = v; }
153 :
154 : private:
155 : bool m_up = true;
156 : bool m_isInside = false;
157 : String m_bendDigit;
158 : std::set<int> m_diveLevels;
159 : bool m_aboveStaff = false;
160 : };
161 13053 : DECLARE_LAYOUTDATA_METHODS(GuitarBend)
162 :
163 : protected:
164 505 : bool isInSpannerMap() const override { return false; }
165 :
166 : private:
167 : GuitarBendType m_bendType = GuitarBendType::BEND;
168 : GuitarBendHold* m_holdLine = nullptr;
169 : bool m_isInvalid = false;
170 : bool m_isBorderlineUnplayable = false;
171 : DirectionV m_diveTabPos = DirectionV::AUTO;
172 : VibratoType m_dipVibratoType = VibratoType::NONE;
173 : bool m_isSlack = false;
174 : std::optional<float> m_targetTimeFactor;
175 : };
176 :
177 : class GuitarBendText; // forward decl
178 : class GuitarBendSegment final : public LineSegment
179 : {
180 738 : OBJECT_ALLOCATOR(engraving, GuitarBendSegment)
181 : DECLARE_CLASSOF(ElementType::GUITAR_BEND_SEGMENT)
182 :
183 : public:
184 : GuitarBendSegment(GuitarBend* sp);
185 : GuitarBendSegment(const GuitarBendSegment&);
186 : ~GuitarBendSegment() override;
187 :
188 9557 : GuitarBend* guitarBend() const { return toGuitarBend(spanner()); }
189 :
190 4 : GuitarBendSegment* clone() const override { return new GuitarBendSegment(*this); }
191 :
192 : int gripsCount() const override;
193 : std::vector<PointF> gripsPositions(const EditData& = EditData()) const override;
194 :
195 : PropertyValue getProperty(Pid id) const override;
196 : bool setProperty(Pid propertyId, const PropertyValue& v) override;
197 : PropertyValue propertyDefault(Pid id) const override;
198 : PropertyDelegate resolvePropertyDelegate(Pid id) const override;
199 :
200 3735 : PointF vertexPointOff() const { return m_vertexPointOff; }
201 0 : void setVertexPointOff(PointF p) { m_vertexPointOff = p; }
202 :
203 : void reset() override;
204 :
205 : double lineWidth() const;
206 :
207 : void scanElements(std::function<void(EngravingItem*)> func) override;
208 :
209 3082 : GuitarBendText* bendText() const { return m_text; }
210 0 : void setBendText(GuitarBendText* t) { m_text = t; }
211 :
212 : bool isUserModified() const override;
213 :
214 0 : std::vector<LineF> gripAnchorLines(Grip) const override { return {}; }
215 :
216 0 : Color curColor(const rendering::PaintOptions& opt) const override
217 : {
218 0 : return guitarBend()->curColor(opt);
219 : }
220 :
221 : struct LayoutData : public LineSegment::LayoutData
222 : {
223 : public:
224 95 : const PointF& vertexPoint() const { return m_vertexPoint; }
225 1242 : void setVertexPoint(PointF p) { m_vertexPoint = p; }
226 :
227 0 : const PainterPath& path() const { return m_path; }
228 1247 : void setPath(const PainterPath& path) { m_path = path; }
229 :
230 24 : const PolygonF& arrow() const { return m_arrow; }
231 1 : PolygonF& arrow() { return m_arrow; }
232 94 : void setArrow(const PolygonF& a) { m_arrow = a; }
233 :
234 : private:
235 : PointF m_vertexPoint = PointF(); // Coordinates relative to pos()
236 : PainterPath m_path = PainterPath();
237 : PolygonF m_arrow = PolygonF();
238 : };
239 4313 : DECLARE_LAYOUTDATA_METHODS(GuitarBendSegment)
240 :
241 : private:
242 : void startDragGrip(EditData& ed) override;
243 : void dragGrip(EditData& ed) override;
244 :
245 : PointF m_vertexPointOff = PointF();
246 : GuitarBendText* m_text = nullptr;
247 : };
248 :
249 : class GuitarBendHold final : public SLine
250 : {
251 6 : OBJECT_ALLOCATOR(engraving, GuitarBendHold)
252 : DECLARE_CLASSOF(ElementType::GUITAR_BEND_HOLD)
253 :
254 : public:
255 : GuitarBendHold(GuitarBend* parent);
256 : GuitarBendHold(const GuitarBendHold&);
257 :
258 0 : GuitarBendHold* clone() const override { return new GuitarBendHold(*this); }
259 :
260 12 : Anchor anchor() const override { return Anchor::NOTE; }
261 :
262 : LineSegment* createLineSegment() override;
263 :
264 : PropertyValue propertyDefault(Pid id) const override;
265 :
266 0 : bool allowTimeAnchor() const override { return false; }
267 :
268 : Note* startNote() const;
269 : Note* endNote() const;
270 :
271 6 : GuitarBend* guitarBend() const { return toGuitarBend(ownershipParent()); }
272 :
273 : double lineWidth() const;
274 :
275 : protected:
276 4 : bool isInSpannerMap() const override { return false; }
277 : };
278 :
279 : class GuitarBendHoldSegment final : public LineSegment
280 : {
281 4 : OBJECT_ALLOCATOR(engraving, GuitarBendHoldSegment)
282 : DECLARE_CLASSOF(ElementType::GUITAR_BEND_HOLD_SEGMENT)
283 :
284 : public:
285 : GuitarBendHoldSegment(GuitarBendHold* sp);
286 :
287 18 : GuitarBendHold* guitarBendHold() const { return toGuitarBendHold(spanner()); }
288 :
289 0 : GuitarBendHoldSegment* clone() const override { return new GuitarBendHoldSegment(*this); }
290 :
291 : GuitarBendSegment* startBendSeg() const { return m_startBendSeg; }
292 : GuitarBendSegment* endBendSeg() const { return m_endBendSeg; }
293 6 : void setStartBendSeg(GuitarBendSegment* s) { m_startBendSeg = s; }
294 6 : void setEndBendSeg(GuitarBendSegment* s) { m_endBendSeg = s; }
295 :
296 6 : double dashLength() const { return m_dashLength; }
297 :
298 6 : double lineWidth() const { return guitarBendHold()->lineWidth(); }
299 :
300 0 : std::vector<LineF> gripAnchorLines(Grip) const override { return {}; }
301 :
302 : struct LayoutData : LineSegment::LayoutData {
303 : public:
304 0 : const SymIdList& symIds() const { return m_symIds; }
305 0 : void setSymIds(const SymIdList& v) { m_symIds = v; }
306 :
307 : private:
308 : SymIdList m_symIds;
309 : };
310 8 : DECLARE_LAYOUTDATA_METHODS(GuitarBendHoldSegment)
311 :
312 : private:
313 : void dragGrip(EditData& ed) override;
314 :
315 : double m_dashLength = 3.0;
316 :
317 : GuitarBendSegment* m_startBendSeg = nullptr;
318 : GuitarBendSegment* m_endBendSeg = nullptr;
319 : };
320 :
321 : class GuitarBendText final : public TextBase
322 : {
323 738 : OBJECT_ALLOCATOR(engraving, GuitarBendText)
324 : DECLARE_CLASSOF(ElementType::GUITAR_BEND_TEXT)
325 :
326 : public:
327 : GuitarBendText(GuitarBendSegment* parent);
328 0 : GuitarBendText* clone() const override { return new GuitarBendText(*this); }
329 :
330 0 : bool isEditable() const override { return false; }
331 :
332 100 : bool positionRelativeToNoteheadRest() const override { return false; }
333 : };
334 : }
|