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 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717
|
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2008-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 "harmony.h"
#include "pitchspelling.h"
#include "score.h"
#include "system.h"
#include "measure.h"
#include "segment.h"
#include "chordlist.h"
#include "mscore.h"
#include "fret.h"
#include "staff.h"
#include "part.h"
#include "utils.h"
#include "sym.h"
#include "xml.h"
namespace Ms {
//---------------------------------------------------------
// harmonyName
//---------------------------------------------------------
QString Harmony::harmonyName() const
{
// Hack:
const_cast<Harmony*>(this)->determineRootBaseSpelling();
HChord hc = descr() ? descr()->chord : HChord();
QString s, r, e, b;
if (_leftParen)
s = "(";
if (_rootTpc != Tpc::TPC_INVALID)
r = tpc2name(_rootTpc, _rootSpelling, _rootCase);
if (_textName != "") {
e = _textName;
e.remove('=');
}
else if (!_degreeList.empty()) {
hc.add(_degreeList);
// try to find the chord in chordList
const ChordDescription* newExtension = 0;
const ChordList* cl = score()->style().chordList();
for (const ChordDescription& cd : *cl) {
if (cd.chord == hc && !cd.names.empty()) {
newExtension = &cd;
break;
}
}
// now determine the chord name
if (newExtension)
e = newExtension->names.front();
else {
// not in table, fallback to using HChord.name()
r = hc.name(_rootTpc);
e = "";
}
}
if (_baseTpc != Tpc::TPC_INVALID)
b = "/" + tpc2name(_baseTpc, _baseSpelling, _baseCase);
s += r + e + b;
if (_rightParen)
s += ")";
return s;
}
//---------------------------------------------------------
// rootName
//---------------------------------------------------------
QString Harmony::rootName()
{
determineRootBaseSpelling();
return tpc2name(_rootTpc, _rootSpelling, _rootCase);
}
//---------------------------------------------------------
// baseName
//---------------------------------------------------------
QString Harmony::baseName()
{
determineRootBaseSpelling();
return tpc2name(_baseTpc, _baseSpelling, _baseCase);
}
//---------------------------------------------------------
// resolveDegreeList
// try to detect chord number and to eliminate degree
// list
//---------------------------------------------------------
void Harmony::resolveDegreeList()
{
if (_degreeList.empty())
return;
HChord hc = descr() ? descr()->chord : HChord();
hc.add(_degreeList);
// qDebug("resolveDegreeList: <%s> <%s-%s>: ", _descr->name, _descr->xmlKind, _descr->xmlDegrees);
// hc.print();
// _descr->chord.print();
// try to find the chord in chordList
const ChordList* cl = score()->style().chordList();
foreach(const ChordDescription& cd, *cl) {
if ((cd.chord == hc) && !cd.names.empty()) {
qDebug("ResolveDegreeList: found in table as %s", qPrintable(cd.names.front()));
_id = cd.id;
_degreeList.clear();
return;
}
}
qDebug("ResolveDegreeList: not found in table");
}
//---------------------------------------------------------
// chordSymbolStyle
//---------------------------------------------------------
const ElementStyle chordSymbolStyle {
{ Sid::harmonyPlacement, Pid::PLACEMENT },
{ Sid::minHarmonyDistance, Pid::MIN_DISTANCE },
};
//---------------------------------------------------------
// Harmony
//---------------------------------------------------------
Harmony::Harmony(Score* s)
: TextBase(s, Tid::HARMONY_A, ElementFlag::MOVABLE | ElementFlag::ON_STAFF)
{
_rootTpc = Tpc::TPC_INVALID;
_baseTpc = Tpc::TPC_INVALID;
_rootCase = NoteCaseType::CAPITAL;
_baseCase = NoteCaseType::CAPITAL;
_id = -1;
_parsedForm = 0;
_leftParen = false;
_rightParen = false;
initElementStyle(&chordSymbolStyle);
}
Harmony::Harmony(const Harmony& h)
: TextBase(h)
{
_rootTpc = h._rootTpc;
_baseTpc = h._baseTpc;
_rootCase = h._rootCase;
_baseCase = h._baseCase;
_id = h._id;
_leftParen = h._leftParen;
_rightParen = h._rightParen;
_degreeList = h._degreeList;
_parsedForm = h._parsedForm ? new ParsedChord(*h._parsedForm) : 0;
_textName = h._textName;
_userName = h._userName;
for (const TextSegment* s : h.textList) {
TextSegment* ns = new TextSegment();
ns->set(s->text, s->font, s->x, s->y);
textList.append(ns);
}
}
//---------------------------------------------------------
// ~Harmony
//---------------------------------------------------------
Harmony::~Harmony()
{
foreach(const TextSegment* ts, textList)
delete ts;
if (_parsedForm)
delete _parsedForm;
}
//---------------------------------------------------------
// write
//---------------------------------------------------------
void Harmony::write(XmlWriter& xml) const
{
if (!xml.canWrite(this))
return;
xml.stag(this);
if (_leftParen)
xml.tagE("leftParen");
if (_rootTpc != Tpc::TPC_INVALID || _baseTpc != Tpc::TPC_INVALID) {
int rRootTpc = _rootTpc;
int rBaseTpc = _baseTpc;
if (staff()) {
// parent can be a fret diagram
Segment* segment = parent()->isSegment() ? toSegment(parent()) : toSegment(parent()->parent());
Fraction tick = segment ? segment->tick() : Fraction(-1,1);
const Interval& interval = part()->instrument(tick)->transpose();
if (xml.clipboardmode() && !score()->styleB(Sid::concertPitch) && interval.chromatic) {
rRootTpc = transposeTpc(_rootTpc, interval, true);
rBaseTpc = transposeTpc(_baseTpc, interval, true);
}
}
if (rRootTpc != Tpc::TPC_INVALID) {
xml.tag("root", rRootTpc);
if (_rootCase != NoteCaseType::CAPITAL)
xml.tag("rootCase", static_cast<int>(_rootCase));
}
if (_id > 0)
xml.tag("extension", _id);
// parser uses leading "=" as a hidden specifier for minor
// this may or may not currently be incorporated into _textName
QString writeName = _textName;
if (_parsedForm && _parsedForm->name().startsWith("=") && !writeName.startsWith("="))
writeName = "=" + writeName;
if (!writeName.isEmpty())
xml.tag("name", writeName);
if (rBaseTpc != Tpc::TPC_INVALID) {
xml.tag("base", rBaseTpc);
if (_baseCase != NoteCaseType::CAPITAL)
xml.tag("baseCase", static_cast<int>(_baseCase));
}
for (const HDegree& hd : _degreeList) {
HDegreeType tp = hd.type();
if (tp == HDegreeType::ADD || tp == HDegreeType::ALTER || tp == HDegreeType::SUBTRACT) {
xml.stag("degree");
xml.tag("degree-value", hd.value());
xml.tag("degree-alter", hd.alter());
switch (tp) {
case HDegreeType::ADD:
xml.tag("degree-type", "add");
break;
case HDegreeType::ALTER:
xml.tag("degree-type", "alter");
break;
case HDegreeType::SUBTRACT:
xml.tag("degree-type", "subtract");
break;
default:
break;
}
xml.etag();
}
}
}
else
xml.tag("name", _textName);
TextBase::writeProperties(xml, false, true);
if (_rightParen)
xml.tagE("rightParen");
xml.etag();
}
//---------------------------------------------------------
// read
//---------------------------------------------------------
void Harmony::read(XmlReader& e)
{
while (e.readNextStartElement()) {
const QStringRef& tag(e.name());
if (tag == "base")
setBaseTpc(e.readInt());
else if (tag == "baseCase")
_baseCase = static_cast<NoteCaseType>(e.readInt());
else if (tag == "extension")
setId(e.readInt());
else if (tag == "name")
_textName = e.readElementText();
else if (tag == "root")
setRootTpc(e.readInt());
else if (tag == "rootCase")
_rootCase = static_cast<NoteCaseType>(e.readInt());
else if (tag == "degree") {
int degreeValue = 0;
int degreeAlter = 0;
QString degreeType = "";
while (e.readNextStartElement()) {
const QStringRef& t(e.name());
if (t == "degree-value")
degreeValue = e.readInt();
else if (t == "degree-alter")
degreeAlter = e.readInt();
else if (t == "degree-type")
degreeType = e.readElementText();
else
e.unknown();
}
if (degreeValue <= 0 || degreeValue > 13
|| degreeAlter < -2 || degreeAlter > 2
|| (degreeType != "add" && degreeType != "alter" && degreeType != "subtract")) {
qDebug("incorrect degree: degreeValue=%d degreeAlter=%d degreeType=%s",
degreeValue, degreeAlter, qPrintable(degreeType));
}
else {
if (degreeType == "add")
addDegree(HDegree(degreeValue, degreeAlter, HDegreeType::ADD));
else if (degreeType == "alter")
addDegree(HDegree(degreeValue, degreeAlter, HDegreeType::ALTER));
else if (degreeType == "subtract")
addDegree(HDegree(degreeValue, degreeAlter, HDegreeType::SUBTRACT));
}
}
else if (tag == "leftParen") {
_leftParen = true;
e.readNext();
}
else if (tag == "rightParen") {
_rightParen = true;
e.readNext();
}
else if (readProperty(tag, e, Pid::POS_ABOVE))
;
else if (!TextBase::readProperties(e))
e.unknown();
}
// TODO: now that we can render arbitrary chords,
// we could try to construct a full representation from a degree list.
// These will typically only exist for chords imported from MusicXML prior to MuseScore 2.0
// or constructed in the Chord Symbol Properties dialog.
if (_rootTpc != Tpc::TPC_INVALID) {
if (_id > 0) {
// positive id will happen only for scores that were created with explicit chord lists
// lookup id in chord list and generate new description if necessary
getDescription();
}
else
{
// default case: look up by name
// description will be found for any chord already read in this score
// and we will generate a new one if necessary
getDescription(_textName);
}
}
else if (_textName == "") {
// unrecognized chords prior to 2.0 were stored as text with markup
// we need to strip away the markup
// this removes any user-applied formatting,
// but we no longer support user-applied formatting for chord symbols anyhow
// with any luck, the resulting text will be parseable now, so give it a shot
createLayout();
QString s = plainText();
if (!s.isEmpty()) {
setHarmony(s);
return;
}
// empty text could also indicate a root-less slash chord ("/E")
// we'll fall through and render it normally
}
// render chord from description (or _textName)
render();
setXmlText(harmonyName());
}
//---------------------------------------------------------
// determineRootBaseSpelling
//---------------------------------------------------------
void Harmony::determineRootBaseSpelling(NoteSpellingType& rootSpelling, NoteCaseType& rootCase,
NoteSpellingType& baseSpelling, NoteCaseType& baseCase)
{
// spelling
if (score()->styleB(Sid::useStandardNoteNames))
rootSpelling = NoteSpellingType::STANDARD;
else if (score()->styleB(Sid::useGermanNoteNames))
rootSpelling = NoteSpellingType::GERMAN;
else if (score()->styleB(Sid::useFullGermanNoteNames))
rootSpelling = NoteSpellingType::GERMAN_PURE;
else if (score()->styleB(Sid::useSolfeggioNoteNames))
rootSpelling = NoteSpellingType::SOLFEGGIO;
else if (score()->styleB(Sid::useFrenchNoteNames))
rootSpelling = NoteSpellingType::FRENCH;
baseSpelling = rootSpelling;
// case
// always use case as typed if automatic capitalization is off
if (!score()->styleB(Sid::automaticCapitalization)) {
rootCase = _rootCase;
baseCase = _baseCase;
return;
}
// set default
if (score()->styleB(Sid::allCapsNoteNames)) {
rootCase = NoteCaseType::UPPER;
baseCase = NoteCaseType::UPPER;
}
else {
rootCase = NoteCaseType::CAPITAL;
baseCase = NoteCaseType::CAPITAL;
}
// override for bass note
if (score()->styleB(Sid::lowerCaseBassNotes))
baseCase = NoteCaseType::LOWER;
// override for minor chords
if (score()->styleB(Sid::lowerCaseMinorChords)) {
const ChordDescription* cd = descr();
QString quality;
if (cd) {
// use chord description if possible
// this is the usual case
quality = cd->quality();
}
else if (_parsedForm) {
// this happens on load of new chord list
// for chord symbols that were added/edited since the score was loaded
// or read aloud with screenreader
// parsed form is usable even if out of date with respect to chord list
quality = _parsedForm->quality();
}
else {
// this happens on load of new chord list
// for chord symbols that have not been edited since the score was loaded
// we need to parse this chord for now to determine quality
// but don't keep the parsed form around as we're not ready for it yet
quality = parsedForm()->quality();
delete _parsedForm;
_parsedForm = 0;
}
if (quality == "minor" || quality == "diminished" || quality == "half-diminished")
rootCase = NoteCaseType::LOWER;
}
}
//---------------------------------------------------------
// determineRootBaseSpelling
//---------------------------------------------------------
void Harmony::determineRootBaseSpelling()
{
determineRootBaseSpelling(_rootSpelling, _rootRenderCase,
_baseSpelling, _baseRenderCase);
}
//---------------------------------------------------------
// convertNote
// convert something like "C#" into tpc 21
//---------------------------------------------------------
static int convertNote(const QString& s, NoteSpellingType noteSpelling, NoteCaseType& noteCase, int& idx)
{
bool useGerman = false;
bool useSolfeggio = false;
static const int spellings[] = {
// bb b - # ##
0, 7, 14, 21, 28, // C
2, 9, 16, 23, 30, // D
4, 11, 18, 25, 32, // E
-1, 6, 13, 20, 27, // F
1, 8, 15, 22, 29, // G
3, 10, 17, 24, 31, // A
5, 12, 19, 26, 33, // B
};
if (s == "")
return Tpc::TPC_INVALID;
noteCase = s[0].isLower() ? NoteCaseType::LOWER : NoteCaseType::CAPITAL;
int acci;
switch (noteSpelling) {
case NoteSpellingType::SOLFEGGIO:
case NoteSpellingType::FRENCH:
useSolfeggio = true;
if (s.toLower().startsWith("sol"))
acci = 3;
else
acci = 2;
break;
case NoteSpellingType::GERMAN:
case NoteSpellingType::GERMAN_PURE:
useGerman = true;
// fall through
default:
acci = 1;
}
idx = acci;
int alter = 0;
int n = s.size();
QString acc = s.right(n-acci);
if (acc != "") {
if (acc.startsWith("bb")) {
alter = -2;
idx += 2;
}
else if (acc.startsWith("b")) {
alter = -1;
idx += 1;
}
else if (useGerman && acc.startsWith("eses")) {
alter = -2;
idx += 4;
}
else if (useGerman && (acc.startsWith("ses") || acc.startsWith("sas"))) {
alter = -2;
idx += 3;
}
else if (useGerman && acc.startsWith("es")) {
alter = -1;
idx += 2;
}
else if (useGerman && acc.startsWith("s") && !acc.startsWith("su")) {
alter = -1;
idx += 1;
}
else if (acc.startsWith("##")) {
alter = 2;
idx += 2;
}
else if (acc.startsWith("x")) {
alter = 2;
idx += 1;
}
else if (acc.startsWith("#")) {
alter = 1;
idx += 1;
}
else if (useGerman && acc.startsWith("isis")) {
alter = 2;
idx += 4;
}
else if (useGerman && acc.startsWith("is")) {
alter = 1;
idx += 2;
}
}
int r;
if (useGerman) {
switch(s[0].toLower().toLatin1()) {
case 'c': r = 0; break;
case 'd': r = 1; break;
case 'e': r = 2; break;
case 'f': r = 3; break;
case 'g': r = 4; break;
case 'a': r = 5; break;
case 'h': r = 6; break;
case 'b':
if (alter && alter != -1)
return Tpc::TPC_INVALID;
r = 6;
alter = -1;
break;
default:
return Tpc::TPC_INVALID;
}
}
else if (useSolfeggio) {
if (s.length() < 2)
return Tpc::TPC_INVALID;
if (s[1].isUpper())
noteCase = NoteCaseType::UPPER;
QString ss = s.toLower().left(2);
if (ss == "do")
r = 0;
else if (ss == "re" || ss == "ré")
r = 1;
else if (ss == "mi")
r = 2;
else if (ss == "fa")
r = 3;
else if (ss == "so") // sol, but only check first 2 characters
r = 4;
else if (ss == "la")
r = 5;
else if (ss == "si")
r = 6;
else
return Tpc::TPC_INVALID;
}
else {
switch(s[0].toLower().toLatin1()) {
case 'c': r = 0; break;
case 'd': r = 1; break;
case 'e': r = 2; break;
case 'f': r = 3; break;
case 'g': r = 4; break;
case 'a': r = 5; break;
case 'b': r = 6; break;
default: return Tpc::TPC_INVALID;
}
}
r = spellings[r * 5 + alter + 2];
return r;
}
//---------------------------------------------------------
// parseHarmony
// determine root and bass tpc & case
// compare body of chordname against chord list
// return true if chord is recognized
//---------------------------------------------------------
const ChordDescription* Harmony::parseHarmony(const QString& ss, int* root, int* base, bool syntaxOnly)
{
_id = -1;
if (_parsedForm) {
delete _parsedForm;
_parsedForm = 0;
}
_textName.clear();
bool useLiteral = false;
if (ss.endsWith(' '))
useLiteral = true;
QString s = ss.simplified();
if ((_leftParen = s.startsWith('(')))
s.remove(0,1);
if ((_rightParen = (s.endsWith(')') && s.count('(') < s.count(')'))))
s.remove(s.size()-1,1);
if (_leftParen || _rightParen)
s = s.simplified(); // in case of spaces inside parentheses
int n = s.size();
if (n < 1)
return 0;
determineRootBaseSpelling();
int idx;
int r = convertNote(s, _rootSpelling, _rootCase, idx);
if (r == Tpc::TPC_INVALID) {
if (s[0] == '/')
idx = 0;
else {
qDebug("failed <%s>", qPrintable(ss));
_userName = s;
_textName = s;
return 0;
}
}
*root = r;
bool preferMinor;
if (score()->styleB(Sid::lowerCaseMinorChords) && s[0].isLower())
preferMinor = true;
else
preferMinor = false;
*base = Tpc::TPC_INVALID;
int slash = s.lastIndexOf('/');
if (slash != -1) {
QString bs = s.mid(slash + 1).simplified();
s = s.mid(idx, slash - idx).simplified();
int idx2;
*base = convertNote(bs, _baseSpelling, _baseCase, idx2);
if (idx2 != bs.size())
*base = Tpc::TPC_INVALID;
if (*base == Tpc::TPC_INVALID) {
// if what follows after slash is not (just) a TPC
// then reassemble chord and try to parse with the slash
s = s + "/" + bs;
}
}
else
s = s.mid(idx); // don't simplify; keep leading space before extension if present
_userName = s;
const ChordList* cl = score()->style().chordList();
const ChordDescription* cd = 0;
if (useLiteral)
cd = descr(s);
else {
_parsedForm = new ParsedChord();
_parsedForm->parse(s, cl, syntaxOnly, preferMinor);
// parser prepends "=" to name of implied minor chords
// use this here as well
if (preferMinor)
s = _parsedForm->name();
// look up to see if we already have a descriptor (chord has been used before)
cd = descr(s, _parsedForm);
}
if (cd) {
// descriptor found; use its information
_id = cd->id;
if (!cd->names.empty())
_textName = cd->names.front();
}
else {
// no descriptor yet; just set textname
// we will generate descriptor later if necessary (when we are done editing this chord)
_textName = s;
}
return cd;
}
//---------------------------------------------------------
// startEdit
//---------------------------------------------------------
void Harmony::startEdit(EditData& ed)
{
if (!textList.empty()) {
// convert chord symbol to plain text
setXmlText(harmonyName());
// clear rendering
for (const TextSegment* t : textList)
delete t;
textList.clear();
}
// layout as text, without position reset
TextBase::layout1();
triggerLayout();
TextBase::startEdit(ed);
}
//---------------------------------------------------------
// edit
//---------------------------------------------------------
bool Harmony::edit(EditData& ed)
{
if (ed.key == Qt::Key_Return)
return true; // Harmony only single line
bool rv = TextBase::edit(ed);
// layout as text, without position reset
TextBase::layout1();
triggerLayout();
// check spelling
int root = TPC_INVALID;
int base = TPC_INVALID;
QString str = xmlText();
showSpell = !str.isEmpty() && !parseHarmony(str, &root, &base, true) && root == TPC_INVALID;
if (showSpell)
qDebug("bad spell");
return rv;
}
//---------------------------------------------------------
// endEdit
//---------------------------------------------------------
void Harmony::endEdit(EditData& ed)
{
// render to layout as chord symbol
setHarmony(plainText());
// disable spell check
showSpell = false;
TextBase::endEdit(ed); // layout happens here
if (links()) {
for (ScoreElement* e : *links()) {
if (e == this)
continue;
Harmony* h = toHarmony(e);
// transpose if necessary
// at this point chord will already have been rendered in same key as original
// (as a result of TextBase::endEdit() calling setText() for linked elements)
// we may now need to change the TPC's and the text, and re-render
if (score()->styleB(Sid::concertPitch) != h->score()->styleB(Sid::concertPitch)) {
Part* partDest = h->part();
Segment* segment = toSegment(parent());
Fraction tick = segment ? segment->tick() : Fraction(-1,1);
Interval interval = partDest->instrument(tick)->transpose();
if (!interval.isZero()) {
if (!h->score()->styleB(Sid::concertPitch))
interval.flip();
int rootTpc = transposeTpc(h->rootTpc(), interval, true);
int baseTpc = transposeTpc(h->baseTpc(), interval, true);
//score()->undoTransposeHarmony(h, rootTpc, baseTpc);
h->setRootTpc(rootTpc);
h->setBaseTpc(baseTpc);
h->setXmlText(h->harmonyName());
h->setHarmony(h->plainText());
h->triggerLayout();
}
}
}
}
}
//---------------------------------------------------------
// setHarmony
//---------------------------------------------------------
void Harmony::setHarmony(const QString& s)
{
int r, b;
const ChordDescription* cd = parseHarmony(s, &r, &b);
if (!cd && _parsedForm && _parsedForm->parseable()) {
// our first time encountering this chord
// generate a descriptor and use it
cd = generateDescription();
_id = cd->id;
}
if (cd) {
setRootTpc(r);
setBaseTpc(b);
render();
}
else {
// unparseable chord, render as plain text
for (const TextSegment* ts : textList)
delete ts;
textList.clear();
setRootTpc(Tpc::TPC_INVALID);
setBaseTpc(Tpc::TPC_INVALID);
_id = -1;
render();
}
}
//---------------------------------------------------------
// baseLine
//---------------------------------------------------------
qreal Harmony::baseLine() const
{
return (textList.empty()) ? TextBase::baseLine() : 0.0;
}
//---------------------------------------------------------
// text
//---------------------------------------------------------
QString HDegree::text() const
{
if (_type == HDegreeType::UNDEF)
return QString();
const char* d = 0;
switch(_type) {
case HDegreeType::UNDEF: break;
case HDegreeType::ADD: d= "add"; break;
case HDegreeType::ALTER: d= "alt"; break;
case HDegreeType::SUBTRACT: d= "sub"; break;
}
QString degree(d);
switch(_alter) {
case -1: degree += "b"; break;
case 1: degree += "#"; break;
default: break;
}
QString s = QString("%1").arg(_value);
QString ss = degree + s;
return ss;
}
//---------------------------------------------------------
// fromXml
// lookup harmony in harmony data base
// using musicXml "kind" string and degree list
//---------------------------------------------------------
const ChordDescription* Harmony::fromXml(const QString& kind, const QList<HDegree>& dl)
{
QStringList degrees;
foreach(const HDegree& d, dl)
degrees.append(d.text());
QString lowerCaseKind = kind.toLower();
const ChordList* cl = score()->style().chordList();
foreach(const ChordDescription& cd, *cl) {
QString k = cd.xmlKind;
QString lowerCaseK = k.toLower(); // required for xmlKind Tristan
QStringList d = cd.xmlDegrees;
if ((lowerCaseKind == lowerCaseK) && (d == degrees)) {
// qDebug("harmony found in db: %s %s -> %d", qPrintable(kind), qPrintable(degrees), cd->id);
return &cd;
}
}
return 0;
}
//---------------------------------------------------------
// fromXml
// lookup harmony in harmony data base
// using musicXml "kind" string only
//---------------------------------------------------------
const ChordDescription* Harmony::fromXml(const QString& kind)
{
QString lowerCaseKind = kind.toLower();
const ChordList* cl = score()->style().chordList();
foreach(const ChordDescription& cd, *cl) {
if (lowerCaseKind == cd.xmlKind)
return &cd;
}
return 0;
}
//---------------------------------------------------------
// fromXml
// construct harmony directly from XML
// build name first
// then generate chord description from that
//---------------------------------------------------------
const ChordDescription* Harmony::fromXml(const QString& kind, const QString& kindText, const QString& symbols, const QString& parens, const QList<HDegree>& dl)
{
ParsedChord* pc = new ParsedChord;
_textName = pc->fromXml(kind, kindText, symbols, parens, dl, score()->style().chordList());
_parsedForm = pc;
const ChordDescription* cd = getDescription(_textName,pc);
return cd;
}
//---------------------------------------------------------
// descr
// look up id in chord list
// return chord description if found, or null
//---------------------------------------------------------
const ChordDescription* Harmony::descr() const
{
return score()->style().chordDescription(_id);
}
//---------------------------------------------------------
// descr
// look up name in chord list
// optionally look up by parsed chord as fallback
// return chord description if found, or null
//---------------------------------------------------------
const ChordDescription* Harmony::descr(const QString& name, const ParsedChord* pc) const
{
const ChordList* cl = score()->style().chordList();
const ChordDescription* match = 0;
if (cl) {
foreach (const ChordDescription& cd, *cl) {
for (const QString& s : cd.names) {
if (s == name)
return &cd;
else if (pc) {
for (const ParsedChord& sParsed : cd.parsedChords) {
if (sParsed == *pc)
match = &cd;
}
}
}
}
}
// exact match failed, so fall back on parsed match if one was found
return match;
}
//---------------------------------------------------------
// getDescription
// look up id in chord list
// return chord description if found
// if not found, and chord is parseable,
// generate a new chord description
// and add to chord list
//---------------------------------------------------------
const ChordDescription* Harmony::getDescription()
{
const ChordDescription* cd = descr();
if (cd && !cd->names.empty())
_textName = cd->names.front();
else if (_textName != "") {
cd = generateDescription();
_id = cd->id;
}
return cd;
}
//---------------------------------------------------------
// getDescription
// same but lookup by name and optionally parsed chord
//---------------------------------------------------------
const ChordDescription* Harmony::getDescription(const QString& name, const ParsedChord* pc)
{
const ChordDescription* cd = descr(name, pc);
if (cd)
_id = cd->id;
else {
cd = generateDescription();
_id = cd->id;
}
return cd;
}
//---------------------------------------------------------
// generateDescription
// generate new chord description from _textName
// add to chord list using private id
//---------------------------------------------------------
const ChordDescription* Harmony::generateDescription()
{
ChordList* cl = score()->style().chordList();
ChordDescription cd(_textName);
cd.complete(_parsedForm, cl);
// remove parsed chord from description
// so we will only match it literally in the future
cd.parsedChords.clear();
return &*cl->insert(cd.id, cd);
}
//---------------------------------------------------------
// layout
//---------------------------------------------------------
void Harmony::layout()
{
if (!parent()) {
setPos(0.0, 0.0);
setOffset(0.0, 0.0);
layout1();
return;
}
//if (isStyled(Pid::OFFSET))
// setOffset(propertyDefault(Pid::OFFSET).toPointF());
if (placeBelow())
rypos() = staff() ? staff()->height() : 0.0;
else
rypos() = 0.0;
layout1();
qreal yy = ipos().y();
qreal xx = 0.0;
if (parent()->isFretDiagram()) {
if (isStyled(Pid::ALIGN))
setAlign(Align::HCENTER | Align::BASELINE);
yy = -score()->styleP(Sid::harmonyFretDist);
}
qreal hb = lineHeight() - TextBase::baseLine();
if (align() & Align::BOTTOM)
yy -= hb;
else if (align() & Align::VCENTER) {
yy -= hb;
yy += (height() * .5);
}
else if (align() & Align::BASELINE) {
}
else { // Align::TOP
yy -= hb;
yy += height();
}
qreal cw = symWidth(SymId::noteheadBlack);
if (align() & Align::RIGHT) {
xx += cw;
xx -= width();
}
else if (align() & Align::HCENTER) {
if (parent()->isFretDiagram()) {
FretDiagram* fd = toFretDiagram(parent());
xx += fd->centerX();
xx -= width() * .5;
}
else {
xx += (cw * .5);
xx -= (width() * .5);
}
}
setPos(xx, yy);
}
//---------------------------------------------------------
// layout1
//---------------------------------------------------------
void Harmony::layout1()
{
if (isLayoutInvalid())
createLayout();
if (textBlockList().empty())
textBlockList().append(TextBlock());
calculateBoundingRect(); // for normal symbols this is called in layout: computeMinWidth()
if (hasFrame())
layoutFrame();
score()->addRefresh(canvasBoundingRect());
}
//---------------------------------------------------------
// calculateBoundingRect
//---------------------------------------------------------
void Harmony::calculateBoundingRect()
{
if (textList.empty())
TextBase::layout1();
else {
QRectF bb;
for (const TextSegment* ts : textList)
bb |= ts->tightBoundingRect().translated(ts->x, ts->y);
setbbox(bb);
for (int i = 0; i < rows(); ++i) {
TextBlock& t = textBlockList()[i];
// when MS switch to editing Harmony MS draws text defined by textBlockList().
// When MS switches back to normal state it draws text from textList
// To correct placement of text in editing we need to layout textBlockList() elements
t.layout(this);
for (auto& s : t.fragments()) {
s.pos = { 0, 0 };
}
}
}
}
//---------------------------------------------------------
// draw
//---------------------------------------------------------
void Harmony::draw(QPainter* painter) const
{
// painter->setPen(curColor());
if (textList.empty()) {
TextBase::draw(painter);
return;
}
if (hasFrame()) {
if (frameWidth().val() != 0.0) {
QColor color = frameColor();
QPen pen(color, frameWidth().val() * spatium(), Qt::SolidLine,
Qt::SquareCap, Qt::MiterJoin);
painter->setPen(pen);
}
else
painter->setPen(Qt::NoPen);
QColor bg(bgColor());
painter->setBrush(bg.alpha() ? QBrush(bg) : Qt::NoBrush);
if (circle())
painter->drawArc(frame, 0, 5760);
else {
int r2 = frameRound();
if (r2 > 99)
r2 = 99;
painter->drawRoundedRect(frame, frameRound(), r2);
}
}
painter->setBrush(Qt::NoBrush);
QColor color = textColor();
painter->setPen(color);
for (const TextSegment* ts : textList) {
QFont f(ts->font);
f.setPointSizeF(f.pointSizeF() * MScore::pixelRatio);
painter->setFont(f);
painter->drawText(QPointF(ts->x, ts->y), ts->text);
}
}
//---------------------------------------------------------
// drawEditMode
//---------------------------------------------------------
void Harmony::drawEditMode(QPainter* p, EditData& ed)
{
TextBase::drawEditMode(p, ed);
QColor originalColor = color();
if (showSpell) {
setColor(QColor(Qt::red));
setSelected(false);
}
QPointF pos(canvasPos());
p->translate(pos);
TextBase::draw(p);
p->translate(-pos);
if (showSpell) {
setColor(originalColor);
setSelected(true);
}
}
//---------------------------------------------------------
// TextSegment
//---------------------------------------------------------
TextSegment::TextSegment(const QString& s, const QFont& f, qreal x, qreal y)
{
set(s, f, x, y);
select = false;
}
//---------------------------------------------------------
// width
//---------------------------------------------------------
qreal TextSegment::width() const
{
QFontMetricsF fm(font, MScore::paintDevice());
#if 1
return fm.width(text);
#else
qreal w = 0.0;
foreach(QChar c, text) {
// if we calculate width by character, at least skip high surrogates
if (c.isHighSurrogate())
continue;
w += fm.width(c);
}
return w;
#endif
}
//---------------------------------------------------------
// boundingRect
//---------------------------------------------------------
QRectF TextSegment::boundingRect() const
{
QFontMetricsF fm(font, MScore::paintDevice());
return fm.boundingRect(text);
}
//---------------------------------------------------------
// tightBoundingRect
//---------------------------------------------------------
QRectF TextSegment::tightBoundingRect() const
{
QFontMetricsF fm(font, MScore::paintDevice());
return fm.tightBoundingRect(text);
}
//---------------------------------------------------------
// set
//---------------------------------------------------------
void TextSegment::set(const QString& s, const QFont& f, qreal _x, qreal _y)
{
font = f;
x = _x;
y = _y;
setText(s);
}
//---------------------------------------------------------
// render
//---------------------------------------------------------
void Harmony::render(const QString& s, qreal& x, qreal& y)
{
int fontIdx = 0;
if (!s.isEmpty()) {
TextSegment* ts = new TextSegment(s, fontList[fontIdx], x, y);
textList.append(ts);
x += ts->width();
}
}
//---------------------------------------------------------
// render
//---------------------------------------------------------
void Harmony::render(const QList<RenderAction>& renderList, qreal& x, qreal& y, int tpc, NoteSpellingType noteSpelling, NoteCaseType noteCase)
{
ChordList* chordList = score()->style().chordList();
QStack<QPointF> stack;
int fontIdx = 0;
qreal _spatium = spatium();
qreal mag = magS();
// qDebug("===");
for (const RenderAction& a : renderList) {
// a.print();
if (a.type == RenderAction::RenderActionType::SET) {
TextSegment* ts = new TextSegment(fontList[fontIdx], x, y);
ChordSymbol cs = chordList->symbol(a.text);
if (cs.isValid()) {
ts->font = fontList[cs.fontIdx];
ts->setText(cs.value);
}
else
ts->setText(a.text);
textList.append(ts);
x += ts->width();
}
else if (a.type == RenderAction::RenderActionType::MOVE) {
x += a.movex * mag * _spatium * .2;
y += a.movey * mag * _spatium * .2;
}
else if (a.type == RenderAction::RenderActionType::PUSH)
stack.push(QPointF(x,y));
else if (a.type == RenderAction::RenderActionType::POP) {
if (!stack.empty()) {
QPointF pt = stack.pop();
x = pt.x();
y = pt.y();
}
else
qDebug("RenderAction::RenderActionType::POP: stack empty");
}
else if (a.type == RenderAction::RenderActionType::NOTE) {
QString c;
int acc;
tpc2name(tpc, noteSpelling, noteCase, c, acc);
TextSegment* ts = new TextSegment(fontList[fontIdx], x, y);
QString lookup = "note" + c;
ChordSymbol cs = chordList->symbol(lookup);
if (!cs.isValid())
cs = chordList->symbol(c);
if (cs.isValid()) {
ts->font = fontList[cs.fontIdx];
ts->setText(cs.value);
}
else {
ts->setText(c);
}
textList.append(ts);
x += ts->width();
}
else if (a.type == RenderAction::RenderActionType::ACCIDENTAL) {
QString c;
QString acc;
QString context = "accidental";
tpc2name(tpc, noteSpelling, noteCase, c, acc);
// German spelling - use special symbol for accidental in TPC_B_B
// to allow it to be rendered as either Bb or B
if (tpc == Tpc::TPC_B_B && noteSpelling == NoteSpellingType::GERMAN)
context = "german_B";
if (acc != "") {
TextSegment* ts = new TextSegment(fontList[fontIdx], x, y);
QString lookup = context + acc;
ChordSymbol cs = chordList->symbol(lookup);
if (!cs.isValid())
cs = chordList->symbol(acc);
if (cs.isValid()) {
ts->font = fontList[cs.fontIdx];
ts->setText(cs.value);
}
else
ts->setText(acc);
textList.append(ts);
x += ts->width();
}
}
else
qDebug("unknown render action %d", static_cast<int>(a.type));
}
}
//---------------------------------------------------------
// render
// construct Chord Symbol
//---------------------------------------------------------
void Harmony::render()
{
int capo = score()->styleI(Sid::capoPosition);
ChordList* chordList = score()->style().chordList();
fontList.clear();
for (const ChordFont& cf : chordList->fonts) {
QFont ff(font());
ff.setPointSizeF(ff.pointSizeF() * cf.mag);
if (!(cf.family.isEmpty() || cf.family == "default"))
ff.setFamily(cf.family);
fontList.append(ff);
}
if (fontList.empty())
fontList.append(font());
for (const TextSegment* s : textList)
delete s;
textList.clear();
qreal x = 0.0, y = 0.0;
determineRootBaseSpelling();
if (_leftParen)
render("( ", x, y);
if (_rootTpc != Tpc::TPC_INVALID) {
// render root
render(chordList->renderListRoot, x, y, _rootTpc, _rootSpelling, _rootRenderCase);
// render extension
const ChordDescription* cd = getDescription();
if (cd)
render(cd->renderList, x, y, 0);
}
else
render(_textName, x, y);
// render bass
if (_baseTpc != Tpc::TPC_INVALID)
render(chordList->renderListBase, x, y, _baseTpc, _baseSpelling, _baseRenderCase);
if (_rootTpc != Tpc::TPC_INVALID && capo > 0 && capo < 12) {
int tpcOffset[] = { 0, 5, -2, 3, -4, 1, 6, -1, 4, -3, 2, -5 };
int capoRootTpc = _rootTpc + tpcOffset[capo];
int capoBassTpc = _baseTpc;
if (capoBassTpc != Tpc::TPC_INVALID)
capoBassTpc += tpcOffset[capo];
/*
* For guitarists, avoid x and bb in Root or Bass,
* and also avoid E#, B#, Cb and Fb in Root.
*/
if (capoRootTpc < 8 || (capoBassTpc != Tpc::TPC_INVALID && capoBassTpc < 6)) {
capoRootTpc += 12;
if (capoBassTpc != Tpc::TPC_INVALID)
capoBassTpc += 12;
}
else if (capoRootTpc > 24 || (capoBassTpc != Tpc::TPC_INVALID && capoBassTpc > 26)) {
capoRootTpc -= 12;
if (capoBassTpc != Tpc::TPC_INVALID)
capoBassTpc -= 12;
}
render("(", x, y);
render(chordList->renderListRoot, x, y, capoRootTpc, _rootSpelling, _rootRenderCase);
// render extension
const ChordDescription* cd = getDescription();
if (cd)
render(cd->renderList, x, y, 0);
if (capoBassTpc != Tpc::TPC_INVALID)
render(chordList->renderListBase, x, y, capoBassTpc, _baseSpelling, _baseRenderCase);
render(")", x, y);
}
if (_rightParen)
render(" )", x, y);
}
//---------------------------------------------------------
// spatiumChanged
//---------------------------------------------------------
void Harmony::spatiumChanged(qreal oldValue, qreal newValue)
{
TextBase::spatiumChanged(oldValue, newValue);
render();
}
//---------------------------------------------------------
// localSpatiumChanged
//---------------------------------------------------------
void Harmony::localSpatiumChanged(qreal oldValue, qreal newValue)
{
TextBase::localSpatiumChanged(oldValue, newValue);
render();
}
//---------------------------------------------------------
// extensionName
//---------------------------------------------------------
const QString& Harmony::extensionName() const
{
return _textName;
}
//---------------------------------------------------------
// xmlKind
//---------------------------------------------------------
QString Harmony::xmlKind() const
{
const ChordDescription* cd = descr();
return cd ? cd->xmlKind : QString();
}
//---------------------------------------------------------
// musicXmlText
//---------------------------------------------------------
QString Harmony::musicXmlText() const
{
const ChordDescription* cd = descr();
return cd ? cd->xmlText : QString();
}
//---------------------------------------------------------
// xmlSymbols
//---------------------------------------------------------
QString Harmony::xmlSymbols() const
{
const ChordDescription* cd = descr();
return cd ? cd->xmlSymbols : QString();
}
//---------------------------------------------------------
// xmlParens
//---------------------------------------------------------
QString Harmony::xmlParens() const
{
const ChordDescription* cd = descr();
return cd ? cd->xmlParens : QString();
}
//---------------------------------------------------------
// xmlDegrees
//---------------------------------------------------------
QStringList Harmony::xmlDegrees() const
{
const ChordDescription* cd = descr();
return cd ? cd->xmlDegrees : QStringList();
}
//---------------------------------------------------------
// degree
//---------------------------------------------------------
HDegree Harmony::degree(int i) const
{
return _degreeList.value(i);
}
//---------------------------------------------------------
// addDegree
//---------------------------------------------------------
void Harmony::addDegree(const HDegree& d)
{
_degreeList << d;
}
//---------------------------------------------------------
// numberOfDegrees
//---------------------------------------------------------
int Harmony::numberOfDegrees() const
{
return _degreeList.size();
}
//---------------------------------------------------------
// clearDegrees
//---------------------------------------------------------
void Harmony::clearDegrees()
{
_degreeList.clear();
}
//---------------------------------------------------------
// degreeList
//---------------------------------------------------------
const QList<HDegree>& Harmony::degreeList() const
{
return _degreeList;
}
//---------------------------------------------------------
// parsedForm
//---------------------------------------------------------
const ParsedChord* Harmony::parsedForm()
{
if (!_parsedForm) {
ChordList* cl = score()->style().chordList();
_parsedForm = new ParsedChord();
_parsedForm->parse(_textName, cl, false);
}
return _parsedForm;
}
//---------------------------------------------------------
// accessibleInfo
//---------------------------------------------------------
QString Harmony::accessibleInfo() const
{
return QString("%1: %2").arg(Element::accessibleInfo()).arg(harmonyName());
}
//---------------------------------------------------------
// screenReaderInfo
//---------------------------------------------------------
QString Harmony::screenReaderInfo() const
{
QString rez = Element::accessibleInfo();
if (_rootTpc != Tpc::TPC_INVALID)
rez = QString("%1 %2").arg(rez).arg(tpc2name(_rootTpc, NoteSpellingType::STANDARD, NoteCaseType::AUTO, true));
if (const_cast<Harmony*>(this)->parsedForm() && !hTextName().isEmpty()) {
QString aux = const_cast<Harmony*>(this)->parsedForm()->handle();
aux = aux.replace("#", QObject::tr("♯")).replace("<", "");
QString extension = "";
foreach (QString s, aux.split(">", QString::SkipEmptyParts)) {
if(!s.contains("blues"))
s.replace("b", QObject::tr("♭"));
extension += s + " ";
}
rez = QString("%1 %2").arg(rez).arg(extension);
}
else {
rez = QString("%1 %2").arg(rez).arg(hTextName());
}
if (_baseTpc != Tpc::TPC_INVALID)
rez = QString("%1 / %2").arg(rez).arg(tpc2name(_baseTpc, NoteSpellingType::STANDARD, NoteCaseType::AUTO, true));
return rez;
}
//---------------------------------------------------------
// acceptDrop
//---------------------------------------------------------
bool Harmony::acceptDrop(EditData& data) const
{
return data.dropElement->isFretDiagram();
}
//---------------------------------------------------------
// drop
//---------------------------------------------------------
Element* Harmony::drop(EditData& data)
{
Element* e = data.dropElement;
if (e->isFretDiagram()) {
FretDiagram* fd = toFretDiagram(e);
fd->setParent(parent());
fd->setTrack(track());
score()->undoAddElement(fd);
}
else {
qWarning("Harmony: cannot drop <%s>\n", e->name());
delete e;
e = 0;
}
return e;
}
//---------------------------------------------------------
// getProperty
//---------------------------------------------------------
QVariant Harmony::getProperty(Pid pid) const
{
return TextBase::getProperty(pid);
}
//---------------------------------------------------------
// setProperty
//---------------------------------------------------------
bool Harmony::setProperty(Pid pid, const QVariant& v)
{
if (TextBase::setProperty(pid, v)) {
if (pid == Pid::TEXT)
setHarmony(v.toString());
render();
return true;
}
return false;
}
//---------------------------------------------------------
// propertyDefault
//---------------------------------------------------------
QVariant Harmony::propertyDefault(Pid id) const
{
QVariant v;
switch (id) {
case Pid::SUB_STYLE:
v = int(Tid::HARMONY_A);
break;
case Pid::OFFSET:
if (parent() && parent()->isFretDiagram()) {
v = QVariant(QPointF(0.0, 0.0));
break;
}
// fall-through
default:
v = TextBase::propertyDefault(id);
break;
}
return v;
}
//---------------------------------------------------------
// getPropertyStyle
//---------------------------------------------------------
Sid Harmony::getPropertyStyle(Pid pid) const
{
if (pid == Pid::OFFSET) {
if (parent() && parent()->isFretDiagram())
return Sid::NOSTYLE;
else if (tid() == Tid::HARMONY_A)
return placeAbove() ? Sid::chordSymbolAPosAbove : Sid::chordSymbolAPosBelow;
else
return placeAbove() ? Sid::chordSymbolBPosAbove : Sid::chordSymbolBPosBelow;
}
return TextBase::getPropertyStyle(pid);
}
}
|