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 : #include "harmonicmark.h"
24 :
25 : #include "dummyparent.h"
26 : #include "score.h"
27 : #include "system.h"
28 : #include "text.h"
29 :
30 : using namespace mu;
31 : using namespace mu::engraving;
32 :
33 : namespace mu::engraving {
34 : static const ElementStyle harmonicMarkStyle {
35 : { Sid::letRingFontFace, Pid::BEGIN_FONT_FACE },
36 : { Sid::letRingFontFace, Pid::CONTINUE_FONT_FACE },
37 : { Sid::letRingFontFace, Pid::END_FONT_FACE },
38 : { Sid::letRingFontSize, Pid::BEGIN_FONT_SIZE },
39 : { Sid::letRingFontSize, Pid::CONTINUE_FONT_SIZE },
40 : { Sid::letRingFontSize, Pid::END_FONT_SIZE },
41 : { Sid::letRingFontStyle, Pid::BEGIN_FONT_STYLE },
42 : { Sid::letRingFontStyle, Pid::CONTINUE_FONT_STYLE },
43 : { Sid::letRingFontStyle, Pid::END_FONT_STYLE },
44 : { Sid::letRingTextAlign, Pid::BEGIN_TEXT_ALIGN },
45 : { Sid::letRingTextAlign, Pid::CONTINUE_TEXT_ALIGN },
46 : { Sid::letRingTextAlign, Pid::END_TEXT_ALIGN },
47 : { Sid::letRingPosition, Pid::BEGIN_TEXT_POSITION },
48 : { Sid::letRingPosition, Pid::CONTINUE_TEXT_POSITION },
49 : { Sid::letRingPosition, Pid::END_TEXT_POSITION },
50 : { Sid::letRingHookHeight, Pid::BEGIN_HOOK_HEIGHT },
51 : { Sid::letRingHookHeight, Pid::END_HOOK_HEIGHT },
52 : { Sid::letRingLineStyle, Pid::LINE_STYLE },
53 : { Sid::letRingDashLineLen, Pid::DASH_LINE_LEN },
54 : { Sid::letRingDashGapLen, Pid::DASH_GAP_LEN },
55 : { Sid::letRingFontSpatiumDependent, Pid::TEXT_SIZE_SPATIUM_DEPENDENT },
56 : { Sid::letRingEndHookType, Pid::END_HOOK_TYPE },
57 : { Sid::letRingLineWidth, Pid::LINE_WIDTH },
58 : { Sid::ottava8VAPlacement, Pid::PLACEMENT },
59 :
60 : { Sid::letRingMusicalSymbolSize, Pid::BEGIN_TEXT_MUSIC_SYMBOLS_SIZE },
61 : { Sid::letRingMusicalSymbolSize, Pid::CONTINUE_TEXT_MUSIC_SYMBOLS_SIZE },
62 : { Sid::letRingMusicalSymbolSize, Pid::END_TEXT_MUSIC_SYMBOLS_SIZE },
63 : { Sid::dummyMusicalSymbolsScale, Pid::BEGIN_TEXT_MUSICAL_SYMBOLS_SCALE },
64 : { Sid::dummyMusicalSymbolsScale, Pid::CONTINUE_TEXT_MUSICAL_SYMBOLS_SCALE },
65 : { Sid::dummyMusicalSymbolsScale, Pid::END_TEXT_MUSICAL_SYMBOLS_SCALE },
66 : };
67 :
68 29 : HarmonicMarkSegment::HarmonicMarkSegment(HarmonicMark* sp)
69 29 : : TextLineBaseSegment(ElementType::HARMONIC_MARK_SEGMENT, sp, ElementFlag::MOVABLE | ElementFlag::ON_STAFF)
70 : {
71 29 : m_text->setTextStyleType(propertyDefault(Pid::TEXT_STYLE).value<TextStyleType>());
72 29 : m_endText->setTextStyleType(propertyDefault(Pid::TEXT_STYLE).value<TextStyleType>());
73 29 : }
74 :
75 : //---------------------------------------------------------
76 : // HarmonicMark
77 : //---------------------------------------------------------
78 :
79 91 : HarmonicMark::HarmonicMark(DummyParent* parent)
80 91 : : ChordTextLineBase(ElementType::HARMONIC_MARK, parent)
81 : {
82 91 : initElementStyle(&harmonicMarkStyle);
83 91 : resetProperty(Pid::LINE_VISIBLE);
84 :
85 91 : resetProperty(Pid::BEGIN_TEXT_PLACE);
86 91 : resetProperty(Pid::BEGIN_TEXT);
87 91 : resetProperty(Pid::CONTINUE_TEXT_PLACE);
88 91 : resetProperty(Pid::CONTINUE_TEXT);
89 91 : resetProperty(Pid::END_TEXT_PLACE);
90 91 : resetProperty(Pid::END_TEXT);
91 91 : }
92 :
93 3487 : bool HarmonicMark::setProperty(Pid propertyId, const PropertyValue& value)
94 : {
95 3487 : if (propertyId == Pid::BEGIN_TEXT || propertyId == Pid::CONTINUE_TEXT) {
96 182 : m_text = value.value<String>();
97 : }
98 :
99 3487 : return TextLineBase::setProperty(propertyId, value);
100 : }
101 :
102 : static const ElementStyle harmonicMarkSegmentStyle {
103 : { Sid::letRingMinDistance, Pid::MIN_DISTANCE },
104 : };
105 :
106 : //---------------------------------------------------------
107 : // createLineSegment
108 : //---------------------------------------------------------
109 :
110 29 : LineSegment* HarmonicMark::createLineSegment()
111 : {
112 29 : HarmonicMarkSegment* hm = new HarmonicMarkSegment(this);
113 29 : hm->setTrack(track());
114 29 : hm->initElementStyle(&harmonicMarkSegmentStyle);
115 29 : return hm;
116 : }
117 :
118 : //---------------------------------------------------------
119 : // propertyDefault
120 : //---------------------------------------------------------
121 :
122 2495 : PropertyValue HarmonicMark::propertyDefault(Pid propertyId) const
123 : {
124 2495 : switch (propertyId) {
125 2 : case Pid::LINE_WIDTH:
126 2 : return style().styleV(Sid::letRingLineWidth);
127 :
128 0 : case Pid::ALIGN:
129 0 : return Align(AlignH::LEFT, AlignV::BASELINE);
130 :
131 2 : case Pid::LINE_STYLE:
132 2 : return style().styleV(Sid::letRingLineStyle);
133 :
134 151 : case Pid::LINE_VISIBLE:
135 151 : return true;
136 :
137 120 : case Pid::CONTINUE_TEXT_OFFSET:
138 : case Pid::END_TEXT_OFFSET:
139 120 : return PropertyValue::fromValue(PointF(0, 0));
140 :
141 2 : case Pid::BEGIN_FONT_STYLE:
142 2 : return style().styleV(Sid::letRingFontStyle);
143 :
144 302 : case Pid::BEGIN_TEXT:
145 : case Pid::CONTINUE_TEXT:
146 302 : return PropertyValue::fromValue(m_text); // TODO: fix the style
147 151 : case Pid::END_TEXT:
148 151 : return "";
149 :
150 60 : case Pid::BEGIN_HOOK_TYPE:
151 60 : return HookType::NONE;
152 :
153 453 : case Pid::BEGIN_TEXT_PLACE:
154 : case Pid::CONTINUE_TEXT_PLACE:
155 : case Pid::END_TEXT_PLACE:
156 453 : return TextPlace::AUTO;
157 :
158 58 : case Pid::TEXT_STYLE:
159 58 : return TextStyleType::LET_RING;
160 :
161 480 : case Pid::BEGIN_FILLED_ARROW_HEIGHT: // No arrow endings for harmonic mark
162 : case Pid::BEGIN_FILLED_ARROW_WIDTH:
163 : case Pid::END_FILLED_ARROW_HEIGHT:
164 : case Pid::END_FILLED_ARROW_WIDTH:
165 : case Pid::BEGIN_LINE_ARROW_HEIGHT:
166 : case Pid::BEGIN_LINE_ARROW_WIDTH:
167 : case Pid::END_LINE_ARROW_HEIGHT:
168 : case Pid::END_LINE_ARROW_WIDTH:
169 480 : return 0.0;
170 :
171 714 : default:
172 714 : return TextLineBase::propertyDefault(propertyId);
173 : }
174 : }
175 :
176 : //---------------------------------------------------------
177 : // getPropertyStyle
178 : //---------------------------------------------------------
179 :
180 2844 : Sid HarmonicMark::getPropertyStyle(Pid id) const
181 : {
182 2844 : switch (id) {
183 93 : case Pid::PLACEMENT:
184 93 : return Sid::ottava8VAPlacement;
185 93 : case Pid::BEGIN_FONT_FACE:
186 93 : return Sid::letRingFontFace;
187 279 : case Pid::BEGIN_FONT_SIZE:
188 : case Pid::CONTINUE_FONT_SIZE:
189 : case Pid::END_FONT_SIZE:
190 279 : return Sid::letRingFontSize;
191 277 : case Pid::BEGIN_FONT_STYLE:
192 : case Pid::CONTINUE_FONT_STYLE:
193 : case Pid::END_FONT_STYLE:
194 277 : return Sid::letRingFontStyle;
195 279 : case Pid::BEGIN_TEXT_ALIGN:
196 : case Pid::CONTINUE_TEXT_ALIGN:
197 : case Pid::END_TEXT_ALIGN:
198 279 : return Sid::letRingTextAlign;
199 186 : case Pid::BEGIN_HOOK_HEIGHT:
200 : case Pid::END_HOOK_HEIGHT:
201 186 : return Sid::letRingHookHeight;
202 1637 : default:
203 1637 : break;
204 : }
205 1637 : return TextLineBase::getPropertyStyle(id);
206 : }
207 :
208 0 : Sid HarmonicMark::defaultPosSid() const
209 : {
210 0 : return placeAbove() ? Sid::letRingPosAbove : Sid::letRingPosBelow;
211 : }
212 : }
|