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 "tripletfeel.h"
24 :
25 : #include "types/string.h"
26 : #include "types/translatablestring.h"
27 :
28 : #include "score.h"
29 :
30 : namespace mu::engraving {
31 : static const ElementStyle tripletFeelStyle {
32 : { Sid::subTitleFontSize, Pid::FONT_SIZE }, // TODO: add styles
33 : { Sid::tempoFontStyle, Pid::FONT_STYLE }
34 : };
35 :
36 : static const std::map<TripletFeelType, String> tupletSymbols =
37 : {
38 : { TripletFeelType::TRIPLET_8TH, String(u"%1textBlackNoteShortStem%2"
39 : "%1textCont8thBeamShortStem%2"
40 : "%1textBlackNoteFrac8thShortStem%2"
41 : " = "
42 : "%1textBlackNoteShortStem%2"
43 : "%1textTupletBracketStartShortStem%2"
44 : "%1textTuplet3ShortStem%2"
45 : "%1note8thUp%2"
46 : "%1textTupletBracketEndShortStem%2") },
47 :
48 : { TripletFeelType::TRIPLET_16TH, String(u"%1textBlackNoteShortStem%2"
49 : "%1textCont16thBeamShortStem%2"
50 : "%1textBlackNoteFrac16thShortStem%2"
51 : " = "
52 : "%1textBlackNoteShortStem%2"
53 : "%1textTupletBracketStartShortStem%2"
54 : "%1textCont8thBeamShortStem%2"
55 : "%1textTuplet3ShortStem%2"
56 : "%1textBlackNoteFrac16thShortStem%2"
57 : "%1textTupletBracketEndShortStem%2") },
58 :
59 : { TripletFeelType::DOTTED_8TH, String(u"%1textBlackNoteShortStem%2"
60 : "%1textCont8thBeamShortStem%2"
61 : "%1textBlackNoteFrac8thShortStem%2"
62 : " = "
63 : "%1textBlackNoteShortStem%2"
64 : "%1textCont8thBeamShortStem%2"
65 : "%1textAugmentationDot%2"
66 : "%1textCont8thBeamShortStem%2"
67 : "%1textBlackNoteFrac16thShortStem%2") },
68 :
69 : { TripletFeelType::DOTTED_16TH, String(u"%1textBlackNoteShortStem%2"
70 : "%1textCont16thBeamShortStem%2"
71 : "%1textBlackNoteFrac16thShortStem%2"
72 : " = "
73 : "%1textBlackNoteLongStem%2"
74 : "%1textCont16thBeamLongStem%2"
75 : "%1textAugmentationDot%2"
76 : "%1textCont16thBeamLongStem%2"
77 : "%1textBlackNoteFrac32ndLongStem%2") },
78 :
79 : { TripletFeelType::SCOTTISH_8TH, String(u"%1textBlackNoteShortStem%2"
80 : "%1textCont8thBeamShortStem%2"
81 : "%1textBlackNoteFrac8thShortStem%2"
82 : " = "
83 : "%1textBlackNoteShortStem%2"
84 : "%1textCont16thBeamShortStem%2"
85 : "%1textBlackNoteFrac8thShortStem%2"
86 : "%1textAugmentationDot%2") },
87 :
88 : { TripletFeelType::SCOTTISH_16TH, String(u"%1textBlackNoteShortStem%2"
89 : "%1textCont16thBeamShortStem%2"
90 : "%1textBlackNoteFrac16thShortStem%2"
91 : " = "
92 : "%1textBlackNoteLongStem%2"
93 : "%1textCont32ndBeamLongStem%2"
94 : "%1textBlackNoteFrac16thLongStem%2"
95 : "%1textAugmentationDot%2") },
96 :
97 : { TripletFeelType::NONE, String(u"%1textBlackNoteShortStem%2"
98 : "%1textCont8thBeamShortStem%2"
99 : "%1textBlackNoteFrac8thShortStem%2"
100 : " = "
101 : "%1textBlackNoteShortStem%2"
102 : "%1textCont8thBeamShortStem%2"
103 : "%1textBlackNoteFrac8thShortStem%2") }
104 : };
105 :
106 : static const std::map<TripletFeelType, TranslatableString> tripletFeelNames =
107 : {
108 : { TripletFeelType::TRIPLET_8TH, TranslatableString("engraving/tripletfeel", "Triplet 8th") },
109 : { TripletFeelType::TRIPLET_16TH, TranslatableString("engraving/tripletfeel", "Triplet 16th") },
110 : { TripletFeelType::DOTTED_8TH, TranslatableString("engraving/tripletfeel", "Dotted 8th") },
111 : { TripletFeelType::DOTTED_16TH, TranslatableString("engraving/tripletfeel", "Dotted 16th") },
112 : { TripletFeelType::SCOTTISH_8TH, TranslatableString("engraving/tripletfeel", "Scottish 8th") },
113 : { TripletFeelType::SCOTTISH_16TH, TranslatableString("engraving/tripletfeel", "Scottish 16th") },
114 : { TripletFeelType::NONE, TranslatableString("engraving/tripletfeel", "No triplet feel") }
115 : };
116 :
117 0 : TripletFeel::TripletFeel(DummyParentOr<Segment> parent, TripletFeelType tripletFillType)
118 0 : : SystemText(parent, TextStyleType::SYSTEM, ElementType::TRIPLET_FEEL)
119 : {
120 0 : m_tripletFeelType = tripletFillType;
121 0 : setTripletProperty();
122 0 : initElementStyle(&tripletFeelStyle);
123 0 : }
124 :
125 0 : void TripletFeel::setTripletProperty()
126 : {
127 0 : setSwing(true);
128 :
129 0 : switch (m_tripletFeelType) {
130 0 : case TripletFeelType::TRIPLET_8TH:
131 0 : setSwingParameters(Constants::DIVISION / eightDivision, tripletRatio);
132 0 : break;
133 :
134 0 : case TripletFeelType::TRIPLET_16TH:
135 0 : setSwingParameters(Constants::DIVISION / sixteenthDivision, tripletRatio);
136 0 : break;
137 :
138 0 : case TripletFeelType::DOTTED_8TH:
139 0 : setSwingParameters(Constants::DIVISION / eightDivision, dottedRatio);
140 0 : break;
141 :
142 0 : case TripletFeelType::DOTTED_16TH:
143 0 : setSwingParameters(Constants::DIVISION / sixteenthDivision, dottedRatio);
144 0 : break;
145 :
146 0 : case TripletFeelType::SCOTTISH_8TH:
147 0 : setSwingParameters(Constants::DIVISION / eightDivision, scottishRatio);
148 0 : break;
149 :
150 0 : case TripletFeelType::SCOTTISH_16TH:
151 0 : setSwingParameters(Constants::DIVISION / sixteenthDivision, scottishRatio);
152 0 : break;
153 :
154 0 : case TripletFeelType::NONE:
155 0 : setSwingParameters(0, zeroRatio);
156 0 : break;
157 : }
158 :
159 0 : setXmlText(tupletSymbols.at(m_tripletFeelType).arg(String(u"<sym>staffPosLower3</sym><sym>"), String(u"</sym>")));
160 0 : }
161 :
162 : //---------------------------------------------------------
163 : // propertyDefault
164 : //---------------------------------------------------------
165 :
166 0 : PropertyValue TripletFeel::propertyDefault(Pid propertyId) const
167 : {
168 0 : switch (propertyId) {
169 0 : case Pid::FONT_SIZE:
170 0 : return style().styleV(Sid::subTitleFontSize);
171 :
172 0 : case Pid::FONT_STYLE:
173 0 : return style().styleV(Sid::tempoFontStyle);
174 :
175 0 : default:
176 0 : return SystemText::propertyDefault(propertyId);
177 : }
178 : }
179 :
180 : //---------------------------------------------------------
181 : // getPropertyStyle
182 : //---------------------------------------------------------
183 :
184 0 : Sid TripletFeel::getPropertyStyle(Pid id) const
185 : {
186 0 : switch (id) {
187 0 : case Pid::FONT_SIZE:
188 0 : return Sid::subTitleFontSize;
189 :
190 0 : case Pid::FONT_STYLE:
191 0 : return Sid::tempoFontStyle;
192 0 : default:
193 0 : break;
194 : }
195 :
196 0 : return SystemText::getPropertyStyle(id);
197 : }
198 :
199 : //---------------------------------------------------------
200 : // typeUserName
201 : //---------------------------------------------------------
202 :
203 0 : TranslatableString TripletFeel::subtypeUserName() const
204 : {
205 0 : return tripletFeelNames.at(m_tripletFeelType);
206 : }
207 :
208 : //---------------------------------------------------------
209 : // accessibleInfo
210 : //---------------------------------------------------------
211 :
212 0 : String TripletFeel::accessibleInfo() const
213 : {
214 0 : return String(u"%1: %2").arg(EngravingItem::accessibleInfo(), translatedTypeUserName());
215 : }
216 : }
|