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 <array>
26 :
27 : #include "engravingitem.h"
28 : #include "draw/types/painterpath.h"
29 :
30 : #include "../types/types.h"
31 :
32 : namespace mu::engraving {
33 : class Factory;
34 :
35 : class Chord;
36 : class Note;
37 :
38 : //---------------------------------------------------------
39 : // @@ ChordLine
40 : /// bezier line attached to top note of a chord
41 : /// implements fall, doit, plop, bend
42 : //---------------------------------------------------------
43 :
44 : class ChordLine final : public EngravingItem
45 : {
46 284 : OBJECT_ALLOCATOR(engraving, ChordLine)
47 1868 : DECLARE_CLASSOF(ElementType::CHORDLINE)
48 :
49 : public:
50 :
51 4 : ChordLine* clone() const override { return new ChordLine(*this); }
52 : void setOwnershipParent(DummyParentOr<Chord> parent) { EngravingItem::setOwnershipParent(parent); }
53 :
54 672 : Chord* chord() const { return (Chord*)(ownershipParent()); }
55 :
56 : void setChordLineType(ChordLineType);
57 195 : ChordLineType chordLineType() const { return m_chordLineType; }
58 179 : bool isStraight() const { return m_straight; }
59 99 : void setStraight(bool straight) { m_straight = straight; }
60 526 : bool isWavy() const { return m_wavy; }
61 9 : void setWavy(bool wavy) { m_wavy = wavy; }
62 :
63 : // The shape is described by up to four points: the default points, in spatium units, plus the user's
64 : // offsets of these points, in absolute units. Both are at the chord's normal size: layout scales the
65 : // whole shape by the chord's intrinsic mag.
66 : enum class Point : unsigned char {
67 : START,
68 : BEZIER1,
69 : BEZIER2,
70 : END,
71 : POINTS_COUNT
72 : };
73 : using Points = std::array<PointF, static_cast<size_t>(Point::POINTS_COUNT)>;
74 :
75 : Points defaultPoints() const;
76 174 : const Points& bezierOffsets() const { return m_bezierOffsets; }
77 418 : const PointF& bezierOffset(Point point) const { return m_bezierOffsets[size_t(point)]; }
78 27 : void setBezierOffset(Point point, const PointF& offset) { m_bezierOffsets[size_t(point)] = offset; }
79 : static Pid bezierOffsetPid(Point point);
80 :
81 : double chordMag() const;
82 :
83 : const TranslatableString& chordLineTypeName() const;
84 :
85 : void startDragGrip(EditData&) override;
86 : void dragGrip(EditData&) override;
87 :
88 : String accessibleInfo() const override;
89 :
90 : int subtype() const override;
91 : TranslatableString subtypeUserName() const override;
92 :
93 : PropertyValue getProperty(Pid propertyId) const override;
94 : bool setProperty(Pid propertyId, const PropertyValue&) override;
95 : PropertyValue propertyDefault(Pid) const override;
96 : void reset() override;
97 :
98 : void spatiumChanged(double oldValue, double newValue) override;
99 : void localSpatiumChanged(double oldValue, double newValue) override;
100 :
101 0 : bool needStartEditingAfterSelecting() const override { return true; }
102 : int gripsCount() const override;
103 0 : Grip initialEditModeGrip() const override { return Grip(gripsCount() - 1); }
104 0 : Grip defaultGrip() const override { return initialEditModeGrip(); }
105 : std::vector<PointF> gripsPositions(const EditData&) const override;
106 :
107 866 : bool isToTheLeft() const { return m_chordLineType == ChordLineType::PLOP || m_chordLineType == ChordLineType::SCOOP; }
108 352 : bool isBelow() const { return m_chordLineType == ChordLineType::SCOOP || m_chordLineType == ChordLineType::FALL; }
109 :
110 5 : bool playChordLine() const { return m_playChordLine; }
111 1 : void setPlayChordLine(bool val) { m_playChordLine = val; }
112 :
113 : void setNote(Note* note);
114 578 : Note* note() const { return m_note; }
115 :
116 : SymId waveSym() const;
117 :
118 : struct LayoutData : public EngravingItem::LayoutData {
119 : muse::draw::PainterPath path;
120 : };
121 160 : DECLARE_LAYOUTDATA_METHODS(ChordLine)
122 :
123 : private:
124 :
125 : friend class Factory;
126 :
127 : ChordLine(DummyParentOr<Chord> parent);
128 : ChordLine(const ChordLine&);
129 :
130 : Point gripPoint(Grip grip) const;
131 :
132 : bool m_straight = false;
133 : bool m_wavy = false;
134 :
135 : ChordLineType m_chordLineType = ChordLineType::NOTYPE;
136 : Points m_bezierOffsets;
137 : bool m_playChordLine = true;
138 : Note* m_note = nullptr;
139 : };
140 : }
|