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 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918
|
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2002-2011 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 "hairpin.h"
#include "style.h"
#include "xml.h"
#include "utils.h"
#include "score.h"
#include "measure.h"
#include "segment.h"
#include "system.h"
#include "undo.h"
#include "staff.h"
#include "mscore.h"
#include "chord.h"
namespace Ms {
//---------------------------------------------------------
// hairpinStyle
//---------------------------------------------------------
static const ElementStyle hairpinStyle {
{ Sid::hairpinFontFace, Pid::BEGIN_FONT_FACE },
{ Sid::hairpinFontSize, Pid::BEGIN_FONT_SIZE },
{ Sid::hairpinFontStyle, Pid::BEGIN_FONT_STYLE },
{ Sid::hairpinText, Pid::BEGIN_TEXT },
{ Sid::hairpinTextAlign, Pid::BEGIN_TEXT_ALIGN },
{ Sid::hairpinFontFace, Pid::CONTINUE_FONT_FACE },
{ Sid::hairpinFontSize, Pid::CONTINUE_FONT_SIZE },
{ Sid::hairpinFontStyle, Pid::CONTINUE_FONT_STYLE },
{ Sid::hairpinText, Pid::CONTINUE_TEXT },
{ Sid::hairpinTextAlign, Pid::CONTINUE_TEXT_ALIGN },
{ Sid::hairpinFontFace, Pid::END_FONT_FACE },
{ Sid::hairpinFontSize, Pid::END_FONT_SIZE },
{ Sid::hairpinFontStyle, Pid::END_FONT_STYLE },
{ Sid::hairpinTextAlign, Pid::END_TEXT_ALIGN },
{ Sid::hairpinLineWidth, Pid::LINE_WIDTH },
{ Sid::hairpinHeight, Pid::HAIRPIN_HEIGHT },
{ Sid::hairpinContHeight, Pid::HAIRPIN_CONT_HEIGHT },
{ Sid::hairpinPlacement, Pid::PLACEMENT },
{ Sid::hairpinPosBelow, Pid::OFFSET },
{ Sid::hairpinLineStyle, Pid::LINE_STYLE },
};
//---------------------------------------------------------
// changeMethodTable
//---------------------------------------------------------
const std::vector<Hairpin::VeloMethodItem> Hairpin::veloChangeMethodTable {
{ VeloChangeMethod::NORMAL, "normal" },
{ VeloChangeMethod::EASE_IN, "ease-in" },
{ VeloChangeMethod::EASE_OUT, "ease-out" },
{ VeloChangeMethod::EASE_IN_OUT, "ease-in-out" },
{ VeloChangeMethod::EXPONENTIAL, "exponential" },
};
//---------------------------------------------------------
// HairpinSegment
//---------------------------------------------------------
HairpinSegment::HairpinSegment(Spanner* sp, Score* s)
: TextLineBaseSegment(sp, s, ElementFlag::MOVABLE | ElementFlag::ON_STAFF)
{
}
bool HairpinSegment::acceptDrop(EditData& data) const
{
Element* e = data.dropElement;
if (e->isDynamic())
return true;
return false;
}
Element* HairpinSegment::drop(EditData& data)
{
Element* e = data.dropElement;
if (e->isDynamic()) {
Dynamic* d = toDynamic(e);
hairpin()->undoChangeProperty(Pid::END_TEXT, d->xmlText());
}
return 0;
}
//---------------------------------------------------------
// layout
//---------------------------------------------------------
void HairpinSegment::layout()
{
const qreal _spatium = spatium();
const int _trck = track();
Dynamic* sd = nullptr;
Dynamic* ed = nullptr;
qreal dymax = hairpin()->placeBelow() ? -10000.0 : 10000.0;
if (autoplace() && !score()->isPalette()) {
Segment* start = hairpin()->startSegment();
Segment* end = hairpin()->endSegment();
// Try to fit between adjacent dynamics
qreal minDynamicsDistance = score()->styleP(Sid::autoplaceHairpinDynamicsDistance) * staff()->mag(tick());
const System* sys = system();
if (isSingleType() || isBeginType()) {
if (start && start->system() == sys) {
sd = toDynamic(start->findAnnotation(ElementType::DYNAMIC, _trck, _trck));
if (!sd) {
// Dynamics might have been added to the previous
// segment rather than exactly to hairpin start,
// search in that segment too.
start = start->prev(SegmentType::ChordRest);
if (start && start->system() == sys)
sd = toDynamic(start->findAnnotation(ElementType::DYNAMIC, _trck, _trck));
}
}
if (sd && sd->addToSkyline() && sd->placement() == hairpin()->placement()) {
const qreal sdRight = sd->bbox().right() + sd->pos().x()
+ sd->segment()->pos().x() + sd->measure()->pos().x();
const qreal dist = qMax(sdRight - pos().x() + minDynamicsDistance, 0.0);
rxpos() += dist;
rxpos2() -= dist;
// prepare to align vertically
dymax = sd->pos().y();
}
}
if (isSingleType() || isEndType()) {
if (end && end->tick() < sys->endTick() && start != end) {
// checking ticks rather than systems
// systems may be unknown at layout stage.
ed = toDynamic(end->findAnnotation(ElementType::DYNAMIC, _trck, _trck));
}
if (ed && ed->addToSkyline() && ed->placement() == hairpin()->placement()) {
const qreal edLeft = ed->bbox().left() + ed->pos().x()
+ ed->segment()->pos().x() + ed->measure()->pos().x();
const qreal dist = edLeft - pos2().x() - pos().x() - minDynamicsDistance;
const qreal extendThreshold = 3.0 * _spatium; // TODO: style setting
if (dist < 0.0)
rxpos2() += dist; // always shorten
else if (dist >= extendThreshold && hairpin()->endText().isEmpty() && minDynamicsDistance > 0.0)
rxpos2() += dist; // lengthen only if appropriate
// prepare to align vertically
if (hairpin()->placeBelow())
dymax = qMax(dymax, ed->pos().y());
else
dymax = qMin(dymax, ed->pos().y());
}
}
}
HairpinType type = hairpin()->hairpinType();
if (hairpin()->isLineType()) {
twoLines = false;
TextLineBaseSegment::layout();
drawCircledTip = false;
circledTipRadius = 0.0;
}
else {
twoLines = true;
hairpin()->setBeginTextAlign(Align::LEFT | Align::VCENTER);
hairpin()->setEndTextAlign(Align::RIGHT | Align::VCENTER);
qreal x1 = 0.0;
TextLineBaseSegment::layout();
if (!_text->empty())
x1 = _text->width() + _spatium * .5;
QTransform t;
qreal h1 = hairpin()->hairpinHeight().val() * _spatium * .5;
qreal h2 = hairpin()->hairpinContHeight().val() * _spatium * .5;
qreal x = pos2().x();
if (!_endText->empty())
x -= (_endText->width() + _spatium * .5); // 0.5 spatium distance
if (x < _spatium) // minimum size of hairpin
x = _spatium;
qreal y = pos2().y();
qreal len = sqrt(x * x + y * y);
t.rotateRadians(asin(y/len));
drawCircledTip = hairpin()->hairpinCircledTip();
circledTipRadius = drawCircledTip ? 0.6 * _spatium * .5 : 0.0;
QLine l1, l2;
switch (type) {
case HairpinType::CRESC_HAIRPIN: {
switch (spannerSegmentType()) {
case SpannerSegmentType::SINGLE:
case SpannerSegmentType::BEGIN:
l1.setLine(x1 + circledTipRadius * 2.0, 0.0, len, h1);
l2.setLine(x1 + circledTipRadius * 2.0, 0.0, len, -h1);
circledTip.setX(x1 + circledTipRadius );
circledTip.setY(0.0);
break;
case SpannerSegmentType::MIDDLE:
case SpannerSegmentType::END:
drawCircledTip = false;
l1.setLine(x1, h2, len, h1);
l2.setLine(x1, -h2, len, -h1);
break;
}
}
break;
case HairpinType::DECRESC_HAIRPIN: {
switch (spannerSegmentType()) {
case SpannerSegmentType::SINGLE:
case SpannerSegmentType::END:
l1.setLine(x1, h1, len - circledTipRadius * 2, 0.0);
l2.setLine(x1, -h1, len - circledTipRadius * 2, 0.0);
circledTip.setX(len - circledTipRadius);
circledTip.setY(0.0);
break;
case SpannerSegmentType::BEGIN:
case SpannerSegmentType::MIDDLE:
drawCircledTip = false;
l1.setLine(x1, h1, len, + h2);
l2.setLine(x1, -h1, len, - h2);
break;
}
}
break;
default:
break;
}
// Do Coord rotation
l1 = t.map(l1);
l2 = t.map(l2);
if (drawCircledTip )
circledTip = t.map(circledTip);
points[0] = l1.p1();
points[1] = l1.p2();
points[2] = l2.p1();
points[3] = l2.p2();
npoints = 4;
QRectF r = QRectF(l1.p1(), l1.p2()).normalized() | QRectF(l2.p1(), l2.p2()).normalized();
if (!_text->empty())
r |= _text->bbox();
if (!_endText->empty())
r |= _endText->bbox().translated(x + _endText->bbox().width(), 0.0);
qreal w = point(score()->styleS(Sid::hairpinLineWidth));
setbbox(r.adjusted(-w*.5, -w*.5, w, w));
}
if (!parent()) {
rpos() = QPointF();
roffset() = QPointF();
return;
}
if (isStyled(Pid::OFFSET))
roffset() = hairpin()->propertyDefault(Pid::OFFSET).toPointF();
// rebase vertical offset on drag
qreal rebase = 0.0;
if (offsetChanged() != OffsetChange::NONE)
rebase = rebaseOffset();
if (autoplace()) {
qreal ymax = pos().y();
qreal d;
qreal ddiff = hairpin()->isLineType() ? 0.0 : _spatium * 0.5;
qreal sp = spatium();
qreal md = minDistance().val() * sp;
bool above = spanner()->placeAbove();
SkylineLine sl(!above);
Shape sh = shape();
sl.add(sh.translated(pos()));
if (above) {
d = system()->topDistance(staffIdx(), sl);
if (d > -md)
ymax -= d + md;
// align hairpin with dynamics
if (!hairpin()->diagonal())
ymax = qMin(ymax, dymax - ddiff);
}
else {
d = system()->bottomDistance(staffIdx(), sl);
if (d > -md)
ymax += d + md;
// align hairpin with dynamics
if (!hairpin()->diagonal())
ymax = qMax(ymax, dymax - ddiff);
}
qreal yd = ymax - pos().y();
if (yd != 0.0) {
if (offsetChanged() != OffsetChange::NONE) {
// user moved element within the skyline
// we may need to adjust minDistance, yd, and/or offset
qreal adj = pos().y() + rebase;
bool inStaff = above ? sh.bottom() + adj > 0.0 : sh.top() + adj < staff()->height();
rebaseMinDistance(md, yd, sp, rebase, above, inStaff);
}
rypos() += yd;
}
if (hairpin()->addToSkyline() && !hairpin()->diagonal()) {
// align dynamics with hairpin
if (sd && sd->autoplace() && sd->placement() == hairpin()->placement()) {
qreal ny = y() + ddiff - sd->offset().y();
if (sd->placeAbove())
ny = qMin(ny, sd->ipos().y());
else
ny = qMax(ny, sd->ipos().y());
if (sd->ipos().y() != ny) {
sd->rypos() = ny;
if (sd->addToSkyline()) {
Segment* s = sd->segment();
Measure* m = s->measure();
QRectF r = sd->bbox().translated(sd->pos());
s->staffShape(sd->staffIdx()).add(r);
r = sd->bbox().translated(sd->pos() + s->pos() + m->pos());
m->system()->staff(sd->staffIdx())->skyline().add(r);
}
}
}
if (ed && ed->autoplace() && ed->placement() == hairpin()->placement()) {
qreal ny = y() + ddiff - ed->offset().y();
if (ed->placeAbove())
ny = qMin(ny, ed->ipos().y());
else
ny = qMax(ny, ed->ipos().y());
if (ed->ipos().y() != ny) {
ed->rypos() = ny;
if (ed->addToSkyline()) {
Segment* s = ed->segment();
Measure* m = s->measure();
QRectF r = ed->bbox().translated(ed->pos());
s->staffShape(ed->staffIdx()).add(r);
r = ed->bbox().translated(ed->pos() + s->pos() + m->pos());
m->system()->staff(ed->staffIdx())->skyline().add(r);
}
}
}
}
}
setOffsetChanged(false);
}
//---------------------------------------------------------
// shape
//---------------------------------------------------------
Shape HairpinSegment::shape() const
{
switch (hairpin()->hairpinType()) {
case HairpinType::CRESC_HAIRPIN:
case HairpinType::DECRESC_HAIRPIN:
return Shape(bbox());
case HairpinType::DECRESC_LINE:
case HairpinType::CRESC_LINE:
default:
return TextLineBaseSegment::shape();
}
}
//---------------------------------------------------------
// updateGrips
//---------------------------------------------------------
void HairpinSegment::updateGrips(EditData& ed) const
{
qreal _spatium = spatium();
qreal x = pos2().x();
if (x < _spatium) // minimum size of hairpin
x = _spatium;
qreal y = pos2().y();
QPointF p(x, y);
// Calc QPointF for Grip Aperture
QTransform doRotation;
QPointF gripLineAperturePoint;
qreal h1 = hairpin()->hairpinHeight().val() * spatium() * .5;
qreal len = sqrt( x * x + y * y );
doRotation.rotateRadians(asin(y/len));
qreal lineApertureX;
qreal offsetX = 10; // Horizontal offset for x Grip
if (len < offsetX * 3) // For small hairpin, offset = 30% of len
offsetX = len/3; // else offset is fixed to 10
if (hairpin()->hairpinType() == HairpinType::CRESC_HAIRPIN)
lineApertureX = len - offsetX; // End of CRESCENDO - Offset
else
lineApertureX = offsetX; // Begin of DECRESCENDO + Offset
qreal lineApertureH = ( len - offsetX ) * h1/len; // Vertical position for y grip
gripLineAperturePoint.setX( lineApertureX );
gripLineAperturePoint.setY( lineApertureH );
gripLineAperturePoint = doRotation.map(gripLineAperturePoint);
// End calc position grip aperture
QPointF pp(pagePos());
ed.grip[int(Grip::START)].translate(pp);
ed.grip[int(Grip::END)].translate(p + pp);
ed.grip[int(Grip::MIDDLE)].translate(p * .5 + pp);
ed.grip[int(Grip::APERTURE)].translate(gripLineAperturePoint + pp);
}
//---------------------------------------------------------
// startEdit
//---------------------------------------------------------
void HairpinSegment::startEdit(EditData& ed)
{
ed.grips = 4;
ed.curGrip = Grip::END;
Element::startEdit(ed);
}
//---------------------------------------------------------
// startEditDrag
//---------------------------------------------------------
void HairpinSegment::startEditDrag(EditData& ed)
{
TextLineBaseSegment::startEditDrag(ed);
ElementEditData* eed = ed.getData(this);
eed->pushProperty(Pid::HAIRPIN_HEIGHT);
eed->pushProperty(Pid::HAIRPIN_CONT_HEIGHT);
}
//---------------------------------------------------------
// editDrag
//---------------------------------------------------------
void HairpinSegment::editDrag(EditData& ed)
{
if (ed.curGrip == Grip::APERTURE) {
qreal newHeight = hairpin()->hairpinHeight().val() + ed.delta.y()/spatium()/.5;
if (newHeight < 0.5)
newHeight = 0.5;
hairpin()->setHairpinHeight(Spatium(newHeight));
triggerLayout();
}
TextLineBaseSegment::editDrag(ed);
}
//---------------------------------------------------------
// draw
//---------------------------------------------------------
void HairpinSegment::draw(QPainter* painter) const
{
TextLineBaseSegment::draw(painter);
#if 0
QColor color;
if ((selected() && !(score() && score()->printing())) || !hairpin()->visible())
color = curColor();
else
color = hairpin()->lineColor();
#endif
QColor color = curColor(hairpin()->visible(), hairpin()->lineColor());
qreal w = hairpin()->lineWidth();
if (staff())
w *= staff()->mag(hairpin()->tick());
QPen pen(color, w, hairpin()->lineStyle());
painter->setPen(pen);
if (drawCircledTip) {
painter->setBrush(Qt::NoBrush);
painter->drawEllipse( circledTip,circledTipRadius,circledTipRadius );
}
}
//---------------------------------------------------------
// propertyDelegate
//---------------------------------------------------------
Element* HairpinSegment::propertyDelegate(Pid pid)
{
if (pid == Pid::HAIRPIN_TYPE
|| pid == Pid::VELO_CHANGE
|| pid == Pid::VELO_CHANGE_METHOD
|| pid == Pid::SINGLE_NOTE_DYNAMICS
|| pid == Pid::HAIRPIN_CIRCLEDTIP
|| pid == Pid::HAIRPIN_HEIGHT
|| pid == Pid::HAIRPIN_CONT_HEIGHT
|| pid == Pid::DYNAMIC_RANGE
|| pid == Pid::LINE_STYLE
)
return spanner();
return TextLineBaseSegment::propertyDelegate(pid);
}
//---------------------------------------------------------
// getPropertyStyle
//---------------------------------------------------------
Sid HairpinSegment::getPropertyStyle(Pid pid) const
{
switch (pid) {
case Pid::OFFSET:
if (hairpin()->isLineType())
return spanner()->placeAbove() ? Sid::hairpinLinePosAbove : Sid::hairpinLinePosBelow;
return spanner()->placeAbove() ? Sid::hairpinPosAbove : Sid::hairpinPosBelow;
case Pid::BEGIN_TEXT:
switch (hairpin()->hairpinType()) {
default:
return Sid::hairpinText;
case HairpinType::CRESC_LINE:
return Sid::hairpinCrescText;
case HairpinType::DECRESC_LINE:
return Sid::hairpinDecrescText;
}
break;
case Pid::CONTINUE_TEXT:
switch (hairpin()->hairpinType()) {
default:
return Sid::hairpinText;
case HairpinType::CRESC_LINE:
return Sid::hairpinCrescContText;
case HairpinType::DECRESC_LINE:
return Sid::hairpinDecrescContText;
}
break;
case Pid::LINE_STYLE:
return hairpin()->isLineType() ? Sid::hairpinLineLineStyle : Sid::hairpinLineStyle;
default:
break;
}
return TextLineBaseSegment::getPropertyStyle(pid);
}
Sid Hairpin::getPropertyStyle(Pid pid) const
{
switch (pid) {
case Pid::OFFSET:
if (isLineType())
return placeAbove() ? Sid::hairpinLinePosAbove : Sid::hairpinLinePosBelow;
return placeAbove() ? Sid::hairpinPosAbove : Sid::hairpinPosBelow;
case Pid::BEGIN_TEXT:
switch (hairpinType()) {
default:
return Sid::hairpinText;
case HairpinType::CRESC_LINE:
return Sid::hairpinCrescText;
case HairpinType::DECRESC_LINE:
return Sid::hairpinDecrescText;
}
break;
case Pid::CONTINUE_TEXT:
switch (hairpinType()) {
default:
return Sid::hairpinText;
case HairpinType::CRESC_LINE:
return Sid::hairpinCrescContText;
case HairpinType::DECRESC_LINE:
return Sid::hairpinDecrescContText;
}
break;
case Pid::LINE_STYLE:
return isLineType() ? Sid::hairpinLineLineStyle : Sid::hairpinLineStyle;
default:
break;
}
return TextLineBase::getPropertyStyle(pid);
}
//---------------------------------------------------------
// Hairpin
//---------------------------------------------------------
Hairpin::Hairpin(Score* s)
: TextLineBase(s)
{
initElementStyle(&hairpinStyle);
resetProperty(Pid::BEGIN_TEXT_PLACE);
resetProperty(Pid::CONTINUE_TEXT_PLACE);
resetProperty(Pid::HAIRPIN_TYPE);
resetProperty(Pid::LINE_VISIBLE);
_hairpinCircledTip = false;
_veloChange = 0;
_dynRange = Dynamic::Range::PART;
_singleNoteDynamics = true;
_veloChangeMethod = VeloChangeMethod::NORMAL;
}
//---------------------------------------------------------
// setHairpinType
//---------------------------------------------------------
void Hairpin::setHairpinType(HairpinType val)
{
if (_hairpinType == val)
return;
_hairpinType = val;
#if 0
switch (_hairpinType) {
case HairpinType::CRESC_HAIRPIN:
case HairpinType::DECRESC_HAIRPIN:
setBeginText("");
setContinueText("");
setLineStyle(Qt::SolidLine);
break;
case HairpinType::CRESC_LINE:
setBeginText("cresc.");
setContinueText("(cresc.)");
setLineStyle(Qt::CustomDashLine);
break;
case HairpinType::DECRESC_LINE:
setBeginText("dim.");
setContinueText("(dim.)");
setLineStyle(Qt::CustomDashLine);
break;
case HairpinType::INVALID:
break;
};
#endif
styleChanged();
}
//---------------------------------------------------------
// layout
// compute segments from tick() to _tick2
//---------------------------------------------------------
void Hairpin::layout()
{
setPos(0.0, 0.0);
TextLineBase::layout();
}
//---------------------------------------------------------
// createLineSegment
//---------------------------------------------------------
static const ElementStyle hairpinSegmentStyle {
{ Sid::hairpinPosBelow, Pid::OFFSET },
{ Sid::hairpinMinDistance, Pid::MIN_DISTANCE },
};
LineSegment* Hairpin::createLineSegment()
{
HairpinSegment* h = new HairpinSegment(this, score());
h->setTrack(track());
h->initElementStyle(&hairpinSegmentStyle);
return h;
}
//---------------------------------------------------------
// veloChangeMethodToName
//---------------------------------------------------------
QString Hairpin::veloChangeMethodToName(VeloChangeMethod method)
{
for (auto i : Hairpin::veloChangeMethodTable) {
if (i.method == method)
return i.name;
}
qFatal("Unrecognised velo change method!");
return "none"; // silence a compiler warning
}
//---------------------------------------------------------
// nameToVeloChangeMethod
//---------------------------------------------------------
VeloChangeMethod Hairpin::nameToVeloChangeMethod(QString name)
{
for (auto i : Hairpin::veloChangeMethodTable) {
if (i.name == name)
return i.method;
}
return VeloChangeMethod::NORMAL; // default
}
//---------------------------------------------------------
// write
//---------------------------------------------------------
void Hairpin::write(XmlWriter& xml) const
{
if (!xml.canWrite(this))
return;
xml.stag(this);
xml.tag("subtype", int(_hairpinType));
writeProperty(xml, Pid::VELO_CHANGE);
writeProperty(xml, Pid::HAIRPIN_CIRCLEDTIP);
writeProperty(xml, Pid::DYNAMIC_RANGE);
// writeProperty(xml, Pid::BEGIN_TEXT);
writeProperty(xml, Pid::END_TEXT);
// writeProperty(xml, Pid::CONTINUE_TEXT);
writeProperty(xml, Pid::LINE_VISIBLE);
writeProperty(xml, Pid::SINGLE_NOTE_DYNAMICS);
writeProperty(xml, Pid::VELO_CHANGE_METHOD);
for (const StyledProperty& spp : *styledProperties()) {
if (!isStyled(spp.pid))
writeProperty(xml, spp.pid);
}
SLine::writeProperties(xml);
xml.etag();
}
//---------------------------------------------------------
// read
//---------------------------------------------------------
void Hairpin::read(XmlReader& e)
{
eraseSpannerSegments();
while (e.readNextStartElement()) {
const QStringRef& tag(e.name());
if (tag == "subtype")
setHairpinType(HairpinType(e.readInt()));
else if (readStyledProperty(e, tag))
;
else if (tag == "hairpinCircledTip")
_hairpinCircledTip = e.readInt();
else if (tag == "veloChange")
_veloChange = e.readInt();
else if (tag == "dynType")
_dynRange = Dynamic::Range(e.readInt());
else if (tag == "useTextLine") { // obsolete
e.readInt();
if (hairpinType() == HairpinType::CRESC_HAIRPIN)
setHairpinType(HairpinType::CRESC_LINE);
else if (hairpinType() == HairpinType::DECRESC_HAIRPIN)
setHairpinType(HairpinType::DECRESC_LINE);
}
else if (tag == "singleNoteDynamics")
_singleNoteDynamics = e.readBool();
else if (tag == "veloChangeMethod")
_veloChangeMethod = nameToVeloChangeMethod(e.readElementText());
else if (!TextLineBase::readProperties(e))
e.unknown();
}
styleChanged();
}
//---------------------------------------------------------
// getProperty
//---------------------------------------------------------
QVariant Hairpin::getProperty(Pid id) const
{
switch (id) {
case Pid::HAIRPIN_CIRCLEDTIP:
return _hairpinCircledTip;
case Pid::HAIRPIN_TYPE:
return int(_hairpinType);
case Pid::VELO_CHANGE:
return _veloChange;
case Pid::DYNAMIC_RANGE:
return int(_dynRange);
case Pid::HAIRPIN_HEIGHT:
return _hairpinHeight;
case Pid::HAIRPIN_CONT_HEIGHT:
return _hairpinContHeight;
case Pid::SINGLE_NOTE_DYNAMICS:
return _singleNoteDynamics;
case Pid::VELO_CHANGE_METHOD:
return int(_veloChangeMethod);
default:
return TextLineBase::getProperty(id);
}
}
//---------------------------------------------------------
// setProperty
//---------------------------------------------------------
bool Hairpin::setProperty(Pid id, const QVariant& v)
{
switch (id) {
case Pid::HAIRPIN_CIRCLEDTIP:
_hairpinCircledTip = v.toBool();
break;
case Pid::HAIRPIN_TYPE:
setHairpinType(HairpinType(v.toInt()));
break;
case Pid::VELO_CHANGE:
_veloChange = v.toInt();
break;
case Pid::DYNAMIC_RANGE:
_dynRange = Dynamic::Range(v.toInt());
break;
case Pid::HAIRPIN_HEIGHT:
_hairpinHeight = v.value<Spatium>();
break;
case Pid::HAIRPIN_CONT_HEIGHT:
_hairpinContHeight = v.value<Spatium>();
break;
case Pid::SINGLE_NOTE_DYNAMICS:
_singleNoteDynamics = v.toBool();
break;
case Pid::VELO_CHANGE_METHOD:
_veloChangeMethod = VeloChangeMethod(v.toInt());
break;
default:
return TextLineBase::setProperty(id, v);
}
triggerLayout();
return true;
}
//---------------------------------------------------------
// propertyDefault
//---------------------------------------------------------
QVariant Hairpin::propertyDefault(Pid id) const
{
switch (id) {
case Pid::HAIRPIN_CIRCLEDTIP:
return false;
case Pid::VELO_CHANGE:
return 0;
case Pid::DYNAMIC_RANGE:
return int(Dynamic::Range::PART);
case Pid::LINE_STYLE:
if (isLineType())
return int(Qt::CustomDashLine);
return int(Qt::SolidLine);
case Pid::BEGIN_TEXT:
if (_hairpinType == HairpinType::CRESC_LINE)
return QString("cresc.");
if (_hairpinType == HairpinType::DECRESC_LINE)
return QString("dim.");
return QString();
case Pid::CONTINUE_TEXT:
case Pid::END_TEXT:
if (_hairpinType == HairpinType::CRESC_LINE)
return QString("(cresc.)");
if (_hairpinType == HairpinType::DECRESC_LINE)
return QString("(dim.)");
return QString("");
case Pid::BEGIN_TEXT_PLACE:
case Pid::CONTINUE_TEXT_PLACE:
return int(PlaceText::LEFT);
case Pid::BEGIN_TEXT_OFFSET:
case Pid::CONTINUE_TEXT_OFFSET:
case Pid::END_TEXT_OFFSET:
return QPointF();
case Pid::BEGIN_HOOK_TYPE:
case Pid::END_HOOK_TYPE:
return int(HookType::NONE);
case Pid::BEGIN_HOOK_HEIGHT:
case Pid::END_HOOK_HEIGHT:
return Spatium(0.0);
case Pid::LINE_VISIBLE:
return true;
case Pid::HAIRPIN_TYPE:
return int(HairpinType::CRESC_HAIRPIN);
case Pid::SINGLE_NOTE_DYNAMICS:
return true;
case Pid::VELO_CHANGE_METHOD:
return int(VeloChangeMethod::NORMAL);
case Pid::PLACEMENT:
return score()->styleV(Sid::hairpinPlacement);
default:
return TextLineBase::propertyDefault(id);
}
}
//---------------------------------------------------------
// Hairpin::propertyId
//---------------------------------------------------------
Pid Hairpin::propertyId(const QStringRef& name) const
{
if (name == "subtype")
return Pid::HAIRPIN_TYPE;
return TextLineBase::propertyId(name);
}
//---------------------------------------------------------
// accessibleInfo
//---------------------------------------------------------
QString Hairpin::accessibleInfo() const
{
QString rez = TextLineBase::accessibleInfo();
switch (hairpinType()) {
case HairpinType::CRESC_HAIRPIN:
rez += ": " + QObject::tr("Crescendo");
break;
case HairpinType::DECRESC_HAIRPIN:
rez += ": " + QObject::tr("Decrescendo");
break;
default:
rez += ": " + QObject::tr("Custom");
}
return rez;
}
}
|