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_OTTAVA_H
24 : #define MU_ENGRAVING_OTTAVA_H
25 :
26 : #include "types/translatablestring.h"
27 :
28 : #include "textlinebase.h"
29 : #include "property.h"
30 :
31 : namespace mu::engraving {
32 : //---------------------------------------------------------
33 : // OttavaE
34 : //---------------------------------------------------------
35 :
36 : struct OttavaE {
37 : int offset = 0;
38 : unsigned start = 0;
39 : unsigned end = 0;
40 : };
41 :
42 : //---------------------------------------------------------
43 : // OttavaType
44 : //---------------------------------------------------------
45 :
46 : enum class OttavaType : unsigned char {
47 : OTTAVA_8VA,
48 : OTTAVA_8VB,
49 : OTTAVA_15MA,
50 : OTTAVA_15MB,
51 : OTTAVA_22MA,
52 : OTTAVA_22MB
53 : };
54 :
55 : //---------------------------------------------------------
56 : // OttavaDefault
57 : //---------------------------------------------------------
58 :
59 : struct OttavaDefault {
60 : OttavaType type = OttavaType::OTTAVA_8VA;
61 : int shift = 0;
62 : const char* name = nullptr;
63 : const TranslatableString userName = TranslatableString();
64 : };
65 :
66 : // order is important, should be the same as OttavaType
67 : static const OttavaDefault ottavaDefault[] = {
68 : { OttavaType::OTTAVA_8VA, 12, "8va", TranslatableString("engraving/ottavatype", "8va alta") },
69 : { OttavaType::OTTAVA_8VB, -12, "8vb", TranslatableString("engraving/ottavatype", "8va bassa") },
70 : { OttavaType::OTTAVA_15MA, 24, "15ma", TranslatableString("engraving/ottavatype", "15ma alta") },
71 : { OttavaType::OTTAVA_15MB, -24, "15mb", TranslatableString("engraving/ottavatype", "15ma bassa") },
72 : { OttavaType::OTTAVA_22MA, 36, "22ma", TranslatableString("engraving/ottavatype", "22ma alta") },
73 : { OttavaType::OTTAVA_22MB, -36, "22mb", TranslatableString("engraving/ottavatype", "22ma bassa") }
74 : };
75 :
76 : class Ottava;
77 :
78 : //---------------------------------------------------------
79 : // @@ OttavaSegment
80 : //---------------------------------------------------------
81 :
82 : class OttavaSegment final : public TextLineBaseSegment
83 : {
84 219 : OBJECT_ALLOCATOR(engraving, OttavaSegment)
85 : DECLARE_CLASSOF(ElementType::OTTAVA_SEGMENT)
86 :
87 : void undoChangeProperty(Pid id, const PropertyValue&, PropertyFlags ps) override;
88 :
89 : public:
90 : OttavaSegment(Ottava* sp);
91 :
92 3 : OttavaSegment* clone() const override { return new OttavaSegment(*this); }
93 0 : Ottava* ottava() const { return (Ottava*)spanner(); }
94 :
95 : EngravingObject* propertyDelegate(Pid) const override;
96 :
97 0 : bool canBeExcludedFromOtherParts() const override { return true; }
98 :
99 : private:
100 : void rebaseOffsetsOnAnchorChanged(Grip grip, const PointF& oldPos, System* sys) override;
101 : };
102 :
103 : //---------------------------------------------------------
104 : // @@ Ottava
105 : // @P ottavaType enum (Ottava.OTTAVA_8VA, .OTTAVA_8VB, .OTTAVA_15MA, .OTTAVA_15MB, .OTTAVA_22MA, .OTTAVA_22MB)
106 : //---------------------------------------------------------
107 :
108 : class Ottava final : public TextLineBase
109 : {
110 373 : OBJECT_ALLOCATOR(engraving, Ottava)
111 1350 : DECLARE_CLASSOF(ElementType::OTTAVA)
112 :
113 : public:
114 : Ottava(DummyParentOr<EngravingItem> parent);
115 : Ottava(const Ottava&);
116 :
117 4 : Ottava* clone() const override { return new Ottava(*this); }
118 :
119 1649 : Anchor anchor() const override { return Anchor::SEGMENT; }
120 :
121 : void setOttavaType(OttavaType val);
122 238 : OttavaType ottavaType() const { return m_ottavaType; }
123 :
124 0 : int subtype() const override { return int(ottavaType()); }
125 : TranslatableString subtypeUserName() const override;
126 :
127 78 : bool numbersOnly() const { return m_numbersOnly; }
128 : void setNumbersOnly(bool val);
129 :
130 : void setPlacement(PlacementV);
131 :
132 : LineSegment* createLineSegment() override;
133 : int pitchShift() const;
134 :
135 : PropertyValue getProperty(Pid propertyId) const override;
136 : bool setProperty(Pid propertyId, const PropertyValue&) override;
137 : PropertyValue propertyDefault(Pid) const override;
138 :
139 : String accessibleInfo() const override;
140 : static const char* ottavaTypeName(OttavaType type);
141 :
142 : PointF linePos(Grip grip, System** system) const override;
143 0 : bool allowTimeAnchor() const override { return false; }
144 :
145 : protected:
146 : Sid defaultPosSid() const override;
147 : void doComputeEndElement() override;
148 :
149 : private:
150 :
151 : friend class OttavaSegment;
152 :
153 : void updateStyledProperties();
154 : Sid getPropertyStyle(Pid) const override;
155 : void undoChangeProperty(Pid id, const PropertyValue&, PropertyFlags ps) override;
156 :
157 : OttavaType m_ottavaType = OttavaType::OTTAVA_8VA;
158 : bool m_numbersOnly = false;
159 : };
160 : } // namespace mu::engraving
161 :
162 : #endif
|