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 :
28 : #include "durationtype.h"
29 : #include "draw/types/painterpath.h"
30 : #include "../types/types.h"
31 : #include "beam.h"
32 : #include "chord.h"
33 :
34 : namespace mu::engraving {
35 : class Chord;
36 :
37 : class TremoloTwoChord final : public BeamBase
38 : {
39 157 : OBJECT_ALLOCATOR(engraving, TremoloTwoChord)
40 : DECLARE_CLASSOF(ElementType::TREMOLO_TWOCHORD)
41 :
42 : public:
43 :
44 : TremoloTwoChord& operator=(const TremoloTwoChord&) = delete;
45 0 : TremoloTwoChord* clone() const override { return new TremoloTwoChord(*this); }
46 27 : void setOwnershipParent(DummyParentOr<Chord> parent) { EngravingItem::setOwnershipParent(parent); }
47 : ~TremoloTwoChord() override;
48 :
49 226 : Chord* chord() const { return toChord(ownershipParent()); }
50 :
51 0 : int subtype() const override { return static_cast<int>(m_tremoloType); }
52 : TranslatableString subtypeUserName() const override;
53 :
54 : void scanElements(std::function<void(EngravingItem*)> func) override;
55 :
56 : void setTremoloType(TremoloType t);
57 134 : TremoloType tremoloType() const { return m_tremoloType; }
58 :
59 : double minHeight() const;
60 : void reset() override;
61 :
62 : PointF chordBeamAnchor(const ChordRest* chord, ChordBeamAnchorType anchorType) const;
63 :
64 : double chordMag() const;
65 : RectF drag(EditData&) override;
66 :
67 10959 : Chord* chord1() const { return m_chord1; }
68 458 : void setChord1(Chord* ch) { m_chord1 = ch; }
69 5374 : Chord* chord2() const { return m_chord2; }
70 61 : void setChord2(Chord* ch) { m_chord2 = ch; }
71 109 : void setChords(Chord* c1, Chord* c2)
72 : {
73 109 : m_chord1 = c1;
74 109 : m_chord2 = c2;
75 109 : }
76 :
77 : PairF beamPos() const;
78 :
79 : TDuration durationType() const;
80 : void setDurationType(TDuration d);
81 :
82 : Fraction tremoloLen() const;
83 9421 : int lines() const { return m_lines; }
84 :
85 : bool crossStaffBeamBetween() const;
86 :
87 : String accessibleInfo() const override;
88 : void triggerLayout() const override;
89 :
90 554 : TremoloStyle tremoloStyle() const { return m_style; }
91 31 : void setTremoloStyle(TremoloStyle v) { m_style = v; }
92 : void setDirection(DirectionV v) override;
93 0 : void setBeamFragment(const BeamFragment& bf) { m_beamFragment = bf; }
94 102 : const BeamFragment& beamFragment() const { return m_beamFragment; }
95 790 : BeamFragment& beamFragment() { return m_beamFragment; }
96 :
97 1 : bool playTremolo() const { return m_playTremolo; }
98 0 : void setPlayTremolo(bool v) { m_playTremolo = v; }
99 :
100 : bool customStyleApplicable() const;
101 :
102 : PropertyValue getProperty(Pid propertyId) const override;
103 : bool setProperty(Pid propertyId, const PropertyValue&) override;
104 : PropertyValue propertyDefault(Pid propertyId) const override;
105 :
106 : bool needStartEditingAfterSelecting() const override;
107 : int gripsCount() const override;
108 : Grip initialEditModeGrip() const override;
109 : Grip defaultGrip() const override;
110 : std::vector<PointF> gripsPositions(const EditData&) const override;
111 0 : bool isMovable() const override { return true; }
112 0 : bool isEditable() const override { return true; }
113 : void dragGrip(EditData&) override;
114 :
115 : void clearBeamSegments() override;
116 :
117 : int maxCRMove() const override;
118 : int minCRMove() const override;
119 :
120 : //! NOTE for palettes
121 : muse::draw::PainterPath basePath(double stretch = 0) const;
122 0 : const muse::draw::PainterPath& path() const { return m_path; }
123 0 : void setPath(const muse::draw::PainterPath& p) { m_path = p; }
124 : void computeShape();
125 : //! -----------------
126 :
127 : private:
128 : friend class Factory;
129 :
130 : TremoloTwoChord(DummyParentOr<Chord> parent);
131 : TremoloTwoChord(const TremoloTwoChord&);
132 :
133 : void setBeamPos(const PairF& bp);
134 :
135 : TremoloType m_tremoloType = TremoloType::INVALID_TREMOLO;
136 : Chord* m_chord1 = nullptr;
137 : Chord* m_chord2 = nullptr;
138 : TDuration m_durationType;
139 : bool m_playTremolo = true;
140 :
141 : int m_lines = 0; // derived from _subtype
142 : TremoloStyle m_style = TremoloStyle::DEFAULT;
143 : // for _startAnchor and _slope, once we decide to change trems so that they can
144 : // continue from one system to the other (or indeed, one measure to the other)
145 : // we will want a vector of fragments similar to Beam's _beamFragments structure.
146 : // for now, a single fragment is sufficient
147 : BeamFragment m_beamFragment;
148 :
149 : //! NOTE for palette
150 : PainterPath m_path;
151 : };
152 : }
|