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 "jump.h"
24 :
25 : #include "types/typesconv.h"
26 :
27 : #include "measure.h"
28 : #include "score.h"
29 :
30 : #include "log.h"
31 :
32 : using namespace mu;
33 : using namespace mu::engraving;
34 :
35 : namespace mu::engraving {
36 : //---------------------------------------------------------
37 : // jumpStyle
38 : //---------------------------------------------------------
39 :
40 : static const ElementStyle jumpStyle {
41 : { Sid::repeatRightPlacement, Pid::PLACEMENT },
42 : { Sid::repeatMinDistance, Pid::MIN_DISTANCE },
43 : };
44 :
45 : //---------------------------------------------------------
46 : // JumpTypeTable
47 : //---------------------------------------------------------
48 :
49 : const std::vector<JumpTypeTableItem> jumpTypeTable {
50 : { JumpType::DC, "D.C.", "start", "end", "" },
51 : { JumpType::DC_AL_FINE, "D.C. al Fine", "start", "fine", "" },
52 : { JumpType::DC_AL_CODA, "D.C. al Coda", "start", "coda", "codab" },
53 : { JumpType::DS_AL_CODA, "D.S. al Coda", "segno", "coda", "codab" },
54 : { JumpType::DS_AL_FINE, "D.S. al Fine", "segno", "fine", "" },
55 : { JumpType::DS, "D.S.", "segno", "end", "" },
56 :
57 : { JumpType::DC_AL_DBLCODA, "D.C. al Doppia Coda", "start", "varcoda", "codab" },
58 : { JumpType::DS_AL_DBLCODA, "D.S. al Doppia Coda", "segno", "varcoda", "codab" },
59 : { JumpType::DSS, "Dal Doppio Segno", "varsegno", "end", "" },
60 : { JumpType::DSS_AL_CODA, "D.D.S. al Coda", "varsegno", "coda", "codab" },
61 : { JumpType::DSS_AL_DBLCODA, "D.D.S. al Doppia Coda", "varsegno", "varcoda", "codab" },
62 : { JumpType::DSS_AL_FINE, "D.D.S. al Fine", "varsegno", "fine", "" },
63 : };
64 :
65 : //---------------------------------------------------------
66 : // Jump
67 : //---------------------------------------------------------
68 :
69 159 : Jump::Jump(DummyParentOr<Measure> parent)
70 159 : : TextBase(ElementType::JUMP, parent, TextStyleType::REPEAT_RIGHT, ElementFlag::MOVABLE | ElementFlag::SYSTEM | ElementFlag::ON_STAFF)
71 : {
72 159 : initElementStyle(&jumpStyle);
73 159 : m_playRepeats = false;
74 159 : }
75 :
76 : //---------------------------------------------------------
77 : // setJumpType
78 : //---------------------------------------------------------
79 :
80 57 : void Jump::setJumpType(JumpType t)
81 : {
82 323 : for (const JumpTypeTableItem& p : jumpTypeTable) {
83 323 : if (p.type == t) {
84 57 : setXmlText(String::fromAscii(p.text.ascii()));
85 57 : setJumpTo(String::fromAscii(p.jumpTo.ascii()));
86 57 : setPlayUntil(String::fromAscii(p.playUntil.ascii()));
87 57 : setContinueAt(String::fromAscii(p.continueAt.ascii()));
88 57 : initTextStyleType(TextStyleType::REPEAT_RIGHT);
89 57 : break;
90 : }
91 : }
92 57 : }
93 :
94 : //---------------------------------------------------------
95 : // jumpType
96 : //---------------------------------------------------------
97 :
98 61 : JumpType Jump::jumpType() const
99 : {
100 377 : for (const JumpTypeTableItem& t : jumpTypeTable) {
101 377 : if (m_jumpTo == t.jumpTo && m_playUntil == t.playUntil && m_continueAt == t.continueAt) {
102 61 : return t.type;
103 : }
104 : }
105 0 : return JumpType::USER;
106 : }
107 :
108 0 : String Jump::jumpTypeUserName() const
109 : {
110 0 : return TConv::translatedUserName(jumpType());
111 : }
112 :
113 : //---------------------------------------------------------
114 : // getProperty
115 : //---------------------------------------------------------
116 :
117 716 : PropertyValue Jump::getProperty(Pid propertyId) const
118 : {
119 716 : switch (propertyId) {
120 0 : case Pid::JUMP_TO:
121 0 : return jumpTo();
122 0 : case Pid::PLAY_UNTIL:
123 0 : return playUntil();
124 0 : case Pid::CONTINUE_AT:
125 0 : return continueAt();
126 71 : case Pid::PLAY_REPEATS:
127 71 : return playRepeats();
128 645 : default:
129 645 : break;
130 : }
131 645 : return TextBase::getProperty(propertyId);
132 : }
133 :
134 : //---------------------------------------------------------
135 : // setProperty
136 : //---------------------------------------------------------
137 :
138 5648 : bool Jump::setProperty(Pid propertyId, const PropertyValue& v)
139 : {
140 5648 : switch (propertyId) {
141 0 : case Pid::JUMP_TO:
142 0 : setJumpTo(v.value<String>());
143 0 : break;
144 0 : case Pid::PLAY_UNTIL:
145 0 : setPlayUntil(v.value<String>());
146 0 : break;
147 0 : case Pid::CONTINUE_AT:
148 0 : setContinueAt(v.value<String>());
149 0 : break;
150 0 : case Pid::PLAY_REPEATS:
151 0 : setPlayRepeats(v.toBool());
152 0 : break;
153 5648 : default:
154 5648 : if (!TextBase::setProperty(propertyId, v)) {
155 0 : return false;
156 : }
157 5648 : break;
158 : }
159 5648 : triggerLayout();
160 5648 : score()->invalidateRepeatList();
161 5648 : return true;
162 : }
163 :
164 : //---------------------------------------------------------
165 : // propertyDefault
166 : //---------------------------------------------------------
167 :
168 747 : PropertyValue Jump::propertyDefault(Pid propertyId) const
169 : {
170 747 : switch (propertyId) {
171 0 : case Pid::JUMP_TO:
172 : case Pid::PLAY_UNTIL:
173 : case Pid::CONTINUE_AT:
174 0 : return String();
175 71 : case Pid::PLAY_REPEATS:
176 71 : return false;
177 0 : case Pid::PLACEMENT:
178 0 : return PlacementV::ABOVE;
179 676 : default:
180 676 : break;
181 : }
182 676 : return TextBase::propertyDefault(propertyId);
183 : }
184 :
185 : //---------------------------------------------------------
186 : // nextSegmentElement
187 : //---------------------------------------------------------
188 :
189 0 : EngravingItem* Jump::nextSegmentElement()
190 : {
191 0 : Segment* seg = measure()->last();
192 0 : return seg->firstElementForNavigation(staffIdx());
193 : }
194 :
195 : //---------------------------------------------------------
196 : // prevSegmentElement
197 : //---------------------------------------------------------
198 :
199 0 : EngravingItem* Jump::prevSegmentElement()
200 : {
201 0 : return nextSegmentElement();
202 : }
203 :
204 : //---------------------------------------------------------
205 : // accessibleInfo
206 : //---------------------------------------------------------
207 :
208 0 : String Jump::accessibleInfo() const
209 : {
210 0 : return String(u"%1: %2").arg(EngravingItem::accessibleInfo(), this->jumpTypeUserName());
211 : }
212 :
213 : //---------------------------------------------------------
214 : // subtypeUserName
215 : //---------------------------------------------------------
216 :
217 0 : muse::TranslatableString Jump::subtypeUserName() const
218 : {
219 0 : return TConv::userName(jumpType());
220 : }
221 : }
|