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