File: read114.cpp

package info (click to toggle)
musescore3 3.2.3%2Bdfsg2-11
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 210,672 kB
  • sloc: cpp: 291,093; xml: 200,238; sh: 3,779; ansic: 1,447; python: 393; makefile: 240; perl: 82; pascal: 79
file content (3278 lines) | stat: -rw-r--r-- 145,699 bytes parent folder | download | duplicates (4)
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
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
//=============================================================================
//  MuseScore
//  Music Composition & Notation
//
//  Copyright (C) 2011 Werner Schweer and others
//
//  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 LICENSE.GPL
//=============================================================================

#include "score.h"
#include "slur.h"
#include "staff.h"
#include "excerpt.h"
#include "chord.h"
#include "rest.h"
#include "keysig.h"
#include "volta.h"
#include "measure.h"
#include "beam.h"
#include "segment.h"
#include "ottava.h"
#include "stafftype.h"
#include "text.h"
#include "measurenumber.h"
#include "part.h"
#include "sig.h"
#include "box.h"
#include "dynamic.h"
#include "drumset.h"
#include "style.h"
#include "sym.h"
#include "xml.h"
#include "stringdata.h"
#include "tempo.h"
#include "tempotext.h"
#include "clef.h"
#include "barline.h"
#include "timesig.h"
#include "tuplet.h"
#include "spacer.h"
#include "stafftext.h"
#include "repeat.h"
#include "breath.h"
#include "tremolo.h"
#include "utils.h"
#include "accidental.h"
#include "fingering.h"
#include "marker.h"
#include "read206.h"
#include "bracketItem.h"
#include "harmony.h"
#include "lyrics.h"
#include "image.h"
#include "textframe.h"
#include "jump.h"
#include "textline.h"
#include "pedal.h"

namespace Ms {

static int g_guitarStrings[] = {40,45,50,55,59,64};
static int g_bassStrings[]   = {28,33,38,43};
static int g_violinStrings[] = {55,62,69,76};
static int g_violaStrings[]  = {48,55,62,69};
static int g_celloStrings[]  = {36,43,50,57};

//---------------------------------------------------------
//   StyleVal114
//---------------------------------------------------------

struct StyleVal2 {
      Sid sid;
      QVariant val;
      };

static const StyleVal2 style114[] = {
//      { Sid::lyricsMinBottomDistance,      Spatium(2) },
      { Sid::lyricsDashForce,              QVariant(false) },
      { Sid::frameSystemDistance,          Spatium(1.0) },
      { Sid::minMeasureWidth,              Spatium(4.0) },
//      { Sid::endBarDistance,               Spatium(0.30) },

      { Sid::repeatBarTips,                QVariant(false) },
      { Sid::startBarlineSingle,           QVariant(false) },
      { Sid::startBarlineMultiple,         QVariant(true) },
      { Sid::bracketWidth,                 QVariant(0.35) },
      { Sid::bracketDistance,              QVariant(0.25) },
      { Sid::clefLeftMargin,               QVariant(0.5) },
      { Sid::keysigLeftMargin,             QVariant(0.5) },
      { Sid::timesigLeftMargin,            QVariant(0.5) },
      { Sid::clefKeyRightMargin,           QVariant(1.75) },
      { Sid::clefBarlineDistance,          QVariant(0.18) },
      { Sid::stemWidth,                    QVariant(0.13) },
      { Sid::shortenStem,                  QVariant(true) },
      { Sid::shortStemProgression,         QVariant(0.25) },
      { Sid::shortestStem,                 QVariant(2.25) },
      { Sid::beginRepeatLeftMargin,        QVariant(1.0) },
      { Sid::minNoteDistance,              QVariant(0.4) },
      { Sid::barNoteDistance,              QVariant(1.2) },
      { Sid::noteBarDistance,              QVariant(1.0) },
      { Sid::measureSpacing,               QVariant(1.2) },
      { Sid::staffLineWidth,               QVariant(0.08) },
      { Sid::ledgerLineWidth,              QVariant(0.12) },
      { Sid::akkoladeWidth,                QVariant(1.6) },
      { Sid::accidentalDistance,           QVariant(0.22) },
      { Sid::accidentalNoteDistance,       QVariant(0.22) },
      { Sid::beamWidth,                    QVariant(0.48) },
      { Sid::beamDistance,                 QVariant(0.5) },
      { Sid::beamMinLen,                   QVariant(1.25) },
      { Sid::dotNoteDistance,              QVariant(0.35) },
      { Sid::dotRestDistance,              QVariant(0.25) },
      { Sid::dotDotDistance,               QVariant(0.5) },
      { Sid::propertyDistanceHead,         QVariant(1.0) },
      { Sid::propertyDistanceStem,         QVariant(0.5) },
      { Sid::propertyDistance,             QVariant(1.0) },
      { Sid::articulationMag,              QVariant(qreal(1.0)) },
      { Sid::lastSystemFillLimit,          QVariant(0.3) },
      { Sid::hairpinHeight,                QVariant(1.2) },
      { Sid::hairpinContHeight,            QVariant(0.5) },
      { Sid::hairpinLineWidth,             QVariant(0.13) },
      { Sid::showPageNumber,               QVariant(true) },
      { Sid::showPageNumberOne,            QVariant(false) },
      { Sid::pageNumberOddEven,            QVariant(true) },
      { Sid::showMeasureNumber,            QVariant(true) },
      { Sid::showMeasureNumberOne,         QVariant(false) },
      { Sid::measureNumberInterval,        QVariant(5) },
      { Sid::measureNumberSystem,          QVariant(true) },
      { Sid::measureNumberAllStaffs,       QVariant(false) },
      { Sid::smallNoteMag,                 QVariant(qreal(0.7)) },
      { Sid::graceNoteMag,                 QVariant(qreal(0.7)) },
      { Sid::smallStaffMag,                QVariant(qreal(0.7)) },
      { Sid::smallClefMag,                 QVariant(qreal(0.8)) },
      { Sid::genClef,                      QVariant(true) },
      { Sid::genKeysig,                    QVariant(true) },
      { Sid::genCourtesyTimesig,           QVariant(true) },
      { Sid::genCourtesyKeysig,            QVariant(true) },
      { Sid::useStandardNoteNames,         QVariant(true) },
      { Sid::useGermanNoteNames,           QVariant(false) },
      { Sid::useFullGermanNoteNames,       QVariant(false) },
      { Sid::useSolfeggioNoteNames,        QVariant(false) },
      { Sid::useFrenchNoteNames,           QVariant(false) },
      { Sid::chordDescriptionFile,         QVariant(QString("stdchords.xml")) },
      { Sid::chordStyle,                   QVariant(QString("custom")) },
      { Sid::chordsXmlFile,                QVariant(true) },
//      { Sid::harmonyY,                     QVariant(0.0) },
      { Sid::concertPitch,                 QVariant(false) },
      { Sid::createMultiMeasureRests,      QVariant(false) },
      { Sid::minEmptyMeasures,             QVariant(2) },
      { Sid::minMMRestWidth,               QVariant(4.0) },
      { Sid::hideEmptyStaves,              QVariant(false) },
      { Sid::gateTime,                     QVariant(100) },
      { Sid::tenutoGateTime,               QVariant(100) },
      { Sid::staccatoGateTime,             QVariant(50) },
      { Sid::slurGateTime,                 QVariant(100) },
      { Sid::ArpeggioNoteDistance,         QVariant(.5) },
      { Sid::ArpeggioLineWidth,            QVariant(.18) },
      { Sid::ArpeggioHookLen,              QVariant(.8) },
      { Sid::keySigNaturals,               QVariant(int(KeySigNatural::BEFORE)) },
      { Sid::tupletMaxSlope,               QVariant(qreal(0.5)) },
      { Sid::tupletOufOfStaff,             QVariant(false) },
      { Sid::tupletVHeadDistance,          QVariant(.5) },
      { Sid::tupletVStemDistance,          QVariant(.25) },
      { Sid::tupletStemLeftDistance,       QVariant(.5) },
      { Sid::tupletStemRightDistance,      QVariant(.5) },
      { Sid::tupletNoteLeftDistance,       QVariant(0.0) },
      { Sid::tupletNoteRightDistance,      QVariant(0.0) },
      { Sid::hideInstrumentNameIfOneInstrument, QVariant(false) },
      };

#define MM(x) ((x)/INCH)

//---------------------------------------------------------
//   PaperSize
//---------------------------------------------------------

struct PaperSize {
      const char* name;
      qreal w, h;            // size in inch
      PaperSize(const char* n, qreal wi, qreal hi)
         : name(n), w(wi), h(hi) {}
      };

static const PaperSize paperSizes114[] = {
      PaperSize("Custom",    MM(1),    MM(1)),
      PaperSize("A4",        MM(210),  MM(297)),
      PaperSize("B5",        MM(176),  MM(250)),
      PaperSize("Letter",    8.5,      11),
      PaperSize("Legal",     8.5,      14),
      PaperSize("Executive", 7.5,      10),
      PaperSize("A0",        MM(841),  MM(1189)),
      PaperSize("A1",        MM(594),  MM(841)),
      PaperSize("A2",        MM(420),  MM(594)),
      PaperSize("A3",        MM(297),  MM(420)),
      PaperSize("A5",        MM(148),  MM(210)),
      PaperSize("A6",        MM(105),  MM(148)),
      PaperSize("A7",        MM(74),   MM(105)),
      PaperSize("A8",        MM(52),   MM(74)),
      PaperSize("A9",        MM(37),   MM(52)),
      PaperSize("A10",       MM(26),   MM(37)),
      PaperSize("B0",        MM(1000), MM(1414)),
      PaperSize("B1",        MM(707),  MM(1000)),
      PaperSize("B2",        MM(500),  MM(707)),
      PaperSize("B3",        MM(353),  MM(500)),
      PaperSize("B4",        MM(250),  MM(353)),
      PaperSize("B6",        MM(125),  MM(176)),
      PaperSize("B7",        MM(88),   MM(125)),
      PaperSize("B8",        MM(62),   MM(88)),
      PaperSize("B9",        MM(44),   MM(62)),
      PaperSize("B10",       MM(31),   MM(44)),
      PaperSize("Comm10E",   MM(105),  MM(241)),
      PaperSize("DLE",       MM(110),  MM(220)),
      PaperSize("Folio",     MM(210),  MM(330)),
      PaperSize("Ledger",    MM(432),  MM(279)),
      PaperSize("Tabloid",   MM(279),  MM(432)),
      PaperSize(0,           MM(1),    MM(1))   // mark end of list
      };


//---------------------------------------------------------
//   getPaperSize
//---------------------------------------------------------

static const PaperSize* getPaperSize114(const QString& name)
      {
      for (int i = 0; paperSizes114[i].name; ++i) {
            if (name == paperSizes114[i].name)
                  return &paperSizes114[i];
            }
      qDebug("unknown paper size");
      return &paperSizes114[0];
      }

//---------------------------------------------------------
//   convertFromHtml
//---------------------------------------------------------

QString convertFromHtml(TextBase* t, const QString& ss)
      {
      QTextDocument doc;
      doc.setHtml(ss.trimmed());

      QString s;
      qreal size     = t->size();   // textStyle().size();
      QString family = t->family(); // textStyle().family();

      for (auto b = doc.firstBlock(); b.isValid() ; b = b.next()) {
            if (!s.isEmpty())
                  s += "\n";
            for (auto it = b.begin(); !it.atEnd(); ++it) {
                  QTextFragment f = it.fragment();
                  if (f.isValid()) {
                        QTextCharFormat tf = f.charFormat();
                        QFont font = tf.font();
                        qreal htmlSize = font.pointSizeF();
                        // html font sizes may have spatium adjustments; need to undo this
                        if (t->sizeIsSpatiumDependent())
                              htmlSize *= SPATIUM20 / t->spatium();
                        if (fabs(size - htmlSize) > 0.1) {
                              size = htmlSize;
                              s += QString("<font size=\"%1\"/>").arg(size);
                              }
                        if (family != font.family()) {
                              family = font.family();
                              s += QString("<font face=\"%1\"/>").arg(family);
                              }
                        if (font.bold())
                              s += "<b>";
                        if (font.italic())
                              s += "<i>";
                        if (font.underline())
                              s += "<u>";
                        s += f.text().toHtmlEscaped();
                        if (font.underline())
                              s += "</u>";
                        if (font.italic())
                              s += "</i>";
                        if (font.bold())
                              s += "</b>";
                        }
                  }
            }

      s.replace(QChar(0xe10e), QString("<sym>accidentalNatural</sym>"));  //natural
      s.replace(QChar(0xe10c), QString("<sym>accidentalSharp</sym>"));    // sharp
      s.replace(QChar(0xe10d), QString("<sym>accidentalFlat</sym>"));     // flat
      s.replace(QChar(0xe104), QString("<sym>metNoteHalfUp</sym>")),      // note2_Sym
      s.replace(QChar(0xe105), QString("<sym>metNoteQuarterUp</sym>"));   // note4_Sym
      s.replace(QChar(0xe106), QString("<sym>metNote8thUp</sym>"));       // note8_Sym
      s.replace(QChar(0xe107), QString("<sym>metNote16thUp</sym>"));      // note16_Sym
      s.replace(QChar(0xe108), QString("<sym>metNote32ndUp</sym>"));      // note32_Sym
      s.replace(QChar(0xe109), QString("<sym>metNote64thUp</sym>"));      // note64_Sym
      s.replace(QChar(0xe10a), QString("<sym>metAugmentationDot</sym>")); // dot
      s.replace(QChar(0xe10b), QString("<sym>metAugmentationDot</sym><sym>space</sym><sym>metAugmentationDot</sym>"));    // dotdot
      s.replace(QChar(0xe167), QString("<sym>segno</sym>"));              // segno
      s.replace(QChar(0xe168), QString("<sym>coda</sym>"));               // coda
      s.replace(QChar(0xe169), QString("<sym>codaSquare</sym>"));         // varcoda
      return s;
      }


//---------------------------------------------------------
//   readTextProperties
//---------------------------------------------------------

static bool readTextProperties(XmlReader& e, TextBase* t, Element*)
      {
      const QStringRef& tag(e.name());
      if (tag == "style") {
            int i = e.readInt();
            Tid ss = Tid::DEFAULT;
            switch (i) {
                  case 2:  ss = Tid::TITLE;     break;
                  case 3:  ss = Tid::SUBTITLE;  break;
                  case 4:  ss = Tid::COMPOSER;  break;
                  case 5:  ss = Tid::POET;      break;

                  case 6:  ss = Tid::LYRICS_ODD;    break;
                  case 7:  ss = Tid::LYRICS_EVEN;    break;

                  case 8:  ss = Tid::FINGERING; break;
                  case 9:  ss = Tid::INSTRUMENT_LONG;    break;
                  case 10: ss = Tid::INSTRUMENT_SHORT;   break;
                  case 11: ss = Tid::INSTRUMENT_EXCERPT; break;

                  case 12: ss = Tid::DYNAMICS;  break;
                  case 13: ss = Tid::EXPRESSION;   break;
                  case 14: ss = Tid::TEMPO;     break;
                  case 15: ss = Tid::METRONOME; break;
                  case 16: ss = Tid::FOOTER;    break;  // TextStyleType::COPYRIGHT
                  case 17: ss = Tid::MEASURE_NUMBER; break;
                  case 18: ss = Tid::FOOTER; break;    // TextStyleType::PAGE_NUMBER_ODD
                  case 19: ss = Tid::FOOTER; break;    // TextStyleType::PAGE_NUMBER_EVEN
                  case 20: ss = Tid::TRANSLATOR; break;
                  case 21: ss = Tid::TUPLET;     break;

                  case 22: ss = Tid::SYSTEM;         break;
                  case 23: ss = Tid::STAFF;          break;
                  case 24: ss = Tid::HARMONY_A;        break;
                  case 25: ss = Tid::REHEARSAL_MARK; break;
                  case 26: ss = Tid::REPEAT_LEFT;         break;
                  case 27: ss = Tid::VOLTA;          break;
                  case 28: ss = Tid::FRAME;          break;
                  case 29: ss = Tid::TEXTLINE;       break;
                  case 30: ss = Tid::GLISSANDO;      break;
                  case 31: ss = Tid::STRING_NUMBER;  break;

                  case 32: ss = Tid::OTTAVA;  break;
//??                  case 33: ss = Tid::BENCH;   break;
                  case 34: ss = Tid::HEADER;  break;
                  case 35: ss = Tid::FOOTER;  break;
                  case 0:
                  default:
                        qDebug("style %d invalid", i);
                        ss = Tid::DEFAULT;
                        break;
                  }
            t->initTid(ss);
            }
      else if (tag == "subtype")
            e.skipCurrentElement();
      else if (tag == "html-data") {
            QString ss = e.readXml();
            QString s  = convertFromHtml(t, ss);
// qDebug("html-data <%s>", qPrintable(s));
            t->setXmlText(s);
            }
      else if (tag == "foregroundColor")  // same as "color" ?
            e.skipCurrentElement();
      else if (tag == "frame")
            t->setFrameType(e.readBool() ? FrameType::SQUARE : FrameType::NO_FRAME);
      else if (tag == "halign") {
            Align align = Align(int(t->align()) & int(~Align::HMASK));
            const QString& val(e.readElementText());
            if (val == "center")
                  align = align | Align::HCENTER;
            else if (val == "right")
                  align = align | Align::RIGHT;
            else if (val == "left")
                  ;
            else
                  qDebug("readText: unknown alignment: <%s>", qPrintable(val));
            t->setAlign(align);
            }
      else if (tag == "valign") {
            Align align = Align(int(t->align()) & int(~Align::VMASK));
            const QString& val(e.readElementText());
            if (val == "bottom")
                  align = align | Align::BOTTOM;
            else if (val == "top")
                  ;
            else if (val == "vcenter")
                  align = align | Align::VCENTER;
            else if (val == "baseline")
                  align = align | Align::BASELINE;
            else
                  qDebug("readText: unknown alignment: <%s>", qPrintable(val));
            t->setAlign(align);
            }
      else if (tag == "rxoffset") {       // TODO
            e.readElementText();
            }
      else if (tag == "ryoffset") {       // TODO
            e.readElementText();
            }
      else if (tag == "yoffset") {       // TODO
            e.readElementText();
            }
      else if (tag == "systemFlag") {       // TODO
            e.readElementText();
            }
      else if (!t->readProperties(e))
            return false;
      t->setOffset(QPointF());     // ignore user offsets
      t->setAutoplace(true);
      return true;
      }

//---------------------------------------------------------
//   readText114
//---------------------------------------------------------

static void readText114(XmlReader& e, TextBase* t, Element* be)
      {
      while (e.readNextStartElement()) {
            if (!readTextProperties(e, t, be))
                  e.unknown();
            }
      }

//---------------------------------------------------------
//   readAccidental
//---------------------------------------------------------

static void readAccidental(Accidental* a, XmlReader& e)
      {
      while (e.readNextStartElement()) {
            const QStringRef& tag(e.name());
            if (tag == "bracket") {
                  int i = e.readInt();
                  if (i == 0 || i == 1)
                        a->setBracket(AccidentalBracket(i));
                  }
            else if (tag == "subtype") {
                  QString text(e.readElementText());
                  bool isInt;
                  int i = text.toInt(&isInt);
                  if (isInt) {
                        a->setBracket(i & 0x8000 ? AccidentalBracket::PARENTHESIS : AccidentalBracket::BRACKET);
                        i &= ~0x8000;
                        AccidentalType at;
                        switch (i) {
                              case 0:
                                    at = AccidentalType::NONE;
                                    break;
                              case 6:
                                    a->setBracket(AccidentalBracket::PARENTHESIS);
                                    // fall through
                              case 1:
                              case 11:
                                    at = AccidentalType::SHARP;
                                    break;
                              case 7:
                                    a->setBracket(AccidentalBracket::PARENTHESIS);
                                    // fall through
                              case 2:
                              case 12:
                                    at = AccidentalType::FLAT;
                                    break;
                              case 8:
                                    a->setBracket(AccidentalBracket::PARENTHESIS);
                                    // fall through
                              case 3:
                              case 13:
                                    at = AccidentalType::SHARP2;
                                    break;
                              case 9:
                                    a->setBracket(AccidentalBracket::PARENTHESIS);
                                    // fall through
                              case 4:
                              case 14:
                                    at = AccidentalType::FLAT2;
                                    break;
                              case 10:
                                    a->setBracket(AccidentalBracket::PARENTHESIS);
                                    // fall through
                              case 5:
                              case 15:
                                    at = AccidentalType::NATURAL;
                                    break;
                              case 16:
                                    at = AccidentalType::FLAT_SLASH;
                                    break;
                              case 17:
                                    at = AccidentalType::FLAT_SLASH2;
                                    break;
                              case 18:
                                    at = AccidentalType::MIRRORED_FLAT2;
                                    break;
                              case 19:
                                    at = AccidentalType::MIRRORED_FLAT;
                                    break;
                              case 20:
                                    at = AccidentalType::NONE;//AccidentalType::MIRRORED_FLAT_SLASH;
                                    break;
                              case 21:
                                    at = AccidentalType::NONE;//AccidentalType::FLAT_FLAT_SLASH;
                                    break;
                              case 22:
                                    at = AccidentalType::SHARP_SLASH;
                                    break;
                              case 23:
                                    at = AccidentalType::SHARP_SLASH2;
                                    break;
                              case 24:
                                    at = AccidentalType::SHARP_SLASH3;
                                    break;
                              case 25:
                                    at = AccidentalType::SHARP_SLASH4;
                                    break;
                              case 26:
                                    at = AccidentalType::SHARP_ARROW_UP;
                                    break;
                              case 27:
                                    at = AccidentalType::SHARP_ARROW_DOWN;
                                    break;
                              case 28:
                                    at = AccidentalType::NONE;//AccidentalType::SHARP_ARROW_BOTH;
                                    break;
                              case 29:
                                    at = AccidentalType::FLAT_ARROW_UP;
                                    break;
                              case 30:
                                    at = AccidentalType::FLAT_ARROW_DOWN;
                                    break;
                              case 31:
                                    at = AccidentalType::NONE;//AccidentalType::FLAT_ARROW_BOTH;
                                    break;
                              case 32:
                                    at = AccidentalType::NATURAL_ARROW_UP;
                                    break;
                              case 33:
                                    at = AccidentalType::NATURAL_ARROW_DOWN;
                                    break;
                              case 34:
                                    at = AccidentalType::NONE;//AccidentalType::NATURAL_ARROW_BOTH;
                                    break;
                              default:
                                    at = AccidentalType::NONE;
                                    break;
                              }
                        a->setAccidentalType(at);
                        }
                  else {
                        const static std::map<QString, AccidentalType> accMap = {
                           {"none", AccidentalType::NONE}, {"sharp", AccidentalType::SHARP},
                           {"flat", AccidentalType::FLAT}, {"natural", AccidentalType::NATURAL},
                           {"double sharp", AccidentalType::SHARP2}, {"double flat", AccidentalType::FLAT2},
                           {"flat-slash", AccidentalType::FLAT_SLASH}, {"flat-slash2", AccidentalType::FLAT_SLASH2},
                           {"mirrored-flat2", AccidentalType::MIRRORED_FLAT2}, {"mirrored-flat", AccidentalType::MIRRORED_FLAT},
                           {"sharp-slash", AccidentalType::SHARP_SLASH}, {"sharp-slash2", AccidentalType::SHARP_SLASH2},
                           {"sharp-slash3", AccidentalType::SHARP_SLASH3}, {"sharp-slash4", AccidentalType::SHARP_SLASH4},
                           {"sharp arrow up", AccidentalType::SHARP_ARROW_UP}, {"sharp arrow down", AccidentalType::SHARP_ARROW_DOWN},
                           {"flat arrow up", AccidentalType::FLAT_ARROW_UP}, {"flat arrow down", AccidentalType::FLAT_ARROW_DOWN},
                           {"natural arrow up", AccidentalType::NATURAL_ARROW_UP}, {"natural arrow down", AccidentalType::NATURAL_ARROW_DOWN},
                           {"sori", AccidentalType::SORI}, {"koron", AccidentalType::KORON}
                        };
                        auto it = accMap.find(text);
                        if (it == accMap.end()) {
                              qDebug("invalid type %s", qPrintable(text));
                              a->setAccidentalType(AccidentalType::NONE);
                              }
                        else
                              a->setAccidentalType(it->second);
                        }
                  }
            else if (tag == "role") {
                  AccidentalRole r = AccidentalRole(e.readInt());
                  if (r == AccidentalRole::AUTO || r == AccidentalRole::USER)
                        a->setRole(r);
                  }
            else if (tag == "small")
                  a->setSmall(e.readInt());
            else if (tag == "offset")
                  e.skipCurrentElement(); // ignore manual layout in older scores
            else if (a->Element::readProperties(e))
                  ;
            else
                  e.unknown();
            }
      }

//---------------------------------------------------------
//   convertHeadGroup
//---------------------------------------------------------

static NoteHead::Group convertHeadGroup(int i)
      {
      NoteHead::Group val;
      switch (i) {
            case 1:
                  val = NoteHead::Group::HEAD_CROSS;
                  break;
            case 2:
                  val = NoteHead::Group::HEAD_DIAMOND;
                  break;
            case 3:
                  val = NoteHead::Group::HEAD_TRIANGLE_DOWN;
                  break;
            case 4:
                  val = NoteHead::Group::HEAD_MI;
                  break;
            case 5:
                  val = NoteHead::Group::HEAD_SLASH;
                  break;
            case 6:
                  val = NoteHead::Group::HEAD_XCIRCLE;
                  break;
            case 7:
                  val = NoteHead::Group::HEAD_DO;
                  break;
            case 8:
                  val = NoteHead::Group::HEAD_RE;
                  break;
            case 9:
                  val = NoteHead::Group::HEAD_FA;
                  break;
            case 10:
                  val = NoteHead::Group::HEAD_LA;
                  break;
            case 11:
                  val = NoteHead::Group::HEAD_TI;
                  break;
            case 12:
                  val = NoteHead::Group::HEAD_SOL;
                  break;
            case 13:
                  val = NoteHead::Group::HEAD_BREVIS_ALT;
                  break;
            default:
                  val = NoteHead::Group::HEAD_NORMAL;
            }
      return val;
      }


//---------------------------------------------------------
//   readFingering114
//---------------------------------------------------------

static void readFingering114(XmlReader& e, Fingering* fing)
      {
      bool isStringNumber = false;
      while (e.readNextStartElement()) {
            const QStringRef& tag(e.name());

            if (tag == "html-data") {
                  auto htmlDdata = QTextDocumentFragment::fromHtml(e.readXml()).toPlainText();
                  htmlDdata.replace(" ", "");
                  fing->setPlainText(htmlDdata);
                  }
            else if (tag == "subtype") {
                  auto subtype = e.readElementText();
                  if (subtype == "StringNumber") {
                        isStringNumber = true;
                        fing->setProperty(Pid::SUB_STYLE, QVariant(10));
                        fing->setPropertyFlags(Pid::SUB_STYLE, PropertyFlags::UNSTYLED);
                        }
                  }
            else if (tag == "frame") {
                  auto frame = e.readInt();
                  if (frame)
                        if (isStringNumber) //default value is circle for stringnumber, square is setted in tag circle
                              fing->setFrameType(FrameType::CIRCLE);
                        else //default value is square for stringnumber, circle is setted in tag circle
                              fing->setFrameType(FrameType::SQUARE);
                  else
                        fing->setFrameType(FrameType::NO_FRAME);
                  }
            else if (tag == "circle") {
                  auto circle = e.readInt();
                  if (circle)
                        fing->setFrameType(FrameType::CIRCLE);
                  else
                        fing->setFrameType(FrameType::SQUARE);
                  }
            else {
                  e.skipCurrentElement();
                  }
            }
      }

//---------------------------------------------------------
//   readNote
//---------------------------------------------------------

static void readNote(Note* note, XmlReader& e)
      {
      e.hasAccidental = false;                     // used for userAccidental backward compatibility

      note->setTpc1(Tpc::TPC_INVALID);
      note->setTpc2(Tpc::TPC_INVALID);

      if (e.hasAttribute("pitch"))                   // obsolete
            note->setPitch(e.intAttribute("pitch"));
      if (e.hasAttribute("tpc"))                     // obsolete
            note->setTpc1(e.intAttribute("tpc"));

      while (e.readNextStartElement()) {
            const QStringRef& tag(e.name());
            if (tag == "Accidental") {
                  // on older scores, a note could have both a <userAccidental> tag and an <Accidental> tag
                  // if a userAccidental has some other property set (like for instance offset)
                  Accidental* a;
                  if (e.hasAccidental)            // if the other tag has already been read,
                        a = note->accidental();        // re-use the accidental it constructed
                  else
                        a = new Accidental(note->score());
                  // the accidental needs to know the properties of the
                  // track it belongs to (??)
                  a->setTrack(note->track());
                  readAccidental(a, e);
                  if (!e.hasAccidental)          // only the new accidental, if it has been added previously
                        note->add(a);
                  e.hasAccidental = true;   // we now have an accidental
                  }
            else if (tag == "Text") {
                  Fingering* f = new Fingering(note->score());
                  readFingering114(e, f);
                  note->add(f);
                  }
            else if (tag == "onTimeType") {
                  if (e.readElementText() == "offset")
                        note->setOnTimeType(2);
                  else
                        note->setOnTimeType(1);
                  }
            else if (tag == "offTimeType") {
                  if (e.readElementText() == "offset")
                        note->setOffTimeType(2);
                  else
                        note->setOffTimeType(1);
                  }
            else if (tag == "onTimeOffset") {
                  if (note->onTimeType() == 1)
                        note->setOnTimeOffset(e.readInt() * 1000 / note->chord()->actualTicks().ticks());
                  else
                        note->setOnTimeOffset(e.readInt() * 10);
                  }
            else if (tag == "offTimeOffset") {
                  if (note->offTimeType() == 1)
                        note->setOffTimeOffset(1000 + (e.readInt() * 1000 / note->chord()->actualTicks().ticks()));
                  else
                        note->setOffTimeOffset(1000 + (e.readInt() * 10));
                  }
            else if (tag == "userAccidental") {
                  QString val(e.readElementText());
                  bool ok;
                  int k = val.toInt(&ok);
                  if (ok) {
                        // on older scores, a note could have both a <userAccidental> tag and an <Accidental> tag
                        // if a userAccidental has some other property set (like for instance offset)
                        // only construct a new accidental, if the other tag has not been read yet
                        // (<userAccidental> tag is only used in older scores: no need to check the score mscVersion)
                        if (!e.hasAccidental) {
                              Accidental* a = new Accidental(note->score());
                              note->add(a);
                              }
                        // TODO: for backward compatibility
                        bool bracket = k & 0x8000;
                        k &= 0xfff;
                        AccidentalType at = AccidentalType::NONE;
                        switch(k) {
                              case 0: at = AccidentalType::NONE; break;
                              case 1: at = AccidentalType::SHARP; break;
                              case 2: at = AccidentalType::FLAT; break;
                              case 3: at = AccidentalType::SHARP2; break;
                              case 4: at = AccidentalType::FLAT2; break;
                              case 5: at = AccidentalType::NATURAL; break;

                              case 6: at = AccidentalType::FLAT_SLASH; break;
                              case 7: at = AccidentalType::FLAT_SLASH2; break;
                              case 8: at = AccidentalType::MIRRORED_FLAT2; break;
                              case 9: at = AccidentalType::MIRRORED_FLAT; break;
                              case 10: at = AccidentalType::NONE; break; // AccidentalType::MIRRORED_FLAT_SLASH
                              case 11: at = AccidentalType::NONE; break; // AccidentalType::FLAT_FLAT_SLASH

                              case 12: at = AccidentalType::SHARP_SLASH; break;
                              case 13: at = AccidentalType::SHARP_SLASH2; break;
                              case 14: at = AccidentalType::SHARP_SLASH3; break;
                              case 15: at = AccidentalType::SHARP_SLASH4; break;

                              case 16: at = AccidentalType::SHARP_ARROW_UP; break;
                              case 17: at = AccidentalType::SHARP_ARROW_DOWN; break;
                              case 18: at = AccidentalType::NONE; break; // AccidentalType::SHARP_ARROW_BOTH
                              case 19: at = AccidentalType::FLAT_ARROW_UP; break;
                              case 20: at = AccidentalType::FLAT_ARROW_DOWN; break;
                              case 21: at = AccidentalType::NONE; break; // AccidentalType::FLAT_ARROW_BOTH
                              case 22: at = AccidentalType::NATURAL_ARROW_UP; break;
                              case 23: at = AccidentalType::NATURAL_ARROW_DOWN; break;
                              case 24: at = AccidentalType::NONE; break; // AccidentalType::NATURAL_ARROW_BOTH
                              case 25: at = AccidentalType::SORI; break;
                              case 26: at = AccidentalType::KORON; break;
                              }
                        note->accidental()->setAccidentalType(at);

                        note->accidental()->setBracket(AccidentalBracket(bracket));

                        note->accidental()->setRole(AccidentalRole::USER);
                        e.hasAccidental = true;   // we now have an accidental
                        }
                  }
            else if (tag == "offset")
                  e.skipCurrentElement(); // ignore manual layout in older scores
            else if (tag == "move")
                  note->chord()->setStaffMove(e.readInt());
            else if (tag == "head") {
                  int i = e.readInt();
                  NoteHead::Group val = convertHeadGroup(i);
                  note->setHeadGroup(val);
                  }
            else if (tag == "headType") {
                  int i = e.readInt();
                  NoteHead::Type val;
                  switch (i) {
                        case 1:
                              val = NoteHead::Type::HEAD_WHOLE;
                              break;
                        case 2:
                              val = NoteHead::Type::HEAD_HALF;
                              break;
                        case 3:
                              val = NoteHead::Type::HEAD_QUARTER;
                              break;
                        case 4:
                              val = NoteHead::Type::HEAD_BREVIS;
                              break;
                        default:
                              val = NoteHead::Type::HEAD_AUTO;
                        }
                  note->setHeadType(val);
                  }
            else if (readNoteProperties206(note, e))
                  ;
            else
                  e.unknown();
            }
      // ensure sane values:
      note->setPitch(limit(note->pitch(), 0, 127));

      if (note->concertPitch())
            note->setTpc2(Tpc::TPC_INVALID);
      else {
            note->setPitch(note->pitch() + note->transposition());
            note->setTpc2(note->tpc1());
            note->setTpc1(Tpc::TPC_INVALID);
            }
      if (!tpcIsValid(note->tpc1()) && !tpcIsValid(note->tpc2())) {
            Key key = (note->staff() && note->chord()) ? note->staff()->key(note->chord()->tick()) : Key::C;
            int tpc = pitch2tpc(note->pitch(), key, Prefer::NEAREST);
            if (note->concertPitch())
                  note->setTpc1(tpc);
            else
                  note->setTpc2(tpc);
            }
      if (!(tpcIsValid(note->tpc1()) && tpcIsValid(note->tpc2()))) {
            Fraction tick = note->chord() ? note->chord()->tick() : Fraction(-1,1);
            Interval v = note->staff() ? note->part()->instrument(tick)->transpose() : Interval();
            if (tpcIsValid(note->tpc1())) {
                  v.flip();
                  if (v.isZero())
                        note->setTpc2(note->tpc1());
                  else
                        note->setTpc2(Ms::transposeTpc(note->tpc1(), v, true));
                  }
            else {
                  if (v.isZero())
                        note->setTpc1(note->tpc2());
                  else
                        note->setTpc1(Ms::transposeTpc(note->tpc2(), v, true));
                  }
            }

      // check consistency of pitch, tpc1, tpc2, and transposition
      // see note in InstrumentChange::read() about a known case of tpc corruption produced in 2.0.x
      // but since there are other causes of tpc corruption (eg, https://musescore.org/en/node/74746)
      // including perhaps some we don't know about yet,
      // we will attempt to fix some problems here regardless of version

      if (!e.pasteMode() && !MScore::testMode) {
            int tpc1Pitch = (tpc2pitch(note->tpc1()) + 12) % 12;
            int tpc2Pitch = (tpc2pitch(note->tpc2()) + 12) % 12;
            int concertPitch = note->pitch() % 12;
            if (tpc1Pitch != concertPitch) {
                  qDebug("bad tpc1 - concertPitch = %d, tpc1 = %d", concertPitch, tpc1Pitch);
                  note->setPitch(note->pitch() + tpc1Pitch - concertPitch);
                  }
            Interval v = note->staff()->part()->instrument(e.tick())->transpose();
            int transposedPitch = (note->pitch() - v.chromatic) % 12;
            if (tpc2Pitch != transposedPitch) {
                  qDebug("bad tpc2 - transposedPitch = %d, tpc2 = %d", transposedPitch, tpc2Pitch);
                  // just in case the staff transposition info is not reliable here,
                  v.flip();
                  note->setTpc2(Ms::transposeTpc(note->tpc1(), v, true));
                  }
            }
      }

//---------------------------------------------------------
//   readClefType
//---------------------------------------------------------

static ClefType readClefType(const QString& s)
      {
      ClefType ct = ClefType::G;
      bool ok;
      int i = s.toInt(&ok);
      if (ok) {
            // convert obsolete old coding
            switch (i) {
                  default:
                  case  0: ct = ClefType::G; break;
                  case  1: ct = ClefType::G8_VA; break;
                  case  2: ct = ClefType::G15_MA; break;
                  case  3: ct = ClefType::G8_VB; break;
                  case  4: ct = ClefType::F; break;
                  case  5: ct = ClefType::F8_VB; break;
                  case  6: ct = ClefType::F15_MB; break;
                  case  7: ct = ClefType::F_B; break;
                  case  8: ct = ClefType::F_C; break;
                  case  9: ct = ClefType::C1; break;
                  case 10: ct = ClefType::C2; break;
                  case 11: ct = ClefType::C3; break;
                  case 12: ct = ClefType::C4; break;
                  case 13: ct = ClefType::TAB; break;
                  case 14: ct = ClefType::PERC; break;
                  case 15: ct = ClefType::C5; break;
                  case 16: ct = ClefType::G_1; break;
                  case 17: ct = ClefType::F_8VA; break;
                  case 18: ct = ClefType::F_15MA; break;
                  case 19: ct = ClefType::PERC; break;      // PERC2 no longer supported
                  case 20: ct = ClefType::TAB_SERIF; break;
                  }
            }
      return ct;
      }

//---------------------------------------------------------
//   readClef
//---------------------------------------------------------

static void readClef(Clef* clef, XmlReader& e)
      {
      while (e.readNextStartElement()) {
            const QStringRef& tag(e.name());
            if (tag == "subtype")
                  clef->setClefType(readClefType(e.readElementText()));
            else if (!clef->readProperties(e))
                  e.unknown();
            }
      if (clef->clefType() == ClefType::INVALID)
            clef->setClefType(ClefType::G);
      }

//---------------------------------------------------------
//   readTuplet
//---------------------------------------------------------

static void readTuplet(Tuplet* tuplet, XmlReader& e)
      {
      int bl = -1;
      tuplet->setId(e.intAttribute("id", 0));

      while (e.readNextStartElement()) {
            const QStringRef& tag(e.name());
            if (tag == "subtype")    // obsolete
                  e.skipCurrentElement();
            else if (tag == "hasNumber")  // obsolete even in 1.3
                  tuplet->setNumberType(e.readInt() ? TupletNumberType::SHOW_NUMBER : TupletNumberType::NO_TEXT);
            else if (tag == "hasLine") {  // obsolete even in 1.3
                  tuplet->setHasBracket(e.readInt());
                  tuplet->setBracketType(TupletBracketType::AUTO_BRACKET);
                  }
            else if (tag == "baseLen")    // obsolete even in 1.3
                  bl = e.readInt();
            else if (tag == "tick")
                  tuplet->setTick(Fraction::fromTicks(e.readInt()));
            else if (!readTupletProperties206(e, tuplet))
                  e.unknown();
            }
      Fraction r = (tuplet->ratio() == Fraction(1,1)) ? tuplet->ratio() : tuplet->ratio().reduced();
      // this may be wrong, but at this stage it is kept for compatibility. It will be corrected afterwards
      // during "sanitize" step
      Fraction f(r.denominator(), tuplet->baseLen().fraction().denominator());
      tuplet->setTicks(f.reduced());
      if (bl != -1) {         // obsolete, even in 1.3
            TDuration d;
            d.setVal(bl);
            tuplet->setBaseLen(d);
            d.setVal(bl * tuplet->ratio().denominator());
            tuplet->setTicks(d.fraction());
            }
      }

//---------------------------------------------------------
//   readTremolo
//---------------------------------------------------------

static void readTremolo(Tremolo* tremolo, XmlReader& e)
      {
      enum class OldTremoloType : char {
            OLD_R8 = 0,
            OLD_R16,
            OLD_R32,
            OLD_C8,
            OLD_C16,
            OLD_C32
            };
      while (e.readNextStartElement()) {
            if (e.name() == "subtype") {
                  OldTremoloType sti = OldTremoloType(e.readElementText().toInt());
                  TremoloType st;
                  switch (sti) {
                        default:
                        case OldTremoloType::OLD_R8:  st = TremoloType::R8;  break;
                        case OldTremoloType::OLD_R16: st = TremoloType::R16; break;
                        case OldTremoloType::OLD_R32: st = TremoloType::R32; break;
                        case OldTremoloType::OLD_C8:  st = TremoloType::C8;  break;
                        case OldTremoloType::OLD_C16: st = TremoloType::C16; break;
                        case OldTremoloType::OLD_C32: st = TremoloType::C32; break;
                        }
                  tremolo->setTremoloType(st);
                  }
            else if (!tremolo->Element::readProperties(e))
                  e.unknown();
            }
      }

//---------------------------------------------------------
//   readChord
//---------------------------------------------------------

static void readChord(Measure* m, Chord* chord, XmlReader& e)
      {
      while (e.readNextStartElement()) {
            const QStringRef& tag(e.name());
            if (tag == "Note") {
                  Note* note = new Note(chord->score());
                  // the note needs to know the properties of the track it belongs to
                  note->setTrack(chord->track());
                  note->setChord(chord);
                  readNote(note, e);
                  chord->add(note);
                  }
            else if (tag == "Attribute" || tag == "Articulation") {
                  Element* el = readArticulation(chord, e);
                  if (el->isFermata()) {
                        if (!chord->segment())
                              chord->setParent(m->getSegment(SegmentType::ChordRest, e.tick()));
                        chord->segment()->add(el);
                        }
                  else
                        chord->add(el);
                  }
            else if (tag == "Tremolo") {
                  Tremolo* tremolo = new Tremolo(chord->score());
                  tremolo->setDurationType(chord->durationType());
                  chord->setTremolo(tremolo);
                  tremolo->setTrack(chord->track());
                  readTremolo(tremolo, e);
                  tremolo->setParent(chord);
                  }
            else if (readChordProperties206(e, chord))
                  ;
            else
                  e.unknown();
            }
      }

//---------------------------------------------------------
//   readRest
//---------------------------------------------------------

static void readRest(Measure* m, Rest* rest, XmlReader& e)
      {
      while (e.readNextStartElement()) {
            const QStringRef& tag(e.name());
            if (tag == "Attribute" || tag == "Articulation") {
                  Element* el = readArticulation(rest, e);
                  if (el->isFermata()) {
                        if (!rest->segment())
                              rest->setParent(m->getSegment(SegmentType::ChordRest, e.tick()));
                        rest->segment()->add(el);
                        }
                  else
                        rest->add(el);
                  }
            else if (readChordRestProperties206(e, rest))
                  ;
            else
                  e.unknown();
            }
      }

//---------------------------------------------------------
//   readTempoText
//---------------------------------------------------------

void readTempoText(TempoText* t, XmlReader& e)
      {
      while (e.readNextStartElement()) {
            const QStringRef& tag(e.name());
            if (tag == "tempo")
                  t->setTempo(e.readDouble());
            else if (!readTextProperties(e, t, t))
                  e.unknown();
            }
      }

//---------------------------------------------------------
//   readStaffText
//---------------------------------------------------------

void readStaffText(StaffText* t, XmlReader& e)
      {
      while (e.readNextStartElement()) {
            if (!readTextProperties(e, t, t))
                  e.unknown();
            }
      }

//---------------------------------------------------------
//   readLineSegment114
//---------------------------------------------------------

static void readLineSegment114(XmlReader& e, LineSegment* ls)
      {
      while (e.readNextStartElement()) {
            const QStringRef& tag(e.name());
            if (tag == "off1")
                  ls->setOffset(e.readPoint() * ls->spatium());
            else
                  ls->readProperties(e);
            }
      }

//---------------------------------------------------------
//   readTextLineProperties114
//---------------------------------------------------------

static bool readTextLineProperties114(XmlReader& e, TextLineBase* tl)
      {
      const QStringRef& tag(e.name());

      if (tag == "beginText") {
            Text* text = new Text(tl->score());
            readText114(e, text, tl);
            tl->setBeginText(text->xmlText());
            tl->setPropertyFlags(Pid::BEGIN_TEXT, PropertyFlags::UNSTYLED);
            delete text;
            }
      else if (tag == "continueText") {
            Text* text = new Text(tl->score());
            readText114(e, text, tl);
            tl->setContinueText(text->xmlText());
            tl->setPropertyFlags(Pid::CONTINUE_TEXT, PropertyFlags::UNSTYLED);
            delete text;
            }
      else if (tag == "endText") {
            Text* text = new Text(tl->score());
            readText114(e, text, tl);
            tl->setEndText(text->xmlText());
            tl->setPropertyFlags(Pid::END_TEXT, PropertyFlags::UNSTYLED);
            delete text;
            }
      else if (tag == "beginHook")
            tl->setBeginHookType(e.readBool() ? HookType::HOOK_90 : HookType::NONE);
      else if (tag == "endHook")
            tl->setEndHookType(e.readBool() ? HookType::HOOK_90 : HookType::NONE);
      else if (tag == "beginHookType")
            tl->setBeginHookType(e.readInt() == 0 ? HookType::HOOK_90 : HookType::HOOK_45);
      else if (tag == "endHookType")
            tl->setEndHookType(e.readInt() == 0 ? HookType::HOOK_90 : HookType::HOOK_45);
      else if (tag == "Segment") {
            LineSegment* ls = tl->createLineSegment();
            ls->setTrack(tl->track()); // needed in read to get the right staff mag
            readLineSegment114(e, ls);
            // in v1.x "visible" is a property of the segment only;
            // we must ensure that it propagates also to the parent element.
            // That's why the visibility is set after adding the segment
            // to the corresponding spanner
            ls->setVisible(ls->visible());
            ls->setOffset(QPointF());        // ignore offsets
            ls->setAutoplace(true);
            tl->add(ls);
            }
      else if (tl->readProperties(e))
            return true;
      return true;
      }

//---------------------------------------------------------
//   readVolta114
//---------------------------------------------------------

static void readVolta114(XmlReader& e, Volta* volta)
      {
      while (e.readNextStartElement()) {
            const QStringRef& tag(e.name());
            if (tag == "endings") {
                  QString s = e.readElementText();
                  QStringList sl = s.split(",", QString::SkipEmptyParts);
                  volta->endings().clear();
                  for (const QString& l : sl) {
                        int i = l.simplified().toInt();
                        volta->endings().append(i);
                        }
                  }
            else if (tag == "subtype") {
                  e.readInt();    // TODO
                  }
            else if (tag == "lineWidth") {
                  volta->setLineWidth(e.readDouble() * volta->spatium());
                  volta->setPropertyFlags(Pid::LINE_WIDTH, PropertyFlags::UNSTYLED);
                  }
            else if (!readTextLineProperties114(e, volta))
                  e.unknown();
            }
      volta->setOffset(QPointF());        // ignore offsets
      volta->setAutoplace(true);
      }

//---------------------------------------------------------
//   readOttava114
//---------------------------------------------------------

static void readOttava114(XmlReader& e, Ottava* ottava)
      {
      while (e.readNextStartElement()) {
            const QStringRef& tag(e.name());
            if (tag == "subtype") {
                  QString s = e.readElementText();
                  bool ok;
                  int idx = s.toInt(&ok);
                  if (!ok) {
                        idx = int(OttavaType::OTTAVA_8VA);
                        for (unsigned i = 0; i < sizeof(ottavaDefault)/sizeof(*ottavaDefault); ++i) {
                              if (s == ottavaDefault[i].name) {
                                    idx = i;
                                    break;
                                    }
                              }
                        }
                  //subtype are now in a different order...
                  if (idx == 1)
                        idx = 2;
                  else if (idx == 2)
                        idx = 1;
                  ottava->setOttavaType(OttavaType(idx));
                  }
            else if (tag == "numbersOnly")
                  ottava->setNumbersOnly(e.readInt());
            else if (tag == "lineWidth")
                  ottava->readProperty(e, Pid::LINE_WIDTH);
            else if (tag == "lineStyle")
                  ottava->readProperty(e, Pid::LINE_STYLE);
            else if (tag == "beginSymbol") {                      // obsolete
                  }
            else if (tag == "continueSymbol") {                   // obsolete
                  }
            else if (!readTextLineProperties114(e, ottava))
                  e.unknown();
            }
      }

//---------------------------------------------------------
//   resolveSymCompatibility
//---------------------------------------------------------

static QString resolveSymCompatibility(SymId i, QString programVersion)
      {
      if (!programVersion.isEmpty() && programVersion < "1.1")
            i = SymId(int(i) + 5);
      switch (int(i)) {
            case 197:
                  return "keyboardPedalPed";
            case 191:
                  return "keyboardPedalUp";
            case 193:
                  return "noSym"; //SymId(pedaldotSym);
            case 192:
                  return "noSym"; //SymId(pedaldashSym);
            case 139:
                  return "ornamentTrill";
            default:
                  return "noSym";
          }
      }

//---------------------------------------------------------
//   readTextLine114
//---------------------------------------------------------

static void readTextLine114(XmlReader& e, TextLine* textLine)
      {
      while (e.readNextStartElement()) {
            const QStringRef& tag(e.name());

            if (tag == "lineVisible")
                  textLine->setLineVisible(e.readBool());
            else if (tag == "beginHookHeight") {
                  textLine->setBeginHookHeight(Spatium(e.readDouble()));
                  }
            else if (tag == "endHookHeight" || tag == "hookHeight") { // hookHeight is obsolete
                  textLine->setEndHookHeight(Spatium(e.readDouble()));
                  textLine->setPropertyFlags(Pid::END_HOOK_HEIGHT, PropertyFlags::UNSTYLED);
                  }
            else if (tag == "hookUp") // obsolete
                  textLine->setEndHookHeight(Spatium(qreal(-1.0)));
            else if (tag == "beginSymbol" || tag == "symbol") { // "symbol" is obsolete
                  QString text(e.readElementText());
                  textLine->setBeginText(QString("<sym>%1</sym>").arg(
                        text[0].isNumber()
                              ? resolveSymCompatibility(SymId(text.toInt()), textLine->score()->mscoreVersion())
                              : text));
                  }
            else if (tag == "continueSymbol") {
                  QString text(e.readElementText());
                  textLine->setContinueText(QString("<sym>%1</sym>").arg(
                        text[0].isNumber()
                              ? resolveSymCompatibility(SymId(text.toInt()), textLine->score()->mscoreVersion())
                              : text));
                  }
            else if (tag == "endSymbol") {
                  QString text(e.readElementText());
                  textLine->setEndText(QString("<sym>%1</sym>").arg(
                        text[0].isNumber()
                              ? resolveSymCompatibility(SymId(text.toInt()), textLine->score()->mscoreVersion())
                              : text));
                  }
            else if (tag == "beginSymbolOffset") // obsolete
                  e.readPoint();
            else if (tag == "continueSymbolOffset") // obsolete
                  e.readPoint();
            else if (tag == "endSymbolOffset") // obsolete
                  e.readPoint();
            else if (tag == "beginTextPlace")
                  textLine->setBeginTextPlace(readPlacement(e));
            else if (tag == "continueTextPlace")
                  textLine->setContinueTextPlace(readPlacement(e));
            else if (tag == "endTextPlace")
                  textLine->setEndTextPlace(readPlacement(e));
            else if (!readTextLineProperties114(e, textLine))
                e.unknown();
            }
      }

//---------------------------------------------------------
//   readPedal114
//---------------------------------------------------------

static void readPedal114(XmlReader& e, Pedal* pedal)
      {
      while (e.readNextStartElement()) {
            const QStringRef& tag(e.name());
            if (tag == "beginSymbol"
                  || tag == "beginSymbolOffset"
                  || tag == "endSymbol"
                  || tag == "endSymbolOffset"
                  || tag == "subtype"
                  )
                  e.skipCurrentElement();
            else if (tag == "endHookHeight" || tag == "hookHeight") { // hookHeight is obsolete
                  pedal->setEndHookHeight(Spatium(e.readDouble()));
                  pedal->setPropertyFlags(Pid::END_HOOK_HEIGHT, PropertyFlags::UNSTYLED);
                  }
            else if (tag == "lineWidth") {
                  pedal->setLineWidth(qreal(e.readDouble()));
                  pedal->setPropertyFlags(Pid::LINE_WIDTH, PropertyFlags::UNSTYLED);
                  }
            else if (tag == "lineStyle") {
                  pedal->setLineStyle(Qt::PenStyle(e.readInt()));
                  pedal->setPropertyFlags(Pid::LINE_STYLE, PropertyFlags::UNSTYLED);
                  }
            else if (!readTextLineProperties114(e, pedal))
                  e.unknown();
            }
      pedal->setBeginText("<sym>keyboardPedalPed</sym>");
      }

//---------------------------------------------------------
//   readHarmony114
//---------------------------------------------------------

static void readHarmony114(XmlReader& e, Harmony* h)
      {
      // convert table to tpc values
      static const int table[] = {
            14, 9, 16, 11, 18, 13, 8, 15, 10, 17, 12, 19
            };

      while (e.readNextStartElement()) {
            const QStringRef& tag(e.name());
            if (tag == "base") {
                  if (h->score()->mscVersion() >= 106)
                        h->setBaseTpc(e.readInt());
                  else
                        h->setBaseTpc(table[e.readInt()-1]);
                  }
            else if (tag == "baseCase")
                  h->setBaseCase(static_cast<NoteCaseType>(e.readInt()));
            else if (tag == "extension")
                  h->setId(e.readInt());
            else if (tag == "name")
                  h->setTextName(e.readElementText());
            else if (tag == "root") {
                  if (h->score()->mscVersion() >= 106)
                        h->setRootTpc(e.readInt());
                  else
                        h->setRootTpc(table[e.readInt()-1]);
                  }
            else if (tag == "rootCase")
                  h->setRootCase(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")
                              h->addDegree(HDegree(degreeValue, degreeAlter, HDegreeType::ADD));
                        else if (degreeType == "alter")
                              h->addDegree(HDegree(degreeValue, degreeAlter, HDegreeType::ALTER));
                        else if (degreeType == "subtract")
                              h->addDegree(HDegree(degreeValue, degreeAlter, HDegreeType::SUBTRACT));
                        }
                  }
            else if (tag == "leftParen") {
                  h->setLeftParen(true);
                  e.readNext();
                  }
            else if (tag == "rightParen") {
                  h->setRightParen(true);
                  e.readNext();
                  }
            else if (!readTextProperties(e, h, h))
                  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 (h->rootTpc() != Tpc::TPC_INVALID) {
            if (h->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
                  h->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
                  h->getDescription(h->hTextName());
                  }
            }
      else if (h->hTextName() == "") {
            // 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
//            h->createLayout();
            QString s = h->plainText();
            if (!s.isEmpty()) {
                  h->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)
      h->render();
      }

//---------------------------------------------------------
//   readMeasure
//---------------------------------------------------------

static void readMeasure(Measure* m, int staffIdx, XmlReader& e)
      {
      Segment* segment = 0;
      qreal _spatium = m->spatium();

      QList<Chord*> graceNotes;

      //sort tuplet elements. needed for nested tuplets #22537
      for (Tuplet* t : e.tuplets())
            t->sortElements();
      e.tuplets().clear();
      e.setTrack(staffIdx * VOICES);

      m->createStaves(staffIdx);

      // tick is obsolete
      if (e.hasAttribute("tick"))
            e.setTick(Fraction::fromTicks(m->score()->fileDivision(e.intAttribute("tick"))));

      if (e.hasAttribute("len")) {
            QStringList sl = e.attribute("len").split('/');
            if (sl.size() == 2)
                  m->setTicks(Fraction(sl[0].toInt(), sl[1].toInt()));
            else
                  qDebug("illegal measure size <%s>", qPrintable(e.attribute("len")));
            m->score()->sigmap()->add(m->tick().ticks(), SigEvent(m->ticks(), m->timesig()));
            m->score()->sigmap()->add(m->endTick().ticks(), SigEvent(m->timesig()));
            }

      Staff* staff = m->score()->staff(staffIdx);
      Fraction timeStretch(staff->timeStretch(m->tick()));

      // keep track of tick of previous element
      // this allows markings that need to apply to previous element to do so
      // even though we may have already advanced to next tick position
      Fraction lastTick = e.tick();

      while (e.readNextStartElement()) {
            const QStringRef& tag(e.name());

            if (tag == "move")
                  e.setTick(e.readFraction() + m->tick());
            else if (tag == "tick") {
                  e.setTick(Fraction::fromTicks(m->score()->fileDivision(e.readInt())));
                  lastTick = e.tick();
                  }
            else if (tag == "BarLine") {
                  BarLine* barLine = new BarLine(m->score());
                  barLine->setTrack(e.track());
                  barLine->resetProperty(Pid::BARLINE_SPAN);
                  barLine->resetProperty(Pid::BARLINE_SPAN_FROM);
                  barLine->resetProperty(Pid::BARLINE_SPAN_TO);

                  while (e.readNextStartElement()) {
                        const QStringRef& tg(e.name());
                        if (tg == "subtype") {
                              BarLineType t = BarLineType::NORMAL;
                              switch (e.readInt()) {
                                    default:
                                    case 0:
                                          t = BarLineType::NORMAL;
                                          break;
                                    case 1:
                                          t = BarLineType::DOUBLE;
                                          break;
                                    case 2:
                                          t = BarLineType::START_REPEAT;
                                          break;
                                    case 3:
                                          t = BarLineType::END_REPEAT;
                                          break;
                                    case 4:
                                          t = BarLineType::BROKEN;
                                          break;
                                    case 5:
                                          t = BarLineType::END;
                                          break;
                                    case 6:
                                          t = BarLineType::END_START_REPEAT;
                                          break;
                                    }
                              barLine->setBarLineType(t);
                              }
                        else if (!barLine->Element::readProperties(e))
                              e.unknown();
                        }

                  //
                  //  StartRepeatBarLine: always at the beginning tick of a measure, always BarLineType::START_REPEAT
                  //  BarLine:            in the middle of a measure, has no semantic
                  //  EndBarLine:         at the end tick of a measure
                  //  BeginBarLine:       first segment of a measure

                  SegmentType st;
                  if ((e.tick() != m->tick()) && (e.tick() != m->endTick()))
                        st = SegmentType::BarLine;
                  else if (barLine->barLineType() == BarLineType::START_REPEAT && e.tick() == m->tick())
                        st = SegmentType::StartRepeatBarLine;
                  else if (e.tick() == m->tick() && segment == 0)
                        st = SegmentType::BeginBarLine;
                  else
                        st = SegmentType::EndBarLine;
                  segment = m->getSegment(st, e.tick());
                  segment->add(barLine);
                  }
            else if (tag == "Chord") {
                  Chord* chord = new Chord(m->score());
                  chord->setTrack(e.track());
                  readChord(m, chord, e);
                  if (!chord->segment())
                        chord->setParent(m->getSegment(SegmentType::ChordRest, e.tick()));
                  segment = chord->segment();
                  if (chord->noteType() != NoteType::NORMAL) {
                        graceNotes.push_back(chord);
                        }
                  else {
                        segment->add(chord);
                        Q_ASSERT(segment->segmentType() == SegmentType::ChordRest);

                        for (int i = 0; i < graceNotes.size(); ++i) {
                              Chord* gc = graceNotes[i];
                              gc->setGraceIndex(i);
                              chord->add(gc);
                              }
                        graceNotes.clear();
                        Fraction crticks = chord->actualTicks();

                        if (chord->tremolo()) {
                              Tremolo* tremolo = chord->tremolo();
                              if (tremolo->twoNotes()) {
                                    int track = chord->track();
                                    Segment* ss = 0;
                                    for (Segment* ps = m->first(SegmentType::ChordRest); ps; ps = ps->next(SegmentType::ChordRest)) {
                                          if (ps->tick() >= e.tick())
                                                break;
                                          if (ps->element(track))
                                                ss = ps;
                                          }
                                    Chord* pch = 0;       // previous chord
                                    if (ss) {
                                          ChordRest* cr = toChordRest(ss->element(track));
                                          if (cr && cr->type() == ElementType::CHORD)
                                                pch = toChord(cr);
                                          }
                                    if (pch) {
                                          tremolo->setParent(pch);
                                          pch->setTremolo(tremolo);
                                          chord->setTremolo(0);
                                          // force duration to half
                                          Fraction pts(timeStretch * pch->globalTicks());
                                          pch->setTicks(pts * Fraction(1,2));
                                          chord->setTicks(crticks * Fraction(1,2));
                                          }
                                    else {
                                          qDebug("tremolo: first note not found");
                                          }
                                    crticks = crticks * Fraction(1,2);
                                    }
                              else {
                                    tremolo->setParent(chord);
                                    }
                              }
                        lastTick = e.tick();
                        e.incTick(crticks);
                        }
                  }
            else if (tag == "Rest") {
                  Rest* rest = new Rest(m->score());
                  rest->setDurationType(TDuration::DurationType::V_MEASURE);
                  rest->setTicks(m->timesig()/timeStretch);
                  rest->setTrack(e.track());
                  readRest(m, rest, e);
                  if (!rest->segment())
                        rest->setParent(m->getSegment(SegmentType::ChordRest, e.tick()));
                  segment = rest->segment();
                  segment->add(rest);

                  if (!rest->ticks().isValid())     // hack
                        rest->setTicks(m->timesig()/timeStretch);

                  lastTick = e.tick();
                  e.incTick(rest->actualTicks());
                  }
            else if (tag == "Breath") {
                  Breath* breath = new Breath(m->score());
                  breath->setTrack(e.track());
                  Fraction tick = e.tick();
                  breath->read(e);
                  // older scores placed the breath segment right after the chord to which it applies
                  // rather than before the next chordrest segment with an element for the staff
                  // result would be layout too far left if there are other segments due to notes in other staves
                  // we need to find tick of chord to which this applies, and add its duration
                  Fraction prevTick;
                  if (e.tick() < tick)
                        prevTick = e.tick();    // use our own tick if we explicitly reset to earlier position
                  else
                        prevTick = lastTick;    // otherwise use tick of previous tick/chord/rest tag
                  // find segment
                  Segment* prev = m->findSegment(SegmentType::ChordRest, prevTick);
                  if (prev) {
                        // find chordrest
                        ChordRest* lastCR = toChordRest(prev->element(e.track()));
                        if (lastCR)
                              tick = prevTick + lastCR->actualTicks();
                        }
                  segment = m->getSegment(SegmentType::Breath, tick);
                  segment->add(breath);
                  }
            else if (tag == "endSpanner") {
                  int id = e.attribute("id").toInt();
                  Spanner* spanner = e.findSpanner(id);
                  if (spanner) {
                        spanner->setTicks(e.tick() - spanner->tick());
                        // if (spanner->track2() == -1)
                              // the absence of a track tag [?] means the
                              // track is the same as the beginning of the slur
                        if (spanner->track2() == -1)
                              spanner->setTrack2(spanner->track() ? spanner->track() : e.track());
                        }
                  else {
                        // remember "endSpanner" values
                        SpannerValues sv;
                        sv.spannerId = id;
                        sv.track2    = e.track();
                        sv.tick2     = e.tick();
                        e.addSpannerValues(sv);
                        }
                  e.readNext();
                  }
            else if (tag == "Slur") {
                  Slur *sl = new Slur(m->score());
                  sl->setTick(e.tick());
                  readSlur206(e, sl);
                  //
                  // check if we already saw "endSpanner"
                  //
                  int id = e.spannerId(sl);
                  const SpannerValues* sv = e.spannerValues(id);
                  if (sv) {
                        sl->setTick2(sv->tick2);
                        sl->setTrack2(sv->track2);
                        }
                  m->score()->addSpanner(sl);
                  }
            else if (tag == "HairPin"
               || tag == "Pedal"
               || tag == "Ottava"
               || tag == "Trill"
               || tag == "TextLine"
               || tag == "Volta") {
                  Spanner* sp = toSpanner(Element::name2Element(tag, m->score()));
                  sp->setTrack(e.track());
                  sp->setTick(e.tick());
                  // ?? sp->setAnchor(Spanner::Anchor::SEGMENT);
                  if (tag == "Volta")
                        readVolta114(e, toVolta(sp));
                  else
                        readTextLine206(e, toTextLineBase(sp));
                  m->score()->addSpanner(sp);
                  //
                  // check if we already saw "endSpanner"
                  //
                  int id = e.spannerId(sp);
                  const SpannerValues* sv = e.spannerValues(id);
                  if (sv) {
                        sp->setTicks(sv->tick2 - sp->tick());
                        sp->setTrack2(sv->track2);
                        }
                  }
            else if (tag == "RepeatMeasure") {
                  RepeatMeasure* rm = new RepeatMeasure(m->score());
                  rm->setTrack(e.track());
                  readRest(m, rm, e);
                  segment = m->getSegment(SegmentType::ChordRest, e.tick());
                  segment->add(rm);
                  if (rm->actualTicks().isZero()) // might happen with 1.3 scores
                        rm->setTicks(m->ticks());
                  lastTick = e.tick();
                  e.incTick(m->ticks());
                  }
            else if (tag == "Clef") {
                  Clef* clef = new Clef(m->score());
                  clef->setTrack(e.track());
                  readClef(clef, e);
                  if (m->score()->mscVersion() < 113)
                        clef->setOffset(QPointF());
                  clef->setGenerated(false);
                  // MS3 doesn't support wrong clef for staff type: Default to G
                  bool isDrumStaff = staff->isDrumStaff(e.tick());
                  if (clef->clefType() == ClefType::TAB
                      || (clef->clefType() == ClefType::PERC && !isDrumStaff)
                      || (clef->clefType() != ClefType::PERC && isDrumStaff)) {
                        clef->setClefType(ClefType::G);
                        staff->clefList().erase(e.tick().ticks());
                        staff->clefList().insert(std::pair<int,ClefType>(e.tick().ticks(), ClefType::G));
                        }

                  // there may be more than one clef segment for same tick position
                  // the first clef may be missing and is added later in layout

                  bool header;
                  if (e.tick() != m->tick())
                        header = false;
                  else if (!segment)
                        header = true;
                  else {
                        header = true;
                        for (Segment* s = m->segments().first(); s && s->rtick().isZero(); s = s->next()) {
                              if (s->isKeySigType() || s->isTimeSigType()) {
                                    // hack: there may be other segment types which should
                                    // generate a clef at current position
                                    header = false;
                                    break;
                                    }
                              }
                        }
                  segment = m->getSegment(header ? SegmentType::HeaderClef : SegmentType::Clef, e.tick());
                  segment->add(clef);
                  }
            else if (tag == "TimeSig") {
                  TimeSig* ts = new TimeSig(m->score());
                  ts->setTrack(e.track());
                  ts->read(e);
                  // if time sig not at beginning of measure => courtesy time sig
                  Fraction currTick = e.tick();
                  bool courtesySig = (currTick > m->tick());
                  if (courtesySig) {
                        // if courtesy sig., just add it without map processing
                        segment = m->getSegment(SegmentType::TimeSigAnnounce, currTick);
                        segment->add(ts);
                        }
                  else {
                        // if 'real' time sig., do full process
                        segment = m->getSegment(SegmentType::TimeSig, currTick);
                        segment->add(ts);

                        timeStretch = ts->stretch().reduced();
                        m->setTimesig(ts->sig() / timeStretch);
                        }
                  }
            else if (tag == "KeySig") {
                  KeySig* ks = new KeySig(m->score());
                  ks->setTrack(e.track());
                  ks->read(e);
                  Fraction curTick = e.tick();
                  if (!ks->isCustom() && !ks->isAtonal() && ks->key() == Key::C && curTick.isZero()) {
                        // ignore empty key signature
                        qDebug("remove keysig c at tick 0");
                        if (ks->links()) {
                              if (ks->links()->size() == 1)
                                    e.linkIds().remove(ks->links()->lid());
                              }
                        }
                  else {
                        // if key sig not at beginning of measure => courtesy key sig
                        bool courtesySig = (curTick == m->endTick());
                        segment = m->getSegment(courtesySig ? SegmentType::KeySigAnnounce : SegmentType::KeySig, curTick);
                        segment->add(ks);
                        if (!courtesySig)
                              staff->setKey(curTick, ks->keySigEvent());
                        }
                  }
            else if (tag == "Lyrics") {
                  Lyrics* l = new Lyrics(m->score());
                  l->setTrack(e.track());

                  int iEndTick = 0;           // used for backward compatibility
                  Text* _verseNumber = 0;

                  while (e.readNextStartElement()) {
                        const QStringRef& t(e.name());
                        if (t == "no")
                              l->setNo(e.readInt());
                        else if (t == "syllabic") {
                              QString val(e.readElementText());
                              if (val == "single")
                                    l->setSyllabic(Lyrics::Syllabic::SINGLE);
                              else if (val == "begin")
                                    l->setSyllabic(Lyrics::Syllabic::BEGIN);
                              else if (val == "end")
                                    l->setSyllabic(Lyrics::Syllabic::END);
                              else if (val == "middle")
                                    l->setSyllabic(Lyrics::Syllabic::MIDDLE);
                              else
                                    qDebug("bad syllabic property");
                              }
                        else if (t == "endTick") {          // obsolete
                              // store <endTick> tag value until a <ticks> tag has been read
                              // which positions this lyrics element in the score
                              iEndTick = e.readInt();
                              }
                        else if (t == "ticks")
                              l->setTicks(Fraction::fromTicks(e.readInt()));
                        else if (t == "Number") {                           // obsolete
                              _verseNumber = new Text(l->score());
                              readText114(e, _verseNumber, l);
                              _verseNumber->setParent(l);
                              }
                        else if (!readTextProperties(e, l, l))
                              e.unknown();
                        }
                  // if any endTick, make it relative to current tick
                  if (iEndTick) {
                        l->setTicks(Fraction::fromTicks(iEndTick - e.tick().ticks()));
                        // qDebug("Lyrics::endTick: %d  ticks %d", iEndTick, _ticks);
                        }
                  if (_verseNumber) {
                        // TODO: add text to main text
                        }

                  delete _verseNumber;

                  segment       = m->getSegment(SegmentType::ChordRest, e.tick());
                  ChordRest* cr = toChordRest(segment->element(l->track()));
                  if (!cr)
                        cr = toChordRest(segment->element(e.track())); // in case lyric itself has bad track info
                  if (!cr)
                        qDebug("Internal error: no chord/rest for lyrics");
                  else
                        cr->add(l);
                  }
            else if (tag == "Text") {
                  StaffText* t = new StaffText(m->score());
                  t->setTrack(e.track());
                  readStaffText(t, e);
                  if (t->empty()) {
                        qDebug("reading empty text: deleted");
                        delete t;
                        }
                  else {
                        segment = m->getSegment(SegmentType::ChordRest, e.tick());
                        segment->add(t);
                        }
                  }
            else if (tag == "Dynamic") {
                  Dynamic* dyn = new Dynamic(m->score());
                  dyn->setTrack(e.track());
                  dyn->read(e);
                  dyn->setDynamicType(dyn->xmlText());
                  segment = m->getSegment(SegmentType::ChordRest, e.tick());
                  segment->add(dyn);
                  }
            else if (tag == "Tempo") {
                  TempoText* t = new TempoText(m->score());
                  t->setTrack(e.track());
                  readTempoText(t, e);
                  segment = m->getSegment(SegmentType::ChordRest, e.tick());
                  segment->add(t);
                  }
            else if (tag == "StaffText") {
                  StaffText* t = new StaffText(m->score());
                  t->setTrack(e.track());
                  readStaffText(t, e);
                  segment = m->getSegment(SegmentType::ChordRest, e.tick());
                  segment->add(t);
                  }
            else if (tag == "Harmony") {
                  Harmony* h = new Harmony(m->score());
                  h->setTrack(e.track());
                  readHarmony114(e, h);
                  segment = m->getSegment(SegmentType::ChordRest, e.tick());
                  segment->add(h);
                  }
            else if (tag == "Harmony"
               || tag == "FretDiagram"
               || tag == "TremoloBar"
               || tag == "Symbol"
               || tag == "StaffText"
               || tag == "RehearsalMark"
               || tag == "InstrumentChange"
               || tag == "StaffState"
               ) {
                  Element* el = Element::name2Element(tag, m->score());
                  // hack - needed because tick tags are unreliable in 1.3 scores
                  // for symbols attached to anything but a measure
                  if (el->type() == ElementType::SYMBOL)
                        el->setParent(m);    // this will get reset when adding to segment
                  el->setTrack(e.track());
                  el->read(e);
                  segment = m->getSegment(SegmentType::ChordRest, e.tick());
                  segment->add(el);
                  }
            else if (tag == "Jump") {
                  Jump* j = new Jump(m->score());
                  j->setTrack(e.track());
                  while (e.readNextStartElement()) {
                        const QStringRef& t(e.name());
                        if (t == "jumpTo")
                              j->setJumpTo(e.readElementText());
                        else if (t == "playUntil")
                              j->setPlayUntil(e.readElementText());
                        else if (t == "continueAt")
                              j->setContinueAt(e.readElementText());
                        else if (t == "playRepeats")
                              j->setPlayRepeats(e.readBool());
                        else if (t == "subtype")
                              e.readInt();
                        else if (!j->TextBase::readProperties(e))
                              e.unknown();
                        }
                  m->add(j);
                  }
            else if (tag == "Marker") {
                  Marker* a = new Marker(m->score());
                  a->setTrack(e.track());

                  Marker::Type mt = Marker::Type::SEGNO;
                  while (e.readNextStartElement()) {
                        const QStringRef& t(e.name());
                        if (t == "subtype") {
                              QString s(e.readElementText());
                              a->setLabel(s);
                              mt = a->markerType(s);
                              }
                        else if (!a->TextBase::readProperties(e))
                              e.unknown();
                        }
                  a->setMarkerType(mt);

                  if (a->markerType() == Marker::Type::SEGNO || a->markerType() == Marker::Type::CODA  ||
                      a->markerType() == Marker::Type::VARCODA || a->markerType() == Marker::Type::CODETTA) {
                        // force the marker type for correct display
                        a->setXmlText("");
                        a->setMarkerType(a->markerType());
//TODO::ws                        a->initElementStyle(Tid::REPEAT_LEFT);
                        }
                  m->add(a);
                  }
            else if (tag == "Image") {
                  if (MScore::noImages)
                        e.skipCurrentElement();
                  else {
                        Element* el = Element::name2Element(tag, m->score());
                        el->setTrack(e.track());
                        el->read(e);
                        segment = m->getSegment(SegmentType::ChordRest, e.tick());
                        segment->add(el);
                        }
                  }
            else if (tag == "stretch") {
                  double val = e.readDouble();
                  if (val < 0.0)
                        val = 0;
                  m->setUserStretch(val);
                  }
            else if (tag == "noOffset")
                  m->setNoOffset(e.readInt());
            else if (tag == "measureNumberMode")
                  m->setMeasureNumberMode(MeasureNumberMode(e.readInt()));
            else if (tag == "irregular")
                  m->setIrregular(e.readBool());
            else if (tag == "breakMultiMeasureRest")
                  m->setBreakMultiMeasureRest(e.readBool());
            else if (tag == "sysInitBarLineType") {
                  const QString& val(e.readElementText());
                  BarLine* barLine = new BarLine(m->score());
                  barLine->setTrack(e.track());
                  barLine->setBarLineType(val);
                  segment = m->getSegment(SegmentType::BeginBarLine, m->tick());
                  segment->add(barLine);
                  }
            else if (tag == "Tuplet") {
                  Tuplet* tuplet = new Tuplet(m->score());
                  tuplet->setTrack(e.track());
                  tuplet->setTick(e.tick());
                  tuplet->setParent(m);
                  readTuplet(tuplet, e);
                  e.addTuplet(tuplet);
                  }
            else if (tag == "startRepeat") {
                  m->setRepeatStart(true);
                  e.readNext();
                  }
            else if (tag == "endRepeat") {
                  m->setRepeatCount(e.readInt());
                  m->setRepeatEnd(true);
                  }
            else if (tag == "vspacer" || tag == "vspacerDown") {
                  if (!m->vspacerDown(staffIdx)) {
                        Spacer* spacer = new Spacer(m->score());
                        spacer->setSpacerType(SpacerType::DOWN);
                        spacer->setTrack(staffIdx * VOICES);
                        m->add(spacer);
                        }
                  m->vspacerDown(staffIdx)->setGap(e.readDouble() * _spatium);
                  }
            else if (tag == "vspacer" || tag == "vspacerUp") {
                  if (!m->vspacerUp(staffIdx)) {
                        Spacer* spacer = new Spacer(m->score());
                        spacer->setSpacerType(SpacerType::UP);
                        spacer->setTrack(staffIdx * VOICES);
                        m->add(spacer);
                        }
                  m->vspacerUp(staffIdx)->setGap(e.readDouble() * _spatium);
                  }
            else if (tag == "visible")
                  m->setStaffVisible(staffIdx, e.readInt());
            else if (tag == "slashStyle")
                  m->setStaffSlashStyle(staffIdx, e.readInt());
            else if (tag == "Beam") {
                  Beam* beam = new Beam(m->score());
                  beam->setTrack(e.track());
                  beam->read(e);
                  beam->setParent(0);
                  e.addBeam(beam);
                  }
            else if (tag == "Segment") {
                  segment->read(e);
                  while (e.readNextStartElement()) {
                        const QStringRef& t(e.name());
                        if (t == "off1") {
                              qreal o = e.readDouble();
                              qDebug("TODO: off1 %f", o);
                              }
                        else
                              e.unknown();
                        }
                  }
            else if (tag == "MeasureNumber") {
                  MeasureNumber* noText = new MeasureNumber(m->score());
                  readText114(e, noText, m);
                  noText->setTrack(e.track());
                  noText->setParent(m);
                  m->setNoText(noText->staffIdx(), noText);
                  }
            else if (tag == "multiMeasureRest") {
                  m->setMMRestCount(e.readInt());
                  // set tick to previous measure
                  m->setTick(e.lastMeasure()->tick());
                  e.setTick(e.lastMeasure()->tick());
                  }
            else if (m->MeasureBase::readProperties(e))
                  ;
            else
                  e.unknown();
            }
      // For nested tuplets created with MuseScore 1.3 tuplet dialog (i.e. "Other..." dialog),
      // the parent tuplet was not set. Try to infere if the tuplet was actually a nested tuplet
      for (Tuplet* tuplet : e.tuplets()) {
            Fraction tupletTick = tuplet->tick();
            Fraction tupletDuration = tuplet->actualTicks() - Fraction::fromTicks(1);
            std::vector<DurationElement*> tElements = tuplet->elements();
            for (Tuplet* tuplet2 : e.tuplets()) {
                  if ((tuplet2->tuplet()) || (tuplet2->voice() != tuplet->voice())) // already a nested tuplet or in a different voice
                        continue;
                  // int possibleDuration = tuplet2->duration().ticks() * tuplet->ratio().denominator() / tuplet->ratio().numerator() - 1;
                  Fraction possibleDuration = tuplet2->ticks() * Fraction(tuplet->ratio().denominator(), (tuplet->ratio().numerator()-1));

                  if ((tuplet2 != tuplet) && (tuplet2->tick() >= tupletTick) && (tuplet2->tick() < tupletTick + tupletDuration) && (tuplet2->tick() + possibleDuration < tupletTick + tupletDuration)) {
                        bool found = false;
                        for (DurationElement* de : tElements) {
                              if (de == tuplet2)
                                    found = true;
                              }
                        if (!found) {
                              qDebug("Adding tuplet %p as nested tuplet to tuplet %p",tuplet2,tuplet);
                              tuplet2->setTuplet(tuplet);
                              tuplet->add(tuplet2);
                              }
                        }
                  }
            }
      e.checkTuplets();
      m->connectTremolo();
      }

//---------------------------------------------------------
//   readBoxProperties
//---------------------------------------------------------

static void readBox(XmlReader& e, Box* b);

static bool readBoxProperties(XmlReader& e, Box* b)
      {
      const QStringRef& tag(e.name());
      if (tag == "height")
            b->setBoxHeight(Spatium(e.readDouble()));
      else if (tag == "width")
            b->setBoxWidth(Spatium(e.readDouble()));
      else if (tag == "topGap")
            b->readProperty(e, Pid::TOP_GAP);
      else if (tag == "bottomGap") {
            b->readProperty(e, Pid::BOTTOM_GAP);
            }
      else if (tag == "leftMargin")
            b->setLeftMargin(e.readDouble());
      else if (tag == "rightMargin")
            b->setRightMargin(e.readDouble());
      else if (tag == "topMargin")
            b->setTopMargin(e.readDouble());
      else if (tag == "bottomMargin")
            b->setBottomMargin(e.readDouble());
      else if (tag == "offset")
            b->setOffset(e.readPoint() * b->spatium());
      else if (tag == "pos")        // ignore
            e.readPoint();
      else if (tag == "Text") {
            Text* t;
            if (b->isTBox()) {
                  t = toTBox(b)->text();
                  readText114(e, t, t);
                  }
            else {
                  t = new Text(b->score());
                  readText114(e, t, t);
                  if (t->empty())
                        qDebug("read empty text");
                  else
                        b->add(t);
                  }
            }
      else if (tag == "Symbol") {
            Symbol* s = new Symbol(b->score());
            s->read(e);
            b->add(s);
            }
      else if (tag == "Image") {
            if (MScore::noImages)
                  e.skipCurrentElement();
            else {
                  Image* image = new Image(b->score());
                  image->setTrack(e.track());
                  image->read(e);
                  b->add(image);
                  }
            }
      else if (tag == "HBox") {
            HBox* hb = new HBox(b->score());
            readBox(e, hb);
            b->add(hb);
            }
      else if (tag == "VBox") {
            VBox* vb = new VBox(b->score());
            readBox(e, vb);
            b->add(vb);
            }
//      else if (MeasureBase::readProperties(e))
//            ;
      else
            return false;
      return true;
      }

//---------------------------------------------------------
//   readBox
//---------------------------------------------------------

static void readBox(XmlReader& e, Box* b)
      {
      b->setLeftMargin(0.0);
      b->setRightMargin(0.0);
      b->setTopMargin(0.0);
      b->setBottomMargin(0.0);
      b->setBoxHeight(Spatium(0));     // override default set in constructor
      b->setBoxWidth(Spatium(0));

      while (e.readNextStartElement()) {
            const QStringRef& tag(e.name());
            if (tag == "HBox") {
                  HBox* hb = new HBox(b->score());
                  readBox(e, hb);
                  b->add(hb);
                  }
            else if (tag == "VBox") {
                  VBox* vb = new VBox(b->score());
                  readBox(e, vb);
                  b->add(vb);
                  }
            else if (!readBoxProperties(e, b))
                  e.unknown();
            }
      }

//---------------------------------------------------------
//   readStaffContent
//---------------------------------------------------------

static void readStaffContent(Score* score, XmlReader& e)
      {
      int staff = e.intAttribute("id", 1) - 1;
      e.setTick(Fraction(0,1));
      e.setTrack(staff * VOICES);

      Measure* measure = score->firstMeasure();
      while (e.readNextStartElement()) {
            const QStringRef& tag(e.name());

            if (tag == "Measure") {
                  if (staff == 0) {
                        measure = new Measure(score);
                        measure->setTick(e.tick());
                        const SigEvent& ev = score->sigmap()->timesig(measure->tick());
                        measure->setTicks(ev.timesig());
                        measure->setTimesig(ev.nominal());

                        readMeasure(measure, staff, e);
                        measure->checkMeasure(staff);

                        if (!measure->isMMRest()) {
                              score->measures()->add(measure);
                              e.setLastMeasure(measure);
                              e.setTick(measure->tick() + measure->ticks());
                              }
                        else {
                              // this is a multi measure rest
                              // always preceded by the first measure it replaces
                              Measure* m = e.lastMeasure();

                              if (m) {
                                    m->setMMRest(measure);
                                    measure->setTick(m->tick());
                                    }
                              }
                         }
                  else {
                        if (measure == 0) {
                              qDebug("Score::readStaff(): missing measure!");
                              measure = new Measure(score);
                              measure->setTick(e.tick());
                              score->measures()->add(measure);
                              }
                        e.setTick(measure->tick());

                        readMeasure(measure, staff, e);
                        measure->checkMeasure(staff);

                        if (measure->isMMRest())
                              measure = e.lastMeasure()->nextMeasure();
                        else {
                              e.setLastMeasure(measure);
                              if (measure->mmRest())
                                    measure = measure->mmRest();
                              else
                                    measure = measure->nextMeasure();
                              }
                        }
                  }
            else if (tag == "HBox" || tag == "VBox" || tag == "TBox" || tag == "FBox") {
                  Box* mb = toBox(Element::name2Element(tag, score));
                  readBox(e, mb);
                  mb->setTick(e.tick());
                  score->measures()->add(mb);
                  }
            else if (tag == "tick")
                  e.setTick(Fraction::fromTicks(score->fileDivision(e.readInt())));
            else
                  e.unknown();
            }
      }

//---------------------------------------------------------
//   readStaff
//---------------------------------------------------------

static void readStaff(Staff* staff, XmlReader& e)
      {
      Score* _score = staff->score();
      while (e.readNextStartElement()) {
            const QStringRef& tag(e.name());
            if (tag == "lines") {
                  int lines = e.readInt();
                  staff->setLines(Fraction(0,1), lines);
                  if (lines != 5) {
                        staff->setBarLineFrom(lines == 1 ? BARLINE_SPAN_1LINESTAFF_FROM : 0);
                        staff->setBarLineTo(lines == 1 ? BARLINE_SPAN_1LINESTAFF_TO   : (lines - 1) * 2);
                        }
                  }
            else if (tag == "small")
                  staff->setSmall(Fraction(0,1), e.readInt());
            else if (tag == "invisible")
                  staff->setInvisible(e.readInt());
            else if (tag == "slashStyle")
                  e.skipCurrentElement();
            else if (tag == "cleflist") {
                  // QList<std::pair<int, ClefType>>& cl = e.clefs(idx());
                  staff->clefList().clear();
                  while (e.readNextStartElement()) {
                        if (e.name() == "clef") {
                              int tick    = e.intAttribute("tick", 0);
                              ClefType ct = readClefType(e.attribute("idx", "0"));
                              staff->clefList().insert(std::pair<int,ClefType>(_score->fileDivision(tick), ct));
                              e.readNext();
                              }
                        else
                              e.unknown();
                        }
                  if (staff->clefList().empty())
                        staff->clefList().insert(std::pair<int,ClefType>(0, ClefType::G));
                  }
            else if (tag == "keylist")
                  staff->keyList()->read(e, _score);
            else if (tag == "bracket") {
                  int col = staff->brackets().size();
                  staff->setBracketType(col, BracketType(e.intAttribute("type", -1)));
                  staff->setBracketSpan(col, e.intAttribute("span", 0));
                  e.readNext();
                  }
            else if (tag == "barLineSpan")
                  staff->setBarLineSpan(e.readInt());
            else
                  e.unknown();
            }
      }

//---------------------------------------------------------
//   readDrumset
//---------------------------------------------------------

static void readDrumset(Drumset* ds, XmlReader& e)
      {
      int pitch = e.intAttribute("pitch", -1);
      if (pitch < 0 || pitch > 127) {
            qDebug("load drumset: invalid pitch %d", pitch);
            return;
            }
      while (e.readNextStartElement()) {
            const QStringRef& tag(e.name());
            if (tag == "head")
                  ds->drum(pitch).notehead = convertHeadGroup(e.readInt());
            else if (ds->readProperties(e, pitch))
                  ;
            else
                  e.unknown();
            }
      }

//---------------------------------------------------------
//   readInstrument
//---------------------------------------------------------

static void readInstrument(Instrument *i, Part* p, XmlReader& e)
      {
      int program = -1;
      int bank    = 0;
      int chorus  = 30;
      int reverb  = 30;
      int volume  = 100;
      int pan     = 60;
      bool customDrumset = false;
      i->clearChannels();       // remove default channel
      while (e.readNextStartElement()) {
            const QStringRef& tag(e.name());
            if (tag == "chorus")
                  chorus = e.readInt();
            else if (tag == "reverb")
                  reverb = e.readInt();
            else if (tag == "midiProgram")
                  program = e.readInt();
            else if (tag == "volume")
                  volume = e.readInt();
            else if (tag == "pan")
                  pan = e.readInt();
            else if (tag == "midiChannel")
                  e.skipCurrentElement();
            else if (tag == "Drum") {
                  // if we see one of this tags, a custom drumset will
                  // be created
                  if (!i->drumset())
                        i->setDrumset(new Drumset(*smDrumset));
                  if (!customDrumset) {
                        i->drumset()->clear();
                        customDrumset = true;
                        }
                  readDrumset(i->drumset(), e);
                  }

            else if (i->readProperties(e, p, &customDrumset))
                  ;
            else
                 e.unknown();
            }

      if (i->channel().empty()) {      // for backward compatibility
            Channel* a = new Channel;
            a->setName(Channel::DEFAULT_NAME);
            a->setProgram(program);
            a->setBank(bank);
            a->setVolume(volume);
            a->setPan(pan);
            a->setReverb(reverb);
            a->setChorus(chorus);
            i->appendChannel(a);
            }
      if (i->useDrumset()) {
            if (i->channel()[0]->bank() == 0)
                  i->channel()[0]->setBank(128);
            }

      // Fix user bank controller read
      for (Channel* c : i->channel()) {
            if (c->bank() == 0)
                  c->setUserBankController(false);
            }

      // Read single-note dynamics from template
      i->setSingleNoteDynamicsFromTemplate();
      }

//---------------------------------------------------------
//   readPart
//---------------------------------------------------------

static void readPart(Part* part, XmlReader& e)
      {
      Score* _score = part->score();
      while (e.readNextStartElement()) {
            const QStringRef& tag(e.name());
            if (tag == "Staff") {
                  Staff* staff = new Staff(_score);
                  staff->setPart(part);
                  staff->setStaffType(Fraction(0,1), StaffType()); // will reset later if needed
                  _score->staves().push_back(staff);
                  part->staves()->push_back(staff);
                  readStaff(staff, e);
                  }
            else if (tag == "Instrument") {
                  Instrument* i = part->instrument();
                  readInstrument(i, part, e);
                  // add string data from MIDI program number, if possible
                  if (i->stringData()->strings() == 0
                     && i->channel().count() > 0
                     && i->drumset() == nullptr) {
                        int program = i->channel(0)->program();
                        if (program >= 24 && program <= 30)       // guitars
                              i->setStringData(StringData(19, 6, g_guitarStrings));
                        else if ( (program >= 32 && program <= 39) || program == 43)      // bass / double-bass
                              i->setStringData(StringData(24, 4, g_bassStrings));
                        else if (program == 40)                   // violin and other treble string instr.
                              i->setStringData(StringData(24, 4, g_violinStrings));
                        else if (program == 41)                   // viola and other alto string instr.
                              i->setStringData(StringData(24, 4, g_violaStrings));
                        else if (program == 42)                   // cello and other bass string instr.
                              i->setStringData(StringData(24, 4, g_celloStrings));
                        }
                  Drumset* d = i->drumset();
                  Staff*   st = part->staff(0);
                  if (d && st && st->lines(Fraction(0,1)) != 5) {
                        int n = 0;
                        if (st->lines(Fraction(0,1)) == 1)
                              n = 4;
                        for (int  j = 0; j < DRUM_INSTRUMENTS; ++j)
                              d->drum(j).line -= n;
                        }
                  }
            else if (tag == "name") {
                  Text* t = new Text(_score);
                  readText114(e, t, t);
                  part->instrument()->setLongName(t->xmlText());
                  delete t;
                  }
            else if (tag == "shortName") {
                  Text* t = new Text(_score);
                  readText114(e, t, t);
                  part->instrument()->setShortName(t->xmlText());
                  delete t;
                  }
            else if (tag == "trackName")
                  part->setPartName(e.readElementText());
            else if (tag == "show")
                  part->setShow(e.readInt());
            else
                  e.unknown();
            }
      if (part->partName().isEmpty())
            part->setPartName(part->instrument()->trackName());

      if (part->instrument()->useDrumset()) {
            for (Staff* staff : *part->staves()) {
                  int lines = staff->lines(Fraction(0,1));
                  int bf    = staff->barLineFrom();
                  int bt    = staff->barLineTo();
                  staff->setStaffType(Fraction(0,1), *StaffType::getDefaultPreset(StaffGroup::PERCUSSION));

                  // this allows 2/3-line percussion staves to keep the double spacing they had in 1.3

                  if (lines == 2 || lines == 3)
                        ((StaffType*)(staff->staffType(Fraction(0,1))))->setLineDistance(Spatium(2.0));

                  staff->setLines(Fraction(0,1), lines);       // this also sets stepOffset
                  staff->setBarLineFrom(bf);
                  staff->setBarLineTo(bt);
                  }
            }
      //set default articulations
      QList<MidiArticulation> articulations;
      articulations.append(MidiArticulation("", "", 100, 100));
      articulations.append(MidiArticulation("staccato", "", 100, 50));
      articulations.append(MidiArticulation("tenuto", "", 100, 100));
      articulations.append(MidiArticulation("sforzato", "", 120, 100));
      part->instrument()->setArticulation(articulations);
      }

//---------------------------------------------------------
//   readPageFormat
//---------------------------------------------------------

static void readPageFormat(PageFormat* pf, XmlReader& e)
      {
      qreal _oddRightMargin  = 0.0;
      qreal _evenRightMargin = 0.0;
      bool landscape         = false;
      QString type;

      while (e.readNextStartElement()) {
            const QStringRef& tag(e.name());
            if (tag == "landscape")
                  landscape = e.readInt();
            else if (tag == "page-margins") {
                  type = e.attribute("type","both");
                  qreal lm = 0.0, rm = 0.0, tm = 0.0, bm = 0.0;
                  while (e.readNextStartElement()) {
                        const QStringRef& t(e.name());
                        qreal val = e.readDouble() * 0.5 / PPI;
                        if (t == "left-margin")
                              lm = val;
                        else if (t == "right-margin")
                              rm = val;
                        else if (t == "top-margin")
                              tm = val;
                        else if (t == "bottom-margin")
                              bm = val;
                        else
                              e.unknown();
                        }
                  pf->setTwosided(type == "odd" || type == "even");
                  if (type == "odd" || type == "both") {
                        pf->setOddLeftMargin(lm);
                        _oddRightMargin = rm;
                        pf->setOddTopMargin(tm);
                        pf->setOddBottomMargin(bm);
                        }
                  if (type == "even" || type == "both") {
                        pf->setEvenLeftMargin(lm);
                        _evenRightMargin = rm;
                        pf->setEvenTopMargin(tm);
                        pf->setEvenBottomMargin(bm);
                        }
                  }
            else if (tag == "page-height")
                  pf->setSize(QSizeF(pf->size().width(), e.readDouble() * 0.5 / PPI));
            else if (tag == "page-width")
                  pf->setSize(QSizeF(e.readDouble() * 0.5 / PPI, pf->size().height()));
            else if (tag == "pageFormat") {
                  const PaperSize* s = getPaperSize114(e.readElementText());
                  pf->setSize(QSizeF(s->w, s->h));
                  }
            else if (tag == "page-offset") {
                  e.readInt();
                  }
            else
                  e.unknown();
            }
      if (landscape)
            pf->setSize(pf->size().transposed());
      qreal w1 = pf->size().width() - pf->oddLeftMargin() - _oddRightMargin;
      qreal w2 = pf->size().width() - pf->evenLeftMargin() - _evenRightMargin;
      pf->setPrintableWidth(qMin(w1, w2));     // silently adjust right margins
      }

//---------------------------------------------------------
//   readStyle
//---------------------------------------------------------

static void readStyle(MStyle* style, XmlReader& e)
      {
      QString oldChordDescriptionFile = style->value(Sid::chordDescriptionFile).toString();
      bool chordListTag = false;
      while (e.readNextStartElement()) {
            QString tag = e.name().toString();

            if (tag == "lyricsDistance")        // was renamed
                  tag = "lyricsPosBelow";

            if (tag == "TextStyle") {
//                  TextStyle s;
//TODO                  s.read(e);
//                  style->setTextStyle(s);
                  e.skipCurrentElement();
                  }
            else if (tag == "lyricsMinBottomDistance") {
                  // no longer meaningful since it is now measured from skyline rather than staff
                  //style->set(Sid::lyricsMinBottomDistance, QPointF(0.0, y));
                  e.skipCurrentElement();
                  }
            else if (tag == "Spatium")
                  style->set(Sid::spatium, e.readDouble() * DPMM);
            else if (tag == "page-layout") {
                  PageFormat pf;
                  initPageFormat(style, &pf);
                  pf.read(e);
                  setPageFormat(style, pf);
                  }
            else if (tag == "displayInConcertPitch")
                  style->set(Sid::concertPitch, QVariant(bool(e.readInt())));
            else if (tag == "ChordList") {
                  style->chordList()->clear();
                  style->chordList()->read(e);
                  for (ChordFont f : style->chordList()->fonts) {
                        if (f.family == "MuseJazz") {
                              f.family = "MuseJazz Text";
                              }
                        }
                  style->setCustomChordList(true);
                  chordListTag = true;
                  }
            else if (tag == "pageFillLimit" || tag == "genTimesig" || tag == "FixMeasureNumbers" || tag == "FixMeasureWidth")   // obsolete
                  e.skipCurrentElement();
            else if (tag == "systemDistance")  // obsolete
                  style->set(Sid::minSystemDistance, QVariant(e.readDouble()));
            else if (tag == "stemDir") {
                  int voice = e.attribute("voice", "1").toInt() - 1;
                  switch(voice) {
                        case 0: tag = "StemDir1"; break;
                        case 1: tag = "StemDir2"; break;
                        case 2: tag = "StemDir3"; break;
                        case 3: tag = "StemDir4"; break;
                        }
                  }
            // for compatibility:
            else if (tag == "oddHeader" || tag == "evenHeader" || tag == "oddFooter" || tag == "evenFooter")
                  tag += "C";
#if 0 // TODO-ws
                  int idx2;
                  for (idx2 = 0; idx2 < int(ArticulationType::ARTICULATIONS); ++idx2) {
                        ArticulationInfo& ai =  Articulation::articulationList[idx2];
                        // deal with obsolete tags from 1.14 format
                        if (tag == "SforzatoaccentAnchor")
                              tag = "SforzatoAnchor";
                        if (tag == "SnappizzicatorAnchor")
                              tag = "SnappizzicatoAnchor";
                        else if (tag == "EspressivoAnchor")
                              continue;
                        if (QString::compare(tag, QString(ai.name).append("Anchor"),  Qt::CaseInsensitive) == 0
                              || QString::compare(tag, QString("U").append(ai.name).append("Anchor"), Qt::CaseInsensitive) == 0
                              || QString::compare(tag, QString("D").append(ai.name).append("Anchor"), Qt::CaseInsensitive) == 0
                              ) {
                              Sid si = MStyle::styleIdx(QString(ai.name).append("Anchor"));
                              if (si != Sid::NOSTYLE) {
                                    QString val(e.readElementText());
                                    style->set(si, val.toInt());
                                    break;
                                    }
                              }
                        }
                  if (idx2 < int(ArticulationType::ARTICULATIONS))
                        continue;
#endif
            else {
                  if (!style->readProperties(e)) {
                        e.skipCurrentElement();
                        }
                  }
//TODO                  style->convertToUnit(tag, val);
            }

      // if we just specified a new chord description file
      // and didn't encounter a ChordList tag
      // then load the chord description file

      QString newChordDescriptionFile = style->value(Sid::chordDescriptionFile).toString();
      if (newChordDescriptionFile != oldChordDescriptionFile && !chordListTag) {
            if (!newChordDescriptionFile.startsWith("chords_") && style->value(Sid::chordStyle).toString() == "std") {
                  // should not normally happen,
                  // but treat as "old" (114) score just in case
                  style->set(Sid::chordStyle, QVariant(QString("custom")));
                  style->set(Sid::chordsXmlFile, QVariant(true));
                  qDebug("StyleData::load: custom chord description file %s with chordStyle == std", qPrintable(newChordDescriptionFile));
                  }
            if (style->value(Sid::chordStyle).toString() == "custom")
                  style->setCustomChordList(true);
            else
                  style->setCustomChordList(false);
            style->chordList()->unload();
            }

      // make sure we have a chordlist
      if (!chordListTag)
            style->checkChordList();
#if 0 // TODO
      //
      //  Compatibility with old scores/styles:
      //  translate old frameWidthMM and paddingWidthMM
      //  into spatium units
      //
      int n = style->textStyles().size();
      qreal _spatium = style->value(Sid::spatium).toDouble();
      qreal spMM = _spatium / DPMM;
      for (int i = 0; i < n; ++i) {
            TextStyle* s = &style->textStyle(StyledPropertyListIdx(i));
            if (s->frameWidthMM() != 0.0)
                  s->setFrameWidth(Spatium(s->frameWidthMM() / spMM));
            if (s->paddingWidthMM() != 0.0)
                  s->setPaddingWidth(Spatium(s->paddingWidthMM() / spMM));
            }
#endif
      }

//---------------------------------------------------------
//   read114
//    import old version <= 1.3 files
//---------------------------------------------------------

Score::FileError MasterScore::read114(XmlReader& e)
      {
      for (unsigned int i = 0; i < sizeof(style114)/sizeof(*style114); ++i)
            style().set(style114[i].sid, style114[i].val);
#if 0
      // old text style defaults
      TextStyle ts = style().textStyle("Chord Symbol");
      ts.setYoff(-4.0);
      style().setTextStyle(ts);
      ts = style().textStyle("Rehearsal Mark");
      ts.setSquare(false);
      ts.setFrameRound(20);
      style().setTextStyle(ts);
      ts = style().textStyle("Dynamics");
      ts.setItalic(false);
      style().setTextStyle(ts);
#endif
      TempoMap tm;
      while (e.readNextStartElement()) {
            e.setTrack(-1);
            const QStringRef& tag(e.name());
            if (tag == "Staff")
                  readStaffContent(this, e);
            else if (tag == "KeySig") {               // not supported
                  KeySig* ks = new KeySig(this);
                  ks->read(e);
                  delete ks;
                  }
            else if (tag == "siglist")
                  _sigmap->read(e, _fileDivision);
            else if (tag == "programVersion") {
                  setMscoreVersion(e.readElementText());
                  parseVersion(mscoreVersion());
                  }
            else if (tag == "programRevision")
                  setMscoreRevision(e.readInt());
            else if (tag == "Mag"
               || tag == "MagIdx"
               || tag == "xoff"
               || tag == "Symbols"
               || tag == "cursorTrack"
               || tag == "yoff")
                  e.skipCurrentElement();       // obsolete
            else if (tag == "tempolist") {
                  // store the tempo list to create invisible tempo text later
                  qreal tempo = e.attribute("fix","2.0").toDouble();
                  tm.setRelTempo(tempo);
                  while (e.readNextStartElement()) {
                        if (e.name() == "tempo") {
                              int tick   = e.attribute("tick").toInt();
                              double tmp = e.readElementText().toDouble();
                              tick       = (tick * MScore::division + _fileDivision/2) / _fileDivision;
                              auto pos   = tm.find(tick);
                              if (pos != tm.end())
                                    tm.erase(pos);
                              tm.setTempo(tick, tmp);
                        }
                        else if (e.name() == "relTempo")
                              e.readElementText();
                        else
                              e.unknown();
                  }
            }
            else if (tag == "playMode")
                  setPlayMode(PlayMode(e.readInt()));
            else if (tag == "SyntiSettings")
                  _synthesizerState.read(e);
            else if (tag == "Spatium")
                  setSpatium (e.readDouble() * DPMM);
            else if (tag == "Division")
                  _fileDivision = e.readInt();
            else if (tag == "showInvisible")
                  setShowInvisible(e.readInt());
            else if (tag == "showFrames")
                  setShowFrames(e.readInt());
            else if (tag == "showMargins")
                  setShowPageborders(e.readInt());
            else if (tag == "Style") {
                  qreal sp = spatium();
                  readStyle(&style(), e);
                  //style()->load(e);
                  // adjust this now so chords render properly on read
                  // other style adjustments can wait until reading is finished
                  if (styleB(Sid::useGermanNoteNames))
                        style().set(Sid::useStandardNoteNames, false);
                  if (_layoutMode == LayoutMode::FLOAT) {
                        // style should not change spatium in
                        // float mode
                        setSpatium(sp);
                        }
                  }
            else if (tag == "TextStyle") {
                  e.skipCurrentElement();
#if 0 // TODO
                  TextStyle s;
                  s.read(e);

                  qreal spMM = spatium() / DPMM;
                  if (s.frameWidthMM() != 0.0)
                        s.setFrameWidth(Spatium(s.frameWidthMM() / spMM));
                  if (s.paddingWidthMM() != 0.0)
                        s.setPaddingWidth(Spatium(s.paddingWidthMM() / spMM));

                  // convert 1.2 text styles
                  s.setName(convertOldTextStyleNames(s.name()));
                  if (s.family() == "MuseJazz")
                        s.setFamily("MuseJazz Text");

                  if (s.name() == "Lyrics Odd Lines" || s.name() == "Lyrics Even Lines")
                        s.setAlign(Align(int(s.align()) & int(~Align::VMASK)) | Align::BASELINE);

                  style().setTextStyle(s);
#endif
                  }
            else if (tag == "page-layout") {
                  PageFormat pf;
                  readPageFormat(&pf, e);
                  }
            else if (tag == "copyright" || tag == "rights") {
                  Text* text = new Text(this);
                  readText114(e, text, text);
                  setMetaTag("copyright", text->plainText());
                  delete text;
                  }
            else if (tag == "movement-number")
                  setMetaTag("movementNumber", e.readElementText());
            else if (tag == "movement-title")
                  setMetaTag("movementTitle", e.readElementText());
            else if (tag == "work-number")
                  setMetaTag("workNumber", e.readElementText());
            else if (tag == "work-title")
                  setMetaTag("workTitle", e.readElementText());
            else if (tag == "source")
                  setMetaTag("source", e.readElementText());
            else if (tag == "metaTag") {
                  QString name = e.attribute("name");
                  setMetaTag(name, e.readElementText());
                  }
            else if (tag == "Part") {
                  Part* part = new Part(this);
                  readPart(part, e);
                  parts().push_back(part);
                  }
            else if (tag == "Slur") {
                  Slur* slur = new Slur(this);
                  readSlur206(e, slur);
                  addSpanner(slur);
                  }
            else if ((tag == "HairPin")
                || (tag == "Ottava")
                || (tag == "TextLine")
                || (tag == "Volta")
                || (tag == "Trill")
                || (tag == "Pedal")) {
                  Spanner* s = toSpanner(Element::name2Element(tag, this));
                  if (tag == "Volta")
                        readVolta114(e, toVolta(s));
                  else if (tag == "Ottava")
                        readOttava114(e, toOttava(s));
                  else if (tag == "TextLine")
                        readTextLine114(e, toTextLine(s));
                  else if (tag == "Pedal")
                         readPedal114(e, toPedal(s));
                  else if (tag == "Trill")
                        readTrill206(e, toTrill(s));
                  else {
                        Q_ASSERT(tag == "HairPin");
                        readHairpin206(e, toHairpin(s));
                        }
                  if (s->track() == -1)
                        s->setTrack(e.track());
                  else
                        e.setTrack(s->track());       // update current track
                  if (s->tick() == Fraction(-1,1))
                        s->setTick(e.tick());
                  else
                        e.setTick(s->tick());      // update current tick
                  if (s->track2() == -1)
                        s->setTrack2(s->track());
                  if (s->ticks().isZero()) {
                        qDebug("zero spanner %s ticks: %d", s->name(), s->ticks().ticks());
                        delete s;
                        }
                  else {
                        addSpanner(s);
                        }
                  }
            else if (tag == "Excerpt") {
                  if (MScore::noExcerpts)
                        e.skipCurrentElement();
                  else {
                        Excerpt* ex = new Excerpt(this);
                        ex->read(e);
                        _excerpts.append(ex);
                        }
                  }
            else if (tag == "Beam") {
                  Beam* beam = new Beam(this);
                  beam->read(e);
                  beam->setParent(0);
                  // _beams.append(beam);
                  }
            else if (tag == "name")
                  setName(e.readElementText());
            else
                  e.unknown();
            }

      if (e.error() != QXmlStreamReader::NoError) {
            qDebug("%lld %lld: %s ", e.lineNumber(), e.columnNumber(), qPrintable(e.errorString()));
            return FileError::FILE_BAD_FORMAT;
            }

      for (Staff* s : staves()) {
            int idx   = s->idx();
            int track = idx * VOICES;

            // check barLineSpan
            if (s->barLineSpan() > (nstaves() - idx)) {
                  qDebug("read114: invalid barline span %d (max %d)",
                     s->barLineSpan(), nstaves() - idx);
                  s->setBarLineSpan(nstaves() - idx);
                  }
            for (auto i : s->clefList()) {
                  Fraction tick   = Fraction::fromTicks(i.first);
                  ClefType clefId = i.second._concertClef;
                  Measure* m      = tick2measure(tick);
                  if (!m)
                        continue;
                  SegmentType st = SegmentType::Clef;
                  if (tick == m->tick()) {
                       if (m->prevMeasure())
                              m = m->prevMeasure();
                        else
                              st = SegmentType::HeaderClef;
                        }
                  Segment* seg = m->getSegment(st, tick);
                  if (seg->element(track))
                        seg->element(track)->setGenerated(false);
                  else {
                        Clef* clef = new Clef(this);
                        clef->setClefType(clefId);
                        clef->setTrack(track);
                        clef->setParent(seg);
                        clef->setGenerated(false);
                        seg->add(clef);
                        }
                  }

            // create missing KeySig
            KeyList* km = s->keyList();
            for (auto i = km->begin(); i != km->end(); ++i) {
                  Fraction tick = Fraction::fromTicks(i->first);
                  if (tick < Fraction(0,1)) {
                        qDebug("read114: Key tick %d", tick.ticks());
                        continue;
                        }
                  if (tick.isZero() && i->second.key() == Key::C)
                        continue;
                  Measure* m = tick2measure(tick);
                  if (!m)           //empty score
                        break;
                  Segment* seg = m->getSegment(SegmentType::KeySig, tick);
                  if (seg->element(track))
                        toKeySig(seg->element(track))->setGenerated(false);
                  else {
                        KeySigEvent ke = i->second;
                        KeySig* ks = new KeySig(this);
                        ks->setKeySigEvent(ke);
                        ks->setParent(seg);
                        ks->setTrack(track);
                        ks->setGenerated(false);
                        seg->add(ks);
                        }
                  }
            }

      for (std::pair<int,Spanner*> p : spanner()) {
            Spanner* s = p.second;
            if (!s->isSlur()) {
                  if (s->isVolta()) {
                        Volta* volta = toVolta(s);
                        volta->setAnchor(Spanner::Anchor::MEASURE);
                        }
                  }

            if (s->isOttava() || s->isPedal() || s->isTrill() || s->isTextLine()) {
                  qreal yo = 0;
                  if (s->isOttava()) {
                      // fix ottava position
                      yo = styleValue(Pid::OFFSET, Sid::ottavaPosAbove).toPointF().y();
                      if (s->placeBelow())
                            yo = -yo + s->staff()->height();
                      }
                  else if (s->isPedal()) {
                        yo = styleValue(Pid::OFFSET, Sid::pedalPosBelow).toPointF().y();
                        }
                  else if (s->isTrill()) {
                        yo = styleValue(Pid::OFFSET, Sid::trillPosAbove).toPointF().y();
                        }
                  else if (s->isTextLine()) {
                        yo = -5.0 * spatium();
                  }
                  if (!s->spannerSegments().empty()) {
                        for (SpannerSegment* seg : s->spannerSegments()) {
                              if (!seg->offset().isNull())
                                    seg->ryoffset() = seg->offset().y() - yo;
                              }
                        }
                  else {
                        s->ryoffset() = -yo;
                        }
                  }
            }

      connectTies();

      //
      // remove "middle beam" flags from first ChordRest in
      // measure
      //
      for (Measure* m = firstMeasure(); m; m = m->nextMeasure()) {
            int tracks = nstaves() * VOICES;
            bool first = true;
            for (int track = 0; track < tracks; ++track) {
                  for (Segment* s = m->first(); s; s = s->next()) {
                        if (s->segmentType() != SegmentType::ChordRest)
                              continue;
                        ChordRest* cr = toChordRest(s->element(track));
                        if (cr) {
#if 0 // TODO
                              if (cr->isRest()) {
                                    Rest* r = toRest(cr);
                                    if (!r->offset().isNull()) {
                                          int lineOffset = r->computeLineOffset();
                                          qreal lineDist = r->staff() ? r->staff()->staffType(cr->tick())->lineDistance().val() : 1.0;
                                          r->rUserYoffset() -= (lineOffset * .5 * lineDist * r->spatium());
                                          }
                                    }
#endif
                              if (!first) {
                                    switch (cr->beamMode()) {
                                          case Beam::Mode::AUTO:
                                          case Beam::Mode::BEGIN:
                                          case Beam::Mode::END:
                                          case Beam::Mode::NONE:
                                                break;
                                          case Beam::Mode::MID:
                                          case Beam::Mode::BEGIN32:
                                          case Beam::Mode::BEGIN64:
                                                cr->setBeamMode(Beam::Mode::BEGIN);
                                                break;
                                          case Beam::Mode::INVALID:
                                                if (cr->isChord())
                                                      cr->setBeamMode(Beam::Mode::AUTO);
                                                else
                                                      cr->setBeamMode(Beam::Mode::NONE);
                                                break;
                                          }
                                    first = false;
                                    }
                              }
                        }
                  }
            }
      for (MeasureBase* mb = first(); mb; mb = mb->next()) {
            if (mb->isVBox()) {
                  VBox* b  = toVBox(mb);
                  qreal y = styleP(Sid::staffUpperBorder);
                  b->setBottomGap(y);
                  }
            }

      _fileDivision = MScore::division;

      //
      //    sanity check for barLineSpan and update ottavas
      //
      for (Staff* staff : staves()) {
            int barLineSpan = staff->barLineSpan();
            int idx = staff->idx();
            int n = nstaves();
            if (idx + barLineSpan > n) {
                  qDebug("bad span: idx %d  span %d staves %d", idx, barLineSpan, n);
                  staff->setBarLineSpan(n - idx);
                  }
            staff->updateOttava();
            }

      // adjust some styles
      if (styleB(Sid::hideEmptyStaves))        // http://musescore.org/en/node/16228
            style().set(Sid::dontHideStavesInFirstSystem, false);
      if (styleB(Sid::showPageNumberOne)) {    // http://musescore.org/en/node/21207
            style().set(Sid::evenFooterL, QString("$P"));
            style().set(Sid::oddFooterR, QString("$P"));
            }
      if (styleI(Sid::minEmptyMeasures) == 0)
            style().set(Sid::minEmptyMeasures, 1);
      style().set(Sid::frameSystemDistance, styleS(Sid::frameSystemDistance) + Spatium(6.0));
      // hack: net overall effect of layout changes has been for things to take slightly more room
      qreal adjustedSpacing = qMax(styleD(Sid::measureSpacing) * 0.95, 1.0);
      style().set(Sid::measureSpacing, adjustedSpacing);

      _showOmr = false;

      // add invisible tempo text if necessary
      // some 1.3 scores have tempolist but no tempo text
      fixTicks();
      for (auto i : tm) {
            Fraction tick = Fraction::fromTicks(i.first);
            qreal tempo   = i.second.tempo;
            if (tempomap()->tempo(tick.ticks()) != tempo) {
                  TempoText* tt = new TempoText(this);
                  tt->setXmlText(QString("<sym>metNoteQuarterUp</sym> = %1").arg(qRound(tempo*60)));
                  tt->setTempo(tempo);
                  tt->setTrack(0);
                  tt->setVisible(false);
                  Measure* m = tick2measure(tick);
                  if (m) {
                        Segment* seg = m->getSegment(SegmentType::ChordRest, tick);
                        seg->add(tt);
                        setTempo(tick, tempo);
                        }
                  else
                        delete tt;
                  }
            }

      // create excerpts

      QList<Excerpt*> readExcerpts;
      readExcerpts.swap(_excerpts);
      for (Excerpt* excerpt : readExcerpts) {
            if (excerpt->parts().isEmpty())           // ignore empty parts
                  continue;
            if (!excerpt->parts().isEmpty()) {
                  _excerpts.push_back(excerpt);
                  Score* nscore = new Score(this);
                  excerpt->setPartScore(nscore);
                  nscore->style().set(Sid::createMultiMeasureRests, true);
                  Excerpt::createExcerpt(excerpt);
                  }
            }

      // volta offsets in older scores are hardcoded to be relative to a voltaY of -2.0sp
      // we'll force this and live with it for the score
      // but we wait until now to do it so parts don't have this issue

      if (styleV(Sid::voltaPosAbove) == MScore::baseStyle().value(Sid::voltaPosAbove))
            style().set(Sid::voltaPosAbove, QPointF(0.0, -2.0f));

      fixTicks();
      rebuildMidiMapping();
      updateChannel();

      // treat reading a 1.14 file as import
      // on save warn if old file will be overwritten
      setCreated(true);
      // don't autosave (as long as there's no change to the score)
      setAutosaveDirty(false);

      return FileError::FILE_NO_ERROR;
      }

}