/
fermata.cpp
356 lines (306 loc) · 10.1 KB
/
fermata.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2018 Werner Schweer
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=============================================================================
#include "fermata.h"
#include "score.h"
#include "chordrest.h"
#include "system.h"
#include "measure.h"
#include "staff.h"
#include "stafftype.h"
#include "undo.h"
#include "page.h"
#include "barline.h"
#include "sym.h"
#include "xml.h"
namespace Ms {
//---------------------------------------------------------
// Fermata
//---------------------------------------------------------
Fermata::Fermata(Score* s)
: Element(s, ElementFlag::MOVABLE | ElementFlag::ON_STAFF)
{
setPlacement(Placement::ABOVE);
_symId = SymId::noSym;
_timeStretch = 1.0;
setPlay(true);
}
Fermata::Fermata(SymId id, Score* s)
: Fermata(s)
{
setSymId(id);
}
//---------------------------------------------------------
// read
//---------------------------------------------------------
void Fermata::read(XmlReader& e)
{
while (e.readNextStartElement()) {
if (!readProperties(e))
e.unknown();
}
}
//---------------------------------------------------------
// readProperties
//---------------------------------------------------------
bool Fermata::readProperties(XmlReader& e)
{
const QStringRef& tag(e.name());
if (tag == "subtype") {
QString s = e.readElementText();
SymId id = Sym::name2id(s);
setSymId(id);
}
else if ( tag == "play")
setPlay(e.readBool());
else if (tag == "timeStretch")
_timeStretch = e.readDouble();
else if (tag == "offset") {
if (score()->mscVersion() > 114)
Element::readProperties(e);
else
e.skipCurrentElement(); // ignore manual layout in older scores
}
else if (Element::readProperties(e))
;
else
return false;
return true;
}
//---------------------------------------------------------
// write
//---------------------------------------------------------
void Fermata::write(XmlWriter& xml) const
{
if (!xml.canWrite(this)) {
qDebug("%s not written", name());
return;
}
xml.stag("Fermata");
xml.tag("subtype", Sym::id2name(_symId));
writeProperty(xml, Pid::TIME_STRETCH);
writeProperty(xml, Pid::PLAY);
Element::writeProperties(xml);
xml.etag();
}
//---------------------------------------------------------
// userName
//---------------------------------------------------------
QString Fermata::userName() const
{
return Sym::id2userName(symId());
}
//---------------------------------------------------------
// Symbol::draw
//---------------------------------------------------------
void Fermata::draw(QPainter* painter) const
{
#if 0
SymId sym = symId();
FermataShowIn flags = articulationList[int(articulationType())].flags;
if (staff()) {
if (staff()->staffGroup() == StaffGroup::TAB) {
if (!(flags & FermataShowIn::TABLATURE))
return;
}
else {
if (!(flags & FermataShowIn::PITCHED_STAFF))
return;
}
}
#endif
painter->setPen(curColor());
drawSymbol(_symId, painter, QPointF(-0.5 * width(), 0.0));
}
//---------------------------------------------------------
// chordRest
//---------------------------------------------------------
ChordRest* Fermata::chordRest() const
{
if (parent() && parent()->isChordRest())
return toChordRest(parent());
return 0;
}
//---------------------------------------------------------
// measure
//---------------------------------------------------------
Measure* Fermata::measure() const
{
Segment* s = segment();
return toMeasure(s ? s->parent() : 0);
}
//---------------------------------------------------------
// system
//---------------------------------------------------------
System* Fermata::system() const
{
Measure* m = measure();
return toSystem(m ? m->parent() : 0);
}
//---------------------------------------------------------
// page
//---------------------------------------------------------
Page* Fermata::page() const
{
System* s = system();
return toPage(s ? s->parent() : 0);
}
//---------------------------------------------------------
// layout
// height() and width() should return sensible
// values when calling this method
//---------------------------------------------------------
void Fermata::layout()
{
Segment* s = segment();
if (!s) { // for use in palette
setPos(QPointF());
QRectF b(symBbox(_symId));
setbbox(b.translated(-0.5 * b.width(), 0.0));
return;
}
qreal x = 0.0;
Element* e = s->element(track());
if (e) {
if (e->isChord())
x = score()->noteHeadWidth() * staff()->mag(0) * .5;
else
x = e->x() + e->width() * staff()->mag(0) * .5;
}
qreal y = placeAbove() ? styleP(Sid::fermataPosAbove) : styleP(Sid::fermataPosBelow) + staff()->height();
setPos(QPointF(x, y));
// check used symbol
QString name = Sym::id2name(_symId);
if (placeAbove()) {
if (name.endsWith("Below"))
_symId = Sym::name2id(name.left(name.size() - 5) + "Above");
}
else {
if (name.endsWith("Above"))
_symId = Sym::name2id(name.left(name.size() - 5) + "Below");
}
QRectF b(symBbox(_symId));
setbbox(b.translated(-0.5 * b.width(), 0.0));
autoplaceSegmentElement(styleP(Sid::fermataMinDistance));
}
//---------------------------------------------------------
// reset
//---------------------------------------------------------
void Fermata::reset()
{
Element::reset();
}
//---------------------------------------------------------
// dragAnchor
//---------------------------------------------------------
QLineF Fermata::dragAnchor() const
{
return QLineF(canvasPos(), parent()->canvasPos());
}
//---------------------------------------------------------
// getProperty
//---------------------------------------------------------
QVariant Fermata::getProperty(Pid propertyId) const
{
switch (propertyId) {
case Pid::TIME_STRETCH:
return timeStretch();
case Pid::PLAY:
return play();
default:
return Element::getProperty(propertyId);
}
}
//---------------------------------------------------------
// setProperty
//---------------------------------------------------------
bool Fermata::setProperty(Pid propertyId, const QVariant& v)
{
switch (propertyId) {
case Pid::PLACEMENT: {
Placement p = Placement(v.toInt());
if (p != placement()) {
QString s = Sym::id2name(_symId);
bool up = placeAbove();
if (s.endsWith(up ? "Above" : "Below")) {
QString s2 = s.left(s.size() - 5) + (up ? "Below" : "Above");
_symId = Sym::name2id(s2);
}
setPlacement(p);
}
}
break;
case Pid::PLAY:
setPlay(v.toBool());
break;
case Pid::TIME_STRETCH:
setTimeStretch(v.toDouble());
score()->fixTicks();
break;
default:
return Element::setProperty(propertyId, v);
}
triggerLayout();
return true;
}
//---------------------------------------------------------
// propertyDefault
//---------------------------------------------------------
QVariant Fermata::propertyDefault(Pid propertyId) const
{
switch (propertyId) {
case Pid::PLACEMENT:
return int(Placement::ABOVE);
case Pid::TIME_STRETCH:
return 1.0; // articulationList[int(articulationType())].timeStretch;
case Pid::PLAY:
return true;
default:
break;
}
return Element::propertyDefault(propertyId);
}
//---------------------------------------------------------
// getPropertyStyle
//---------------------------------------------------------
Sid Fermata::getPropertyStyle(Pid /*id*/) const
{
return Sid::NOSTYLE;
}
//---------------------------------------------------------
// resetProperty
//---------------------------------------------------------
void Fermata::resetProperty(Pid id)
{
switch (id) {
case Pid::TIME_STRETCH:
setProperty(id, propertyDefault(id));
return;
default:
break;
}
Element::resetProperty(id);
}
//---------------------------------------------------------
// mag
//---------------------------------------------------------
qreal Fermata::mag() const
{
return parent() ? parent()->mag() * score()->styleD(Sid::articulationMag): 1.0;
}
//---------------------------------------------------------
// accessibleInfo
//---------------------------------------------------------
QString Fermata::accessibleInfo() const
{
return QString("%1: %2").arg(Element::accessibleInfo()).arg(userName());
}
}