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 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
|
//=============================================================================
// 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 {
//---------------------------------------------------------
// fermataStyle
//---------------------------------------------------------
static const ElementStyle fermataStyle {
{ Sid::fermataPosAbove, Pid::OFFSET },
{ Sid::fermataMinDistance, Pid::MIN_DISTANCE },
};
//---------------------------------------------------------
// Fermata
//---------------------------------------------------------
Fermata::Fermata(Score* s)
: Element(s, ElementFlag::MOVABLE | ElementFlag::ON_STAFF)
{
initElementStyle(&fermataStyle);
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(this);
xml.tag("subtype", Sym::id2name(_symId));
writeProperty(xml, Pid::TIME_STRETCH);
writeProperty(xml, Pid::PLAY);
if (!isStyled(Pid::OFFSET))
writeProperty(xml, Pid::OFFSET);
Element::writeProperties(xml);
xml.etag();
}
//---------------------------------------------------------
// subtype
//---------------------------------------------------------
int Fermata::subtype() const
{
QString s = Sym::id2name(_symId);
if (s.endsWith("Below"))
return int(Sym::name2id(s.left(s.size() - 5) + "Above"));
else
return int(_symId);
}
//---------------------------------------------------------
// 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();
setPos(QPointF());
if (!s) { // for use in palette
setOffset(0.0, 0.0);
QRectF b(symBbox(_symId));
setbbox(b.translated(-0.5 * b.width(), 0.0));
return;
}
if (isStyled(Pid::OFFSET))
setOffset(propertyDefault(Pid::OFFSET).toPointF());
Element* e = s->element(track());
if (e) {
if (e->isChord())
rxpos() += score()->noteHeadWidth() * staff()->mag(Fraction(0, 1)) * .5;
else
rxpos() += e->x() + e->width() * staff()->mag(Fraction(0, 1)) * .5;
}
QString name = Sym::id2name(_symId);
if (placeAbove()) {
if (name.endsWith("Below"))
_symId = Sym::name2id(name.left(name.size() - 5) + "Above");
}
else {
rypos() += staff()->height();
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();
}
//---------------------------------------------------------
// dragAnchor
//---------------------------------------------------------
QLineF Fermata::dragAnchor() const
{
return QLineF(canvasPos(), parent()->canvasPos());
}
//---------------------------------------------------------
// getProperty
//---------------------------------------------------------
QVariant Fermata::getProperty(Pid propertyId) const
{
switch (propertyId) {
case Pid::SYMBOL:
return QVariant::fromValue(_symId);
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::SYMBOL:
setSymId(v.value<SymId>());
break;
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(track() & 1 ? Placement::BELOW : Placement::ABOVE);
case Pid::TIME_STRETCH:
return 1.0; // articulationList[int(articulationType())].timeStretch;
case Pid::PLAY:
return true;
default:
break;
}
return Element::propertyDefault(propertyId);
}
//---------------------------------------------------------
// resetProperty
//---------------------------------------------------------
void Fermata::resetProperty(Pid id)
{
switch (id) {
case Pid::TIME_STRETCH:
setProperty(id, propertyDefault(id));
return;
default:
break;
}
Element::resetProperty(id);
}
//---------------------------------------------------------
// propertyId
//---------------------------------------------------------
Pid Fermata::propertyId(const QStringRef& xmlName) const
{
if (xmlName == "subtype")
return Pid::SYMBOL;
return Element::propertyId(xmlName);
}
//---------------------------------------------------------
// getPropertyStyle
//---------------------------------------------------------
Sid Fermata::getPropertyStyle(Pid pid) const
{
if (pid == Pid::OFFSET)
return placeAbove() ? Sid::fermataPosAbove : Sid::fermataPosBelow;
return ScoreElement::getPropertyStyle(pid);
}
//---------------------------------------------------------
// mag
//---------------------------------------------------------
qreal Fermata::mag() const
{
return staff() ? staff()->mag(tick()) * score()->styleD(Sid::articulationMag) : 1.0;
}
//---------------------------------------------------------
// accessibleInfo
//---------------------------------------------------------
QString Fermata::accessibleInfo() const
{
return QString("%1: %2").arg(Element::accessibleInfo()).arg(userName());
}
}
|