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 "slurtie.h"
26 :
27 : #include "global/allocator.h"
28 :
29 : namespace mu::engraving {
30 : //---------------------------------------------------------
31 : // @@ SlurSegment
32 : /// a single segment of slur; also used for Tie
33 : //---------------------------------------------------------
34 :
35 : class SlurSegment : public SlurTieSegment
36 : {
37 900 : OBJECT_ALLOCATOR(engraving, SlurSegment)
38 : DECLARE_CLASSOF(ElementType::SLUR_SEGMENT)
39 :
40 945 : M_PROPERTY2(double, extraHeight, setExtraHeight, 0.0)
41 973 : M_PROPERTY2(PointF, endPointOff1, setEndPointOff1, PointF(0.0, 0.0))
42 973 : M_PROPERTY2(PointF, endPointOff2, setEndPointOff2, PointF(0.0, 0.0))
43 :
44 : public:
45 : SlurSegment(Slur* sp, ElementType type = ElementType::SLUR_SEGMENT);
46 : SlurSegment(const SlurSegment& ss);
47 :
48 34 : SlurSegment* clone() const override { return new SlurSegment(*this); }
49 :
50 : bool isEdited() const;
51 : bool isEndPointsEdited() const;
52 : bool isEditAllowed(EditData&) const override;
53 : bool edit(EditData&) override;
54 :
55 : void dragGrip(EditData& ed) override;
56 :
57 18256 : Slur* slur() const { return toSlur(spanner()); }
58 :
59 : double endWidth() const override;
60 : double midWidth() const override;
61 : double dottedWidth() const override;
62 :
63 : Color curColor(const rendering::PaintOptions& opt) const override;
64 :
65 : protected:
66 : void changeAnchor(EditData&, EngravingItem*) override;
67 : };
68 :
69 : //---------------------------------------------------------
70 : // @@ Slur
71 : //---------------------------------------------------------
72 :
73 : class Slur : public SlurTie
74 : {
75 912 : OBJECT_ALLOCATOR(engraving, Slur)
76 3654 : DECLARE_CLASSOF(ElementType::SLUR)
77 :
78 : public:
79 : Slur(DummyParent* parent);
80 : Slur(const Slur&);
81 :
82 198426 : Anchor anchor() const override { return Anchor::CHORDREST; }
83 :
84 : struct StemFloated
85 : {
86 : bool left = false;
87 : bool right = false;
88 945 : void reset()
89 : {
90 945 : left = false;
91 945 : right = false;
92 945 : }
93 : };
94 :
95 : /// temporary HACK for correct guitar pro import
96 : enum ConnectedElement : unsigned char {
97 : NONE,
98 : GLISSANDO
99 : };
100 :
101 846 : ~Slur() {}
102 :
103 36 : Slur* clone() const override { return new Slur(*this); }
104 : void setOwnershipParent(EngravingObject*) = delete;
105 :
106 : void setTrack(track_idx_t val) override;
107 :
108 : PropertyValue getProperty(Pid propertyId) const override;
109 : PropertyValue propertyDefault(Pid propertyId) const override;
110 : bool setProperty(Pid propertyId, const PropertyValue& v) override;
111 :
112 976 : SlurSegment* frontSegment() { return toSlurSegment(Spanner::frontSegment()); }
113 : const SlurSegment* frontSegment() const { return toSlurSegment(Spanner::frontSegment()); }
114 879 : SlurSegment* backSegment() { return toSlurSegment(Spanner::backSegment()); }
115 : const SlurSegment* backSegment() const { return toSlurSegment(Spanner::backSegment()); }
116 0 : SlurSegment* segmentAt(int n) { return toSlurSegment(Spanner::segmentAt(n)); }
117 : const SlurSegment* segmentAt(int n) const { return toSlurSegment(Spanner::segmentAt(n)); }
118 :
119 : bool isCrossStaff();
120 : bool hasCrossBeams();
121 : const StemFloated& stemFloated() const { return m_stemFloated; }
122 2822 : StemFloated& stemFloated() { return m_stemFloated; }
123 :
124 482 : SlurTieSegment* newSlurTieSegment() override { return new SlurSegment(this); }
125 :
126 : double scalingFactor() const override;
127 :
128 : void undoSetIncoming(bool incoming);
129 : void undoSetOutgoing(bool outgoing);
130 : void setIncoming(bool incoming);
131 : void setOutgoing(bool outgoing);
132 : bool isIncoming() const;
133 : bool isOutgoing() const;
134 :
135 : void undoChangeStartEndElements(ChordRest* scr, ChordRest* ecr);
136 :
137 : protected:
138 : Slur(const ElementType& type, EngravingObject* parent);
139 :
140 : private:
141 10 : M_PROPERTY2(ConnectedElement, connectedElement, setConnectedElement, ConnectedElement::NONE)
142 330 : M_PROPERTY2(PartialSpannerDirection, partialSpannerDirection, setPartialSpannerDirection, PartialSpannerDirection::NONE)
143 :
144 : PartialSpannerDirection calcIncomingDirection(bool incoming);
145 : PartialSpannerDirection calcOutgoingDirection(bool outgoing);
146 :
147 : friend class Factory;
148 :
149 : StemFloated m_stemFloated; // end point position is attached to stem but floated towards the note
150 : };
151 : } // namespace mu::engraving
|