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 "../types/types.h"
26 :
27 : #include "textlinebase.h"
28 :
29 : namespace mu::engraving {
30 : class Hairpin;
31 : class Transaction;
32 :
33 : enum class HairpinType : signed char {
34 : INVALID = -1,
35 : CRESC_HAIRPIN,
36 : DIM_HAIRPIN,
37 : CRESC_LINE,
38 : DIM_LINE
39 : };
40 :
41 : //---------------------------------------------------------
42 : // @@ HairpinSegment
43 : //---------------------------------------------------------
44 :
45 : class HairpinSegment final : public TextLineBaseSegment
46 : {
47 555 : OBJECT_ALLOCATOR(engraving, HairpinSegment)
48 : DECLARE_CLASSOF(ElementType::HAIRPIN_SEGMENT)
49 :
50 : public:
51 : HairpinSegment(Hairpin* sp);
52 :
53 17 : HairpinSegment* clone() const override { return new HairpinSegment(*this); }
54 :
55 7908 : Hairpin* hairpin() const { return (Hairpin*)spanner(); }
56 :
57 892 : bool drawCircledTip() const { return m_drawCircledTip; }
58 474 : void setDrawCircledTip(bool arg) { m_drawCircledTip = arg; }
59 1332 : double circledTipRadius() const { return m_circledTipRadius; }
60 472 : void setCircledTipRadius(double r) { m_circledTipRadius = r; }
61 3 : PointF circledTip() const { return m_circledTip; }
62 447 : void setCircledTip(const PointF& p) { m_circledTip = p; }
63 :
64 : EngravingObject* propertyDelegate(Pid) const override;
65 :
66 : int gripsCount() const override;
67 : std::vector<PointF> gripsPositions(const EditData& = EditData()) const override;
68 :
69 : std::unique_ptr<ElementGroup> getDragGroup(std::function<bool(const EngravingItem*)> isDragged) override;
70 :
71 172 : bool hasVoiceAssignmentProperties() const override { return spanner()->hasVoiceAssignmentProperties(); }
72 :
73 : EngravingItem* findElementToSnapBefore(bool ignoreInvisible = true) const;
74 : EngravingItem* findElementToSnapAfter(bool ignoreInvisible = true, bool requirePlayable = false) const;
75 :
76 : void endDragGrip(EditData& ed) override;
77 :
78 : private:
79 : TextBase* findStartDynamicOrExpression(bool ignoreInvisible = true) const;
80 : TextBase* findEndDynamicOrExpression(bool ignoreInvisible = true, bool requirePlayable = false) const;
81 :
82 : void startDragGrip(EditData&) override;
83 : void dragGrip(EditData&) override;
84 :
85 : Sid getPropertyStyle(Pid) const override;
86 :
87 : bool acceptDrop(EditData&) const override;
88 : EngravingItem* drop(Transaction& tx, EditData&) override;
89 :
90 : void setPropertyFlags(Pid id, PropertyFlags f) override;
91 :
92 : bool m_drawCircledTip = false;
93 : PointF m_circledTip;
94 : double m_circledTipRadius = 0.0;
95 : };
96 :
97 : //---------------------------------------------------------
98 : // @@ Hairpin
99 : // @P hairpinType enum (Hairpin.CRESCENDO, Hairpin.DIMINUENDO)
100 : // @P veloChange int
101 : //---------------------------------------------------------
102 :
103 : class Hairpin final : public TextLineBase
104 : {
105 721 : OBJECT_ALLOCATOR(engraving, Hairpin)
106 1754 : DECLARE_CLASSOF(ElementType::HAIRPIN)
107 :
108 : public:
109 : Hairpin(DummyParentOr<EngravingItem> parent);
110 :
111 22 : Hairpin* clone() const override { return new Hairpin(*this); }
112 :
113 5482 : Anchor anchor() const override { return Anchor::SEGMENT; }
114 :
115 : DynamicType dynamicTypeFrom() const;
116 : DynamicType dynamicTypeTo() const;
117 :
118 : const Dynamic* dynamicSnappedBefore() const;
119 : const Dynamic* dynamicSnappedAfter() const;
120 :
121 2834 : HairpinType hairpinType() const { return m_hairpinType; }
122 : void setHairpinType(HairpinType val);
123 :
124 : LineSegment* createLineSegment() override;
125 :
126 582 : bool hairpinCircledTip() const { return m_hairpinCircledTip; }
127 3 : void setHairpinCircledTip(bool val) { m_hairpinCircledTip = val; }
128 :
129 8 : int veloChange() const { return m_veloChange; }
130 19 : void setVeloChange(int v) { m_veloChange = v; }
131 :
132 446 : Spatium hairpinHeight() const { return m_hairpinHeight; }
133 0 : void setHairpinHeight(Spatium val) { m_hairpinHeight = val; }
134 :
135 446 : Spatium hairpinContHeight() const { return m_hairpinContHeight; }
136 0 : void setHairpinContHeight(Spatium val) { m_hairpinContHeight = val; }
137 :
138 : bool singleNoteDynamics() const { return m_singleNoteDynamics; }
139 0 : void setSingleNoteDynamics(bool val) { m_singleNoteDynamics = val; }
140 :
141 8 : ChangeMethod veloChangeMethod() const { return m_veloChangeMethod; }
142 0 : void setVeloChangeMethod(ChangeMethod val) { m_veloChangeMethod = val; }
143 :
144 38 : bool isCrescendo() const
145 : {
146 38 : return m_hairpinType == HairpinType::CRESC_HAIRPIN || m_hairpinType == HairpinType::CRESC_LINE;
147 : }
148 :
149 0 : bool isDecrescendo() const
150 : {
151 0 : return m_hairpinType == HairpinType::DIM_HAIRPIN || m_hairpinType == HairpinType::DIM_LINE;
152 : }
153 :
154 : PropertyValue getProperty(Pid id) const override;
155 : bool setProperty(Pid propertyId, const PropertyValue&) override;
156 : PropertyValue propertyDefault(Pid id) const override;
157 :
158 : String accessibleInfo() const override;
159 5305 : bool isLineType() const
160 : {
161 5305 : return m_hairpinType == HairpinType::CRESC_LINE || m_hairpinType == HairpinType::DIM_LINE;
162 : }
163 :
164 : PointF linePos(Grip grip, System** system) const override;
165 :
166 841 : bool hasVoiceAssignmentProperties() const override { return true; }
167 :
168 : void reset() override;
169 :
170 13 : void setVoiceAssignment(VoiceAssignment v) { m_voiceAssignment = v; }
171 1020 : VoiceAssignment voiceAssignment() const { return m_voiceAssignment; }
172 55 : void setDirection(DirectionV v) { m_direction = v; }
173 625 : DirectionV direction() const { return m_direction; }
174 9 : void setCenterBetweenStaves(AutoOnOff v) { m_centerBetweenStaves = v; }
175 814 : AutoOnOff centerBetweenStaves() const { return m_centerBetweenStaves; }
176 :
177 283 : bool snapToItemBefore() const { return m_snapToItemBefore; }
178 0 : void setSnapToItemBefore(bool v) { m_snapToItemBefore = v; }
179 317 : bool snapToItemAfter() const { return m_snapToItemAfter; }
180 0 : void setSnapToItemAfter(bool v) { m_snapToItemAfter = v; }
181 :
182 0 : int subtype() const override { return int(m_hairpinType); }
183 : TranslatableString subtypeUserName() const override;
184 :
185 : protected:
186 : Sid defaultPosSid() const override;
187 :
188 : private:
189 :
190 : Sid getPropertyStyle(Pid) const override;
191 :
192 : HairpinType m_hairpinType = HairpinType::INVALID;
193 : int m_veloChange = 0;
194 : bool m_hairpinCircledTip = false;
195 : bool m_singleNoteDynamics = false;
196 : ChangeMethod m_veloChangeMethod = ChangeMethod::NORMAL;
197 :
198 : Spatium m_hairpinHeight;
199 : Spatium m_hairpinContHeight;
200 :
201 : VoiceAssignment m_voiceAssignment = VoiceAssignment::ALL_VOICE_IN_INSTRUMENT;
202 : DirectionV m_direction = DirectionV::AUTO;
203 : AutoOnOff m_centerBetweenStaves = AutoOnOff::AUTO;
204 :
205 : bool m_snapToItemBefore = true;
206 : bool m_snapToItemAfter = true;
207 : };
208 : } // namespace mu::engraving
209 :
210 : #ifndef NO_QT_SUPPORT
211 16 : Q_DECLARE_METATYPE(mu::engraving::HairpinType)
212 : #endif
|