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