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 "pickscrape.h"
24 :
25 : #include "score.h"
26 : #include "system.h"
27 : #include "text.h"
28 :
29 : using namespace mu;
30 : using namespace mu::engraving;
31 :
32 : namespace mu::engraving {
33 : static const ElementStyle pickScrapeStyle {
34 : { Sid::palmMuteFontFace, Pid::BEGIN_FONT_FACE },
35 : { Sid::palmMuteFontFace, Pid::CONTINUE_FONT_FACE },
36 : { Sid::palmMuteFontFace, Pid::END_FONT_FACE },
37 : { Sid::palmMuteFontSize, Pid::BEGIN_FONT_SIZE },
38 : { Sid::palmMuteFontSize, Pid::CONTINUE_FONT_SIZE },
39 : { Sid::palmMuteFontSize, Pid::END_FONT_SIZE },
40 : { Sid::palmMuteFontStyle, Pid::BEGIN_FONT_STYLE },
41 : { Sid::palmMuteFontStyle, Pid::CONTINUE_FONT_STYLE },
42 : { Sid::palmMuteFontStyle, Pid::END_FONT_STYLE },
43 : { Sid::palmMuteTextAlign, Pid::BEGIN_TEXT_ALIGN },
44 : { Sid::palmMuteTextAlign, Pid::CONTINUE_TEXT_ALIGN },
45 : { Sid::palmMuteTextAlign, Pid::END_TEXT_ALIGN },
46 : { Sid::palmMutePosition, Pid::BEGIN_TEXT_POSITION },
47 : { Sid::palmMutePosition, Pid::CONTINUE_TEXT_POSITION },
48 : { Sid::palmMutePosition, Pid::END_TEXT_POSITION },
49 : { Sid::palmMuteHookHeight, Pid::BEGIN_HOOK_HEIGHT },
50 : { Sid::palmMuteHookHeight, Pid::END_HOOK_HEIGHT },
51 : { Sid::palmMuteLineStyle, Pid::LINE_STYLE },
52 : { Sid::palmMuteDashLineLen, Pid::DASH_LINE_LEN },
53 : { Sid::palmMuteDashGapLen, Pid::DASH_GAP_LEN },
54 : { Sid::palmMuteFontSpatiumDependent, Pid::TEXT_SIZE_SPATIUM_DEPENDENT },
55 : { Sid::palmMuteEndHookType, Pid::END_HOOK_TYPE },
56 : { Sid::palmMuteLineWidth, Pid::LINE_WIDTH },
57 : { Sid::palmMutePlacement, Pid::PLACEMENT },
58 : { Sid::palmMuteMusicalSymbolSize, Pid::BEGIN_TEXT_MUSIC_SYMBOLS_SIZE },
59 : { Sid::palmMuteMusicalSymbolSize, Pid::CONTINUE_TEXT_MUSIC_SYMBOLS_SIZE },
60 : { Sid::palmMuteMusicalSymbolSize, Pid::END_TEXT_MUSIC_SYMBOLS_SIZE },
61 : { Sid::dummyMusicalSymbolsScale, Pid::BEGIN_TEXT_MUSICAL_SYMBOLS_SCALE },
62 : { Sid::dummyMusicalSymbolsScale, Pid::CONTINUE_TEXT_MUSICAL_SYMBOLS_SCALE },
63 : { Sid::dummyMusicalSymbolsScale, Pid::END_TEXT_MUSICAL_SYMBOLS_SCALE },
64 : };
65 :
66 2 : PickScrapeSegment::PickScrapeSegment(PickScrape* sp)
67 2 : : TextLineBaseSegment(ElementType::PICK_SCRAPE_SEGMENT, sp, ElementFlag::MOVABLE | ElementFlag::ON_STAFF)
68 : {
69 2 : m_text->setTextStyleType(propertyDefault(Pid::TEXT_STYLE).value<TextStyleType>());
70 2 : m_endText->setTextStyleType(propertyDefault(Pid::TEXT_STYLE).value<TextStyleType>());
71 2 : }
72 :
73 : //---------------------------------------------------------
74 : // PickScrape
75 : //---------------------------------------------------------
76 :
77 2 : PickScrape::PickScrape(DummyParentOr<EngravingItem> parent)
78 2 : : ChordTextLineBase(ElementType::PICK_SCRAPE, parent)
79 : {
80 2 : initElementStyle(&pickScrapeStyle);
81 2 : resetProperty(Pid::LINE_VISIBLE);
82 :
83 2 : resetProperty(Pid::BEGIN_TEXT_PLACE);
84 2 : resetProperty(Pid::BEGIN_TEXT);
85 2 : resetProperty(Pid::CONTINUE_TEXT_PLACE);
86 2 : resetProperty(Pid::CONTINUE_TEXT);
87 2 : resetProperty(Pid::END_TEXT_PLACE);
88 2 : resetProperty(Pid::END_TEXT);
89 2 : }
90 :
91 : static const ElementStyle pickScrapeSegmentStyle {
92 : { Sid::palmMuteMinDistance, Pid::MIN_DISTANCE },
93 : };
94 :
95 : //---------------------------------------------------------
96 : // createLineSegment
97 : //---------------------------------------------------------
98 :
99 2 : LineSegment* PickScrape::createLineSegment()
100 : {
101 2 : PickScrapeSegment* wb = new PickScrapeSegment(this);
102 2 : wb->setTrack(track());
103 2 : wb->initElementStyle(&pickScrapeSegmentStyle);
104 2 : return wb;
105 : }
106 :
107 : //---------------------------------------------------------
108 : // propertyDefault
109 : //---------------------------------------------------------
110 :
111 76 : PropertyValue PickScrape::propertyDefault(Pid propertyId) const
112 : {
113 76 : switch (propertyId) {
114 0 : case Pid::LINE_WIDTH:
115 0 : return style().styleV(Sid::palmMuteLineWidth);
116 :
117 0 : case Pid::ALIGN:
118 0 : return Align(AlignH::LEFT, AlignV::BASELINE);
119 :
120 0 : case Pid::LINE_STYLE:
121 0 : return style().styleV(Sid::palmMuteLineStyle);
122 :
123 4 : case Pid::LINE_VISIBLE:
124 4 : return true;
125 :
126 4 : case Pid::CONTINUE_TEXT_OFFSET:
127 : case Pid::END_TEXT_OFFSET:
128 4 : return PropertyValue::fromValue(PointF(0, 0));
129 :
130 0 : case Pid::BEGIN_FONT_STYLE:
131 0 : return style().styleV(Sid::palmMuteFontStyle);
132 :
133 8 : case Pid::BEGIN_TEXT:
134 : case Pid::CONTINUE_TEXT:
135 8 : return PropertyValue::fromValue("P.S."); // TODO: fix the style
136 :
137 4 : case Pid::END_TEXT:
138 4 : return "";
139 :
140 2 : case Pid::BEGIN_HOOK_TYPE:
141 2 : return HookType::NONE;
142 :
143 12 : case Pid::BEGIN_TEXT_PLACE:
144 : case Pid::CONTINUE_TEXT_PLACE:
145 : case Pid::END_TEXT_PLACE:
146 12 : return TextPlace::AUTO;
147 :
148 4 : case Pid::TEXT_STYLE:
149 4 : return TextStyleType::PALM_MUTE;
150 :
151 16 : case Pid::BEGIN_FILLED_ARROW_HEIGHT: // No arrow endings for pick scrape
152 : case Pid::BEGIN_FILLED_ARROW_WIDTH:
153 : case Pid::END_FILLED_ARROW_HEIGHT:
154 : case Pid::END_FILLED_ARROW_WIDTH:
155 : case Pid::BEGIN_LINE_ARROW_HEIGHT:
156 : case Pid::BEGIN_LINE_ARROW_WIDTH:
157 : case Pid::END_LINE_ARROW_HEIGHT:
158 : case Pid::END_LINE_ARROW_WIDTH:
159 16 : return 0.0;
160 :
161 22 : default:
162 22 : return TextLineBase::propertyDefault(propertyId);
163 : }
164 : }
165 :
166 : //---------------------------------------------------------
167 : // getPropertyStyle
168 : //---------------------------------------------------------
169 :
170 62 : Sid PickScrape::getPropertyStyle(Pid id) const
171 : {
172 62 : switch (id) {
173 2 : case Pid::PLACEMENT:
174 2 : return Sid::palmMutePlacement;
175 2 : case Pid::BEGIN_FONT_FACE:
176 2 : return Sid::palmMuteFontFace;
177 6 : case Pid::BEGIN_FONT_SIZE:
178 : case Pid::CONTINUE_FONT_SIZE:
179 : case Pid::END_FONT_SIZE:
180 6 : return Sid::palmMuteFontSize;
181 6 : case Pid::BEGIN_FONT_STYLE:
182 : case Pid::CONTINUE_FONT_STYLE:
183 : case Pid::END_FONT_STYLE:
184 6 : return Sid::palmMuteFontStyle;
185 6 : case Pid::BEGIN_TEXT_ALIGN:
186 : case Pid::CONTINUE_TEXT_ALIGN:
187 : case Pid::END_TEXT_ALIGN:
188 6 : return Sid::palmMuteTextAlign;
189 4 : case Pid::BEGIN_HOOK_HEIGHT:
190 : case Pid::END_HOOK_HEIGHT:
191 4 : return Sid::palmMuteHookHeight;
192 36 : default:
193 36 : break;
194 : }
195 36 : return TextLineBase::getPropertyStyle(id);
196 : }
197 :
198 2 : Sid PickScrape::defaultPosSid() const
199 : {
200 2 : return placeAbove() ? Sid::palmMutePosAbove : Sid::palmMutePosBelow;
201 : }
202 : }
|