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 "palmmute.h"
24 :
25 : #include "chordrest.h"
26 : #include "part.h"
27 : #include "score.h"
28 : #include "staff.h"
29 : #include "stafftype.h"
30 : #include "system.h"
31 : #include "text.h"
32 :
33 : #include "log.h"
34 :
35 : using namespace mu;
36 : using namespace mu::engraving;
37 :
38 : namespace mu::engraving {
39 : static const ElementStyle palmMuteStyle {
40 : { Sid::palmMuteFontFace, Pid::BEGIN_FONT_FACE },
41 : { Sid::palmMuteFontFace, Pid::CONTINUE_FONT_FACE },
42 : { Sid::palmMuteFontFace, Pid::END_FONT_FACE },
43 : { Sid::palmMuteFontSize, Pid::BEGIN_FONT_SIZE },
44 : { Sid::palmMuteFontSize, Pid::CONTINUE_FONT_SIZE },
45 : { Sid::palmMuteFontSize, Pid::END_FONT_SIZE },
46 : { Sid::palmMuteFontStyle, Pid::BEGIN_FONT_STYLE },
47 : { Sid::palmMuteFontStyle, Pid::CONTINUE_FONT_STYLE },
48 : { Sid::palmMuteFontStyle, Pid::END_FONT_STYLE },
49 : { Sid::palmMuteTextAlign, Pid::BEGIN_TEXT_ALIGN },
50 : { Sid::palmMuteTextAlign, Pid::CONTINUE_TEXT_ALIGN },
51 : { Sid::palmMuteTextAlign, Pid::END_TEXT_ALIGN },
52 : { Sid::palmMutePosition, Pid::BEGIN_TEXT_POSITION },
53 : { Sid::palmMutePosition, Pid::CONTINUE_TEXT_POSITION },
54 : { Sid::palmMutePosition, Pid::END_TEXT_POSITION },
55 : { Sid::palmMuteHookHeight, Pid::BEGIN_HOOK_HEIGHT },
56 : { Sid::palmMuteHookHeight, Pid::END_HOOK_HEIGHT },
57 : { Sid::palmMuteLineStyle, Pid::LINE_STYLE },
58 : { Sid::palmMuteDashLineLen, Pid::DASH_LINE_LEN },
59 : { Sid::palmMuteDashGapLen, Pid::DASH_GAP_LEN },
60 : { Sid::palmMuteFontSpatiumDependent, Pid::TEXT_SIZE_SPATIUM_DEPENDENT },
61 : { Sid::palmMuteEndHookType, Pid::END_HOOK_TYPE },
62 : { Sid::palmMuteLineWidth, Pid::LINE_WIDTH },
63 : { Sid::palmMutePlacement, Pid::PLACEMENT },
64 : { Sid::palmMuteEndLineArrowHeight, Pid::END_LINE_ARROW_HEIGHT },
65 : { Sid::palmMuteEndLineArrowWidth, Pid::END_LINE_ARROW_WIDTH },
66 : { Sid::palmMuteBeginLineArrowHeight, Pid::BEGIN_LINE_ARROW_HEIGHT },
67 : { Sid::palmMuteBeginLineArrowWidth, Pid::BEGIN_LINE_ARROW_WIDTH },
68 : { Sid::palmMuteEndFilledArrowHeight, Pid::END_FILLED_ARROW_HEIGHT },
69 : { Sid::palmMuteEndFilledArrowWidth, Pid::END_FILLED_ARROW_WIDTH },
70 : { Sid::palmMuteBeginFilledArrowHeight, Pid::BEGIN_FILLED_ARROW_HEIGHT },
71 : { Sid::palmMuteBeginFilledArrowWidth, Pid::BEGIN_FILLED_ARROW_WIDTH },
72 : { Sid::palmMuteMusicalSymbolSize, Pid::BEGIN_TEXT_MUSIC_SYMBOLS_SIZE },
73 : { Sid::palmMuteMusicalSymbolSize, Pid::CONTINUE_TEXT_MUSIC_SYMBOLS_SIZE },
74 : { Sid::palmMuteMusicalSymbolSize, Pid::END_TEXT_MUSIC_SYMBOLS_SIZE },
75 : { Sid::dummyMusicalSymbolsScale, Pid::BEGIN_TEXT_MUSICAL_SYMBOLS_SCALE },
76 : { Sid::dummyMusicalSymbolsScale, Pid::CONTINUE_TEXT_MUSICAL_SYMBOLS_SCALE },
77 : { Sid::dummyMusicalSymbolsScale, Pid::END_TEXT_MUSICAL_SYMBOLS_SCALE },
78 : };
79 :
80 14 : PalmMuteSegment::PalmMuteSegment(PalmMute* sp)
81 14 : : TextLineBaseSegment(ElementType::PALM_MUTE_SEGMENT, sp, ElementFlag::MOVABLE | ElementFlag::ON_STAFF)
82 : {
83 14 : m_text->setTextStyleType(propertyDefault(Pid::TEXT_STYLE).value<TextStyleType>());
84 14 : m_endText->setTextStyleType(propertyDefault(Pid::TEXT_STYLE).value<TextStyleType>());
85 14 : }
86 :
87 : //---------------------------------------------------------
88 : // PalmMute
89 : //---------------------------------------------------------
90 :
91 92 : PalmMute::PalmMute(DummyParentOr<EngravingItem> parent)
92 92 : : ChordTextLineBase(ElementType::PALM_MUTE, parent)
93 : {
94 92 : initElementStyle(&palmMuteStyle);
95 92 : resetProperty(Pid::LINE_VISIBLE);
96 :
97 92 : resetProperty(Pid::BEGIN_TEXT_PLACE);
98 92 : resetProperty(Pid::BEGIN_TEXT);
99 92 : resetProperty(Pid::CONTINUE_TEXT_PLACE);
100 92 : resetProperty(Pid::CONTINUE_TEXT);
101 92 : resetProperty(Pid::END_TEXT_PLACE);
102 92 : resetProperty(Pid::END_TEXT);
103 92 : }
104 :
105 : //---------------------------------------------------------
106 : // createLineSegment
107 : //---------------------------------------------------------
108 :
109 : static const ElementStyle palmMuteSegmentStyle {
110 : { Sid::palmMuteMinDistance, Pid::MIN_DISTANCE },
111 : };
112 :
113 14 : LineSegment* PalmMute::createLineSegment()
114 : {
115 14 : PalmMuteSegment* pms = new PalmMuteSegment(this);
116 14 : pms->setTrack(track());
117 14 : pms->initElementStyle(&palmMuteSegmentStyle);
118 14 : return pms;
119 : }
120 :
121 : //---------------------------------------------------------
122 : // propertyDefault
123 : //---------------------------------------------------------
124 :
125 1717 : PropertyValue PalmMute::propertyDefault(Pid propertyId) const
126 : {
127 1717 : switch (propertyId) {
128 2 : case Pid::LINE_WIDTH:
129 2 : return style().styleV(Sid::palmMuteLineWidth);
130 :
131 0 : case Pid::ALIGN:
132 0 : return Align(AlignH::LEFT, AlignV::BASELINE);
133 :
134 2 : case Pid::LINE_STYLE:
135 2 : return style().styleV(Sid::palmMuteLineStyle);
136 :
137 137 : case Pid::LINE_VISIBLE:
138 137 : return true;
139 :
140 135 : case Pid::BEGIN_TEXT_OFFSET:
141 : case Pid::CONTINUE_TEXT_OFFSET:
142 : case Pid::END_TEXT_OFFSET:
143 135 : return PropertyValue::fromValue(PointF(0, 0));
144 :
145 274 : case Pid::BEGIN_TEXT:
146 : case Pid::CONTINUE_TEXT:
147 274 : return style().styleV(Sid::palmMuteText);
148 137 : case Pid::END_TEXT:
149 137 : return "";
150 :
151 45 : case Pid::BEGIN_HOOK_TYPE:
152 45 : return HookType::NONE;
153 :
154 411 : case Pid::BEGIN_TEXT_PLACE:
155 : case Pid::CONTINUE_TEXT_PLACE:
156 : case Pid::END_TEXT_PLACE:
157 411 : return TextPlace::AUTO;
158 :
159 28 : case Pid::TEXT_STYLE:
160 28 : return TextStyleType::PALM_MUTE;
161 :
162 546 : default:
163 546 : return TextLineBase::propertyDefault(propertyId);
164 : }
165 : }
166 :
167 16 : void PalmMute::setChannel()
168 : {
169 16 : EngravingItem* startEl = startElement();
170 16 : EngravingItem* endEl = endElement();
171 :
172 16 : if (!startEl || !endEl) {
173 0 : return;
174 : }
175 :
176 16 : if (!startEl->isChordRest() || !endEl->isChordRest()) {
177 0 : return;
178 : }
179 :
180 16 : ChordRest* startCR = toChordRest(startEl);
181 16 : ChordRest* endCR = toChordRest(endEl);
182 :
183 16 : Instrument* instrument = startCR->originPart()->instrument(startCR->tick());
184 16 : int idx = instrument->channelIdx(String::fromUtf8(InstrChannel::PALM_MUTE_NAME));
185 16 : if (idx > 0) {
186 0 : staff()->insertIntoChannelList(voice(), startCR->tick(), idx);
187 0 : staff()->insertIntoChannelList(voice(), endCR->endTick(), 0);
188 : }
189 : }
190 :
191 14 : Sid PalmMute::defaultPosSid() const
192 : {
193 14 : return placeAbove() ? Sid::palmMutePosAbove : Sid::palmMutePosBelow;
194 : }
195 : }
|