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 "tremolobar.h"
24 :
25 : #include "draw/types/pen.h"
26 :
27 : #include "score.h"
28 :
29 : #include "log.h"
30 :
31 : using namespace mu;
32 : using namespace mu::engraving;
33 :
34 : namespace mu::engraving {
35 : //---------------------------------------------------------
36 : // tremoloBarStyle
37 : //---------------------------------------------------------
38 :
39 : static const ElementStyle tremoloBarStyle {
40 : { Sid::tremoloBarLineWidth, Pid::LINE_WIDTH },
41 : };
42 :
43 : static const PitchValues DIP_CURVE = { PitchValue(0, 0),
44 : PitchValue(30, -100),
45 : PitchValue(60, 0) };
46 :
47 : static const PitchValues DIVE_CURVE = { PitchValue(0, 0),
48 : PitchValue(60, -150) };
49 :
50 : static const PitchValues RELEASE_UP_CURVE = { PitchValue(0, -150),
51 : PitchValue(60, 0) };
52 :
53 : static const PitchValues INVERTED_DIP_CURVE = { PitchValue(0, 0),
54 : PitchValue(30, 100),
55 : PitchValue(60, 0) };
56 :
57 : static const PitchValues RETURN_CURVE = { PitchValue(0, 0),
58 : PitchValue(60, 150) };
59 :
60 : static const PitchValues RELEASE_DOWN_CURVE = { PitchValue(0, 150),
61 : PitchValue(60, 0) };
62 :
63 : //---------------------------------------------------------
64 : // TremoloBar
65 : //---------------------------------------------------------
66 :
67 30 : TremoloBar::TremoloBar(DummyParentOr<EngravingItem> parent)
68 30 : : EngravingItem(ElementType::TREMOLOBAR, parent, ElementFlag::MOVABLE | ElementFlag::ON_STAFF)
69 : {
70 30 : initElementStyle(&tremoloBarStyle);
71 30 : }
72 :
73 : //---------------------------------------------------------
74 : // getProperty
75 : //---------------------------------------------------------
76 :
77 51 : PropertyValue TremoloBar::getProperty(Pid propertyId) const
78 : {
79 51 : switch (propertyId) {
80 0 : case Pid::LINE_WIDTH:
81 0 : return lineWidth();
82 4 : case Pid::MAG:
83 4 : return userMag();
84 4 : case Pid::PLAY:
85 4 : return play();
86 7 : case Pid::TREMOLOBAR_TYPE:
87 7 : return static_cast<int>(parseTremoloBarTypeFromCurve(m_points));
88 0 : case Pid::TREMOLOBAR_CURVE:
89 0 : return m_points;
90 36 : default:
91 36 : return EngravingItem::getProperty(propertyId);
92 : }
93 : }
94 :
95 : //---------------------------------------------------------
96 : // setProperty
97 : //---------------------------------------------------------
98 :
99 31 : bool TremoloBar::setProperty(Pid propertyId, const PropertyValue& v)
100 : {
101 31 : switch (propertyId) {
102 31 : case Pid::LINE_WIDTH:
103 31 : setLineWidth(v.value<Spatium>());
104 31 : break;
105 0 : case Pid::MAG:
106 0 : setUserMag(v.toDouble());
107 0 : break;
108 0 : case Pid::PLAY:
109 0 : setPlay(v.toBool());
110 0 : break;
111 0 : case Pid::TREMOLOBAR_TYPE:
112 0 : updatePointsByTremoloBarType(static_cast<TremoloBarType>(v.toInt()));
113 0 : break;
114 0 : case Pid::TREMOLOBAR_CURVE:
115 0 : setPoints(v.value<PitchValues>());
116 0 : break;
117 0 : default:
118 0 : return EngravingItem::setProperty(propertyId, v);
119 : }
120 31 : triggerLayout();
121 31 : return true;
122 : }
123 :
124 : //---------------------------------------------------------
125 : // propertyDefault
126 : //---------------------------------------------------------
127 :
128 44 : PropertyValue TremoloBar::propertyDefault(Pid pid) const
129 : {
130 44 : switch (pid) {
131 4 : case Pid::MAG:
132 4 : return 1.0;
133 4 : case Pid::PLAY:
134 4 : return true;
135 0 : case Pid::TREMOLOBAR_TYPE:
136 0 : return static_cast<int>(TremoloBarType::DIP);
137 0 : case Pid::TREMOLOBAR_CURVE:
138 0 : return DIP_CURVE;
139 36 : default:
140 72 : for (const StyledProperty& p : *styledProperties()) {
141 36 : if (p.pid == pid) {
142 0 : if (propertyType(pid) == P_TYPE::ABSOLUTE) {
143 0 : return style().styleAbsolute(p.sid);
144 : }
145 0 : return style().styleV(p.sid);
146 : }
147 : }
148 36 : return EngravingItem::propertyDefault(pid);
149 : }
150 : }
151 :
152 7 : TremoloBarType TremoloBar::parseTremoloBarTypeFromCurve(const PitchValues& curve) const
153 : {
154 7 : if (curve == DIP_CURVE) {
155 1 : return TremoloBarType::DIP;
156 6 : } else if (curve == DIVE_CURVE) {
157 1 : return TremoloBarType::DIVE;
158 5 : } else if (curve == RELEASE_UP_CURVE) {
159 1 : return TremoloBarType::RELEASE_UP;
160 4 : } else if (curve == INVERTED_DIP_CURVE) {
161 1 : return TremoloBarType::INVERTED_DIP;
162 3 : } else if (curve == RETURN_CURVE) {
163 1 : return TremoloBarType::RETURN;
164 2 : } else if (curve == RELEASE_DOWN_CURVE) {
165 1 : return TremoloBarType::RELEASE_DOWN;
166 : }
167 :
168 1 : return TremoloBarType::CUSTOM;
169 : }
170 :
171 0 : void TremoloBar::updatePointsByTremoloBarType(const TremoloBarType type)
172 : {
173 0 : switch (type) {
174 0 : case TremoloBarType::DIP:
175 0 : m_points = DIP_CURVE;
176 0 : break;
177 0 : case TremoloBarType::DIVE:
178 0 : m_points = DIVE_CURVE;
179 0 : break;
180 0 : case TremoloBarType::RELEASE_UP:
181 0 : m_points = RELEASE_UP_CURVE;
182 0 : break;
183 0 : case TremoloBarType::INVERTED_DIP:
184 0 : m_points = INVERTED_DIP_CURVE;
185 0 : break;
186 0 : case TremoloBarType::RETURN:
187 0 : m_points = RETURN_CURVE;
188 0 : break;
189 0 : case TremoloBarType::RELEASE_DOWN:
190 0 : m_points = RELEASE_DOWN_CURVE;
191 0 : break;
192 0 : case TremoloBarType::CUSTOM:
193 0 : break;
194 : }
195 0 : }
196 : }
|