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 : #ifndef MU_ENGRAVING_ARTICULATION_H
24 : #define MU_ENGRAVING_ARTICULATION_H
25 :
26 : #include <set>
27 :
28 : #include "chordrest.h"
29 : #include "engravingitem.h"
30 :
31 : namespace mu::engraving {
32 : class Factory;
33 :
34 : class ChordRest;
35 : class Measure;
36 : class Page;
37 : class Segment;
38 : class System;
39 :
40 : //---------------------------------------------------------
41 : // ArticulationInfo
42 : // gives infos about note attributes
43 : //---------------------------------------------------------
44 :
45 : enum class ArticulationCategory : unsigned char {
46 : NONE = 0x0,
47 : DOUBLE = 0x1,
48 : TENUTO = 0x2,
49 : STACCATO = 0x4,
50 : ACCENT = 0x8,
51 : MARCATO = 0x10,
52 : LUTE_FINGERING = 0x20,
53 : LAISSEZ_VIB = 0x40,
54 : HANDBELLS = 0x80,
55 : };
56 : DECLARE_FLAGS(ArticulationCategories, ArticulationCategory)
57 : DECLARE_OPERATORS_FOR_FLAGS(ArticulationCategories)
58 :
59 : enum class ArticulationAnchor : char {
60 : TOP, // attribute is always placed at top
61 : BOTTOM, // attribute is placed at bottom
62 : AUTO, // anchor depends on chord direction, away from stem
63 : };
64 :
65 : enum class ArticulationStemSideAlign : char
66 : {
67 : // horizontal align for stem-side articulation layout
68 : STEM, // attribute is placed directly over the stem
69 : NOTEHEAD, // attribute is centered on the notehead
70 : AVERAGE, // attribute is placed at the average of stem pos and notehead center
71 : };
72 :
73 : // flags:
74 : enum class ArticulationShowIn : char {
75 : PITCHED_STAFF = 1, TABLATURE = 2
76 : };
77 :
78 : constexpr ArticulationShowIn operator|(ArticulationShowIn a1, ArticulationShowIn a2)
79 : {
80 : return static_cast<ArticulationShowIn>(static_cast<unsigned char>(a1) | static_cast<unsigned char>(a2));
81 : }
82 :
83 : constexpr bool operator&(ArticulationShowIn a1, ArticulationShowIn a2)
84 : {
85 : return static_cast<unsigned char>(a1) & static_cast<unsigned char>(a2);
86 : }
87 :
88 : enum class ArticulationsUpdateMode : unsigned char {
89 : Insert,
90 : Remove
91 : };
92 :
93 : std::set<SymId> updateArticulations(const std::set<SymId>& articulationSymbolIds, SymId articulationSymbolId,
94 : ArticulationsUpdateMode updateMode = ArticulationsUpdateMode::Insert);
95 : std::set<SymId> splitArticulations(const std::set<SymId>& articulationSymbolIds);
96 : std::set<SymId> joinArticulations(const std::set<SymId>& articulationSymbolIds);
97 : std::set<SymId> flipArticulations(const std::set<SymId>& articulationSymbolIds, PlacementV placement);
98 :
99 : //---------------------------------------------------------
100 : // @@ Articulation
101 : /// articulation marks
102 : //---------------------------------------------------------
103 :
104 : class Articulation : public EngravingItem
105 : {
106 2178 : OBJECT_ALLOCATOR(engraving, Articulation)
107 2389 : DECLARE_CLASSOF(ElementType::ARTICULATION)
108 :
109 : public:
110 :
111 92 : Articulation(const Articulation&) = default;
112 : Articulation& operator=(const Articulation&) = delete;
113 :
114 88 : virtual Articulation* clone() const override { return new Articulation(*this); }
115 162 : void setOwnershipParent(DummyParentOr<ChordRest, BarLine> parent) { EngravingItem::setOwnershipParent(parent); }
116 :
117 : virtual double mag() const override;
118 :
119 13015 : SymId symId() const { return m_symId; }
120 : void setSymId(SymId id);
121 : virtual int subtype() const override;
122 :
123 : void setTextType(ArticulationTextType textType);
124 7561 : ArticulationTextType textType() const { return m_textType; }
125 340 : Text* text() const { return m_text; }
126 28 : void setText(Text* t) { m_text = t; }
127 :
128 : void setSelected(bool f) override;
129 : void setVisible(bool f) override;
130 :
131 : TranslatableString typeUserName() const override;
132 : TranslatableString subtypeUserName() const override;
133 : String articulationName() const; // type-name of articulation; used for midi rendering
134 : static String symId2ArticulationName(SymId symId);
135 :
136 : bool layoutCloseToNote() const;
137 :
138 : bool isHiddenOnTabStaff() const;
139 :
140 : std::vector<LineF> dragAnchorLines() const override;
141 :
142 : PropertyValue getProperty(Pid propertyId) const override;
143 : bool setProperty(Pid propertyId, const PropertyValue&) override;
144 : PropertyValue propertyDefault(Pid) const override;
145 : void resetProperty(Pid id) override;
146 : Sid getPropertyStyle(Pid id) const override;
147 :
148 386 : void setDirection(DirectionV d) { m_direction = d; }
149 1132 : DirectionV direction() const { return m_direction; }
150 :
151 : ChordRest* chordRest() const;
152 : Segment* segment() const;
153 : Measure* measure() const;
154 : System* system() const;
155 : Page* page() const;
156 :
157 8227 : ArticulationAnchor anchor() const { return m_anchor; }
158 1709 : void setAnchor(ArticulationAnchor v) { m_anchor = v; }
159 :
160 951 : OrnamentStyle ornamentStyle() const { return m_ornamentStyle; }
161 180 : void setOrnamentStyle(OrnamentStyle val) { m_ornamentStyle = val; }
162 :
163 953 : bool playArticulation() const { return m_playArticulation; }
164 179 : void setPlayArticulation(bool val) { m_playArticulation = val; }
165 :
166 761 : String channelName() const { return m_channelName; }
167 0 : void setChannelName(const String& s) { m_channelName = s; }
168 :
169 : virtual String accessibleInfo() const override;
170 :
171 9013 : bool isDouble() const { return m_categories & ArticulationCategory::DOUBLE; }
172 15992 : bool isTenuto() const { return m_categories & ArticulationCategory::TENUTO; }
173 29372 : bool isStaccato() const { return m_categories & ArticulationCategory::STACCATO; }
174 3019 : bool isAccent() const { return m_categories & ArticulationCategory::ACCENT; }
175 2626 : bool isMarcato() const { return m_categories & ArticulationCategory::MARCATO; }
176 : bool isLuteFingering() const { return m_categories & ArticulationCategory::LUTE_FINGERING; }
177 14199 : bool isLaissezVib() const { return m_categories & ArticulationCategory::LAISSEZ_VIB; }
178 2490 : bool isHandbellsArticulation() const { return m_categories & ArticulationCategory::HANDBELLS; }
179 :
180 : bool isBasicArticulation() const;
181 :
182 : void styleChanged() override;
183 :
184 : bool isOnCrossBeamSide() const;
185 :
186 : staff_idx_t vStaffIdx() const override;
187 :
188 : struct LayoutData : public EngravingItem::LayoutData
189 : {
190 : ld_field<bool> up = { "[Articulation] up", true };
191 : ld_field<SymId> symId = { "[Articulation] symId", SymId::noSym };
192 :
193 1861 : void reset() override
194 : {
195 1861 : EngravingItem::LayoutData::reset();
196 1861 : up.reset();
197 1861 : symId.reset();
198 1861 : }
199 :
200 : double opticalCenter() const;
201 : };
202 42864 : DECLARE_LAYOUTDATA_METHODS(Articulation)
203 :
204 : void setUp(bool val);
205 :
206 : //! --- DEPRECATED ---
207 28878 : bool up() const { return ldata()->up; }
208 : //! ------------------
209 :
210 : protected:
211 : friend class mu::engraving::Factory;
212 : Articulation(DummyParentOr<ChordRest, BarLine> parent, ElementType type = ElementType::ARTICULATION);
213 :
214 : private:
215 :
216 : void setupShowOnTabStyles();
217 :
218 : enum class AnchorGroup : unsigned char {
219 : ARTICULATION,
220 : LUTE_FINGERING,
221 : OTHER
222 : };
223 : static AnchorGroup anchorGroup(SymId);
224 :
225 : void computeCategories();
226 :
227 : ArticulationCategories m_categories = ArticulationCategory::NONE;
228 :
229 : SymId m_symId = SymId::noSym;
230 : DirectionV m_direction = DirectionV::AUTO;
231 : String m_channelName;
232 :
233 : ArticulationTextType m_textType = ArticulationTextType::NO_TEXT;
234 : Text* m_text = nullptr;
235 :
236 : ArticulationAnchor m_anchor = ArticulationAnchor::AUTO;
237 :
238 : OrnamentStyle m_ornamentStyle = OrnamentStyle::DEFAULT; // for use in ornaments such as trill
239 : bool m_playArticulation = true;
240 :
241 : std::pair<Sid, Sid> m_showOnTabStyles = { Sid::NOSTYLE, Sid::NOSTYLE };
242 : };
243 : } // namespace mu::engraving
244 :
245 : #endif
|