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 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512
|
/*
* yaps - program to convert abc files to PostScript.
* Copyright (C) 1999 James Allwright
* e-mail: J.R.Allwright@westminster.ac.uk
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/* drawtune.c */
/* This file contains routines for generating final PostScript Output */
/* There are 2 stages to this process. First the symbol positions are */
/* calculated, then the PostScript symbols are generated. */
#include <stdio.h>
#ifdef ANSILIBS
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#endif
#include "abc.h"
#include "structs.h"
#include "sizes.h"
#include "drawtune.h"
/* external functions and variables */
extern struct tune thetune;
extern int debugging;
extern int pagenumbering;
extern char outputname[256];
extern char outputroot[256];
extern int make_open();
extern void printlib();
extern int count_dots(int *base, int *base_exp, int n, int m);
extern void monospace(struct tune* t);
extern void spacevoices(struct tune* t);
/* provided by debug.c */
extern void showtune(struct tune *t);
struct key* newkey(char* name, int sharps, char accidental[], int mult[]);
struct aclef* newclef(enum cleftype t, int octave);
char* addstring();
extern int lineno;
extern int separate_voices;
extern int print_xref;
extern int landscape;
static void pagebottom();
static void setfont(int size, int num);
FILE* f;
struct feature* beamset[64];
struct feature* gracebeamset[32];
int beamctr, gracebeamctr;;
int rootstem;
int fontsize, fontnum;
int donemeter;
int ingrace, inchord;
int chordcount;
struct feature* chordhead;
double scale, descend, totlen, oldplace;
int pagecount = 1;
int pagelen, pagewidth, xmargin, ymargin;
double scaledlen, scaledwidth;
int staffsep;
int eps_out;
int titleleft = 0;
int titlecaps = 0;
int gchords_above = 1;
enum placetype {left, right, centre};
struct font textfont;
struct font titlefont;
struct font subtitlefont;
struct font wordsfont;
struct font composerfont;
struct font vocalfont;
struct font gchordfont;
struct font partsfont;
/* arrays giving character widths for characters 32-255 */
/* font for lyrics : 13 point Times-Bold */
double timesbold_width[224] = {
3.249, 4.328, 7.214, 6.499, 6.499, 12.999, 10.828, 4.328,
4.328, 4.328, 6.499, 7.409, 3.249, 7.409, 3.249, 3.613,
6.499, 6.499, 6.499, 6.499, 6.499, 6.499, 6.499, 6.499,
6.499, 6.499, 4.328, 4.328, 7.409, 7.409, 7.409, 6.499,
12.089, 9.385, 8.67, 9.385, 9.385, 8.67, 7.942, 10.113,
10.113, 5.056, 6.499, 10.113, 8.67, 12.271, 9.385, 10.113,
7.942, 10.113, 9.385, 7.227, 8.67, 9.385, 9.385, 12.999,
9.385, 9.385, 8.67, 4.328, 3.613, 4.328, 7.552, 6.499,
4.328, 6.499, 7.227, 5.771, 7.227, 5.771, 4.328, 6.499,
7.227, 3.613, 4.328, 7.227, 3.613, 10.828, 7.227, 6.499,
7.227, 7.227, 5.771, 5.056, 4.328, 7.227, 6.499, 9.385,
6.499, 6.499, 5.771, 5.121, 2.859, 5.121, 6.759, 3.249,
3.249, 3.249, 3.249, 3.249, 3.249, 3.249, 3.249, 3.249,
3.249, 3.249, 3.249, 3.249, 3.249, 3.249, 3.249, 3.249,
3.613, 4.328, 4.328, 4.328, 4.328, 4.328, 4.328, 4.328,
4.328, 3.249, 4.328, 4.328, 3.249, 4.328, 4.328, 4.328,
3.249, 4.328, 6.499, 6.499, 6.499, 6.499, 2.859, 6.499,
4.328, 9.71, 3.899, 6.499, 7.409, 4.328, 9.71, 4.328,
5.199, 7.409, 3.899, 3.899, 4.328, 7.227, 7.019, 3.249,
4.328, 3.899, 4.289, 6.499, 9.749, 9.749, 9.749, 6.499,
9.385, 9.385, 9.385, 9.385, 9.385, 9.385, 12.999, 9.385,
8.67, 8.67, 8.67, 8.67, 5.056, 5.056, 5.056, 5.056,
9.385, 9.385, 10.113, 10.113, 10.113, 10.113, 10.113, 7.409,
10.113, 9.385, 9.385, 9.385, 9.385, 9.385, 7.942, 7.227,
6.499, 6.499, 6.499, 6.499, 6.499, 6.499, 9.385, 5.771,
5.771, 5.771, 5.771, 5.771, 3.613, 3.613, 3.613, 3.613,
6.499, 7.227, 6.499, 6.499, 6.499, 6.499, 6.499, 7.409,
6.499, 7.227, 7.227, 7.227, 7.227, 6.499, 7.227, 6.499,
};
/* font for chord names : 12 point Helvetica */
double helvetica_width[224] = {
3.335, 3.335, 4.259, 6.671, 6.671, 10.667, 8.003, 2.651,
3.995, 3.995, 4.667, 7.007, 3.335, 3.995, 3.335, 3.335,
6.671, 6.671, 6.671, 6.671, 6.671, 6.671, 6.671, 6.671,
6.671, 6.671, 3.335, 3.335, 7.007, 7.007, 7.007, 6.671,
12.179, 8.003, 8.003, 8.663, 8.663, 8.003, 7.331, 9.335,
8.663, 3.335, 5.999, 8.003, 6.671, 9.995, 8.663, 9.335,
8.003, 9.335, 8.663, 8.003, 7.331, 8.663, 8.003, 11.327,
8.003, 8.003, 7.331, 3.335, 3.335, 3.335, 5.627, 6.671,
2.663, 6.671, 6.671, 5.999, 6.671, 6.671, 3.335, 6.671,
6.671, 2.663, 2.663, 5.999, 2.663, 9.995, 6.671, 6.671,
6.671, 6.671, 3.995, 5.999, 3.335, 6.671, 5.999, 8.663,
5.999, 5.999, 5.999, 4.007, 3.119, 4.007, 7.007, 3.335,
3.335, 3.335, 3.335, 3.335, 3.335, 3.335, 3.335, 3.335,
3.335, 3.335, 3.335, 3.335, 3.335, 3.335, 3.335, 3.335,
3.335, 3.335, 3.335, 3.335, 3.335, 3.335, 3.335, 3.335,
3.335, 3.335, 3.335, 3.335, 3.335, 3.335, 3.335, 3.335,
3.335, 3.995, 6.671, 6.671, 2.003, 6.671, 6.671, 6.671,
6.671, 2.291, 3.995, 6.671, 3.995, 3.995, 5.999, 5.999,
3.335, 6.671, 6.671, 6.671, 3.335, 3.335, 6.443, 4.199,
2.663, 3.995, 3.995, 6.671, 11.999, 11.999, 3.335, 7.331,
3.335, 3.995, 3.995, 3.995, 3.995, 3.995, 3.995, 3.995,
3.995, 3.335, 3.995, 3.995, 3.335, 3.995, 3.995, 3.995,
11.999, 3.335, 3.335, 3.335, 3.335, 3.335, 3.335, 3.335,
3.335, 3.335, 3.335, 3.335, 3.335, 3.335, 3.335, 3.335,
3.335, 11.999, 3.335, 4.439, 3.335, 3.335, 3.335, 3.335,
6.671, 9.335, 11.999, 4.379, 3.335, 3.335, 3.335, 3.335,
3.335, 10.667, 3.335, 3.335, 3.335, 3.335, 3.335, 3.335,
2.663, 7.331, 11.327, 7.331, 3.335, 3.335, 3.335, 3.335,
};
static int ISOencoding(char ch1, char ch2)
/* converts the 2 characters following '\' into an ISO Latin 1 Font */
/* character code in the range 128-255 */
{
int code;
code = 0;
switch (ch1) {
case '`':
switch(ch2) {
case 'A': code = 0300; break;
case 'E': code = 0310; break;
case 'I': code = 0314; break;
case 'O': code = 0322; break;
case 'U': code = 0331; break;
case 'a': code = 0340; break;
case 'e': code = 0350; break;
case 'i': code = 0354; break;
case 'o': code = 0362; break;
case 'u': code = 0371; break;
default:
break;
};
break;
case '\'':
switch(ch2) {
case 'A': code = 0301; break;
case 'E': code = 0311; break;
case 'I': code = 0315; break;
case 'U': code = 0332; break;
case 'Y': code = 0335; break;
case 'a': code = 0341; break;
case 'e': code = 0351; break;
case 'i': code = 0355; break;
case 'o': code = 0363; break;
case 'u': code = 0372; break;
case 'y': code = 0375; break;
default:
break;
};
break;
case '^':
switch(ch2) {
case 'A': code = 0302; break;
case 'E': code = 0312; break;
case 'I': code = 0316; break;
case 'O': code = 0324; break;
case 'U': code = 0333; break;
case 'a': code = 0342; break;
case 'e': code = 0352; break;
case 'i': code = 0356; break;
case 'o': code = 0364; break;
case 'u': code = 0373; break;
default:
break;
};
break;
case '"':
switch(ch2) {
case 'A': code = 0304; break;
case 'E': code = 0313; break;
case 'I': code = 0317; break;
case 'O': code = 0326; break;
case 'U': code = 0334; break;
case 'a': code = 0344; break;
case 'e': code = 0353; break;
case 'i': code = 0357; break;
case 'o': code = 0366; break;
case 'u': code = 0374; break;
case 'y': code = 0377; break;
default:
break;
};
break;
case '~':
switch(ch2) {
case 'A': code = 0303; break;
case 'N': code = 0321; break;
case 'O': code = 0325; break;
case 'a': code = 0343; break;
case 'n': code = 0361; break;
case 'o': code = 0365; break;
default:
break;
};
break;
case 'c':
switch(ch2) {
case 'C': code = 0307; break;
case 'c': code = 0347; break;
default:
break;
};
break;
case 'o':
switch(ch2) {
case 'A': code = 0305; break;
case 'a': code = 0345; break;
default:
break;
};
break;
case 'A':
if (ch2=='A') {
code = 0305;
};
if (ch2=='E') {
code = 0305;
};
break;
case 'a':
if (ch2=='a') {
code = 0345;
};
if (ch2=='e') {
code = 0346;
};
break;
case 's':
if (ch2=='s') {
code = 0337;
};
break;
default:
break;
};
return(code);
}
static int getISO(char s[], int j, int* code)
/* convert input into 8-bit character code */
/* s[] is input string, j is place in string */
/* returns new place in string and writes 8-bit value to code */
{
int i;
int count;
i =j;
if (s[i]=='\\') {
/* look for 2 character code */
*code = ISOencoding(s[i+1], s[i+2]);
if (*code != 0) {
i = i+3;
} else {
/* look for octal code */
i = i+1;
*code = 0;
count = 0;
while ((s[i]>='0')&&(s[i]<='7')&&(count<3)) {
*code = ((*code)*8+(int)s[i]-'0')%256;
count = count+1;
i = i+1;
};
if (*code == 0) {
*code = '\\';
};
};
} else {
*code = (int)s[i] & 0xFF;
i = i + 1;
};
return(i);
}
static void ISOdecode(char s[], char out[])
/* convert coded characters to straight 8-bit ascii */
{
int i, j, len;
int code;
len = strlen(s);
i = 0;
j = 0;
while (i<len) {
i = getISO(s, i, &code);
out[j] = (char)code;
j = j + 1;
};
out[j] = '\0';
}
static void ISOfprintf(char s[])
/* interpret special characters and print to file */
{
int i, len, ch;
int code;
len = strlen(s);
i = 0;
while (i<len) {
switch(s[i]) {
case '(':
fprintf(f, "\\(");
i = i+1;
break;
case ')':
fprintf(f, "\\)");
i = i+1;
break;
case '\\':
i = getISO(s, i, &code);
fprintf(f, "\\%03o", code);
break;
default:
ch = 0xFF & (int)s[i];
if ((ch > 31) && (ch < 128)) {
fprintf(f, "%c", s[i]);
} else {
fprintf(f, "\\%03o", 0xFF & (int)s[i]);
};
i = i+1;
break;
};
};
}
static double stringwidth(char* str, double ptsize, int fontno)
/* calculate width of string */
{
int i, len, ch;
double width;
int code;
double baseptsize;
double* charwidth;
if (fontno == 3) {
charwidth = &helvetica_width[0];
baseptsize = 12.0;
} else {
charwidth = ×bold_width[0];
baseptsize = 13.0;
};
width = 0.0;
len = strlen(str);
i = 0;
while (i < len) {
i = getISO(str, i, &code);
ch = code - 32;
if ((ch >= 0) && (ch < 224)) {
width = width + charwidth[ch];
} else {
width = width + charwidth[0]; /* approximate with space */
};
};
return(width*ptsize/baseptsize);
}
void setscaling(char* s)
/* scaling value from string following -s in arglist */
{
double f;
f = -1.0;
sscanf(s, "%lf", &f);
if (f < 0.001) {
f = TUNE_SCALING;
};
scale = f;
}
void setmargins(s)
char* s;
/* set margin values from string following -M in arglist */
{
int i, j;
xmargin = XMARGIN;
ymargin = YMARGIN;
if (s != NULL) {
i = -1;
j = -1;
sscanf(s, "%dx%d", &i, &j);
if ((i != -1) && (j != -1)) {
xmargin = i;
ymargin = j;
};
};
}
void setpagesize(s)
char* s;
/* set page size from string following -P in arglist */
{
int i, j;
pagelen = A4_PAGELEN - 2 * ymargin;
pagewidth = A4_PAGEWIDTH - 2 * xmargin;
if (s != NULL) {
i = 0;
j = 0;
sscanf(s, "%dx%d", &i, &j);
if (i == 0) {
pagelen = A4_PAGELEN - 2 * ymargin;
pagewidth = A4_PAGEWIDTH - 2 * xmargin;
};
if (i == 1) {
pagelen = US_LETTER_PAGELEN - 2 * ymargin;
pagewidth = US_LETTER_PAGEWIDTH - 2 * xmargin;
};
if ((i > 100) && (i > 2*xmargin) && (j > 100) && (j > 2*ymargin)) {
pagewidth = i - 2 * xmargin;
pagelen = j - 2 * ymargin;
};
};
if (landscape) {
i = xmargin;
xmargin = ymargin;
ymargin = i;
i = pagelen;
pagelen = pagewidth;
pagewidth = i;
};
scaledlen = ((double)(pagelen))/scale;
scaledwidth = ((double)(pagewidth))/scale;
}
static void set_space(afont, s)
/* set vertical space to appear above a line in the given font */
/* s is a string specifying space in points (default), centimetres */
/* or inches */
struct font* afont;
char* s;
{
int count;
double x;
char units[40];
count = sscanf(s, "%lf%s", &x, units);
if (count > 0) {
if ((count >= 2) && (strncmp(units, "cm", 2) == 0)) {
x = x*28.3;
};
if ((count >= 2) && (strncmp(units, "in", 2) == 0)) {
x = x*72.0 ;
};
afont->space = (int)x;
};
}
static void init_font(afont, ptsize, spce, defnum, specialnum)
/* initialize font structure with given values */
struct font* afont;
int ptsize, spce, defnum, specialnum;
{
afont->pointsize = ptsize;
afont->space = spce;
afont->default_num = defnum;
afont->special_num = specialnum;
afont->name = NULL;
afont->defined = 0;
}
static void startpage()
/* Encapsulated PostScript for a page header */
{
fprintf(f, "%%%%Page: %d %d\n", pagecount, pagecount);
fprintf(f, "%%%%BeginPageSetup\n");
fprintf(f, "gsave\n");
if (landscape) {
fprintf(f, "90 rotate %d %d T\n", xmargin, -ymargin);
} else {
fprintf(f, "%d %d T\n", xmargin, ymargin+pagelen);
};
fprintf(f, "0.8 setlinewidth 0 setlinecap\n");
fprintf(f, "%.3f %.3f scale\n", scale, scale);
fprintf(f, "%%%%EndPageSetup\n\n");
fontnum = 0;
fontsize = 0;
totlen = 0.0;
oldplace = 0.0;
descend = 0.0;
}
static void closepage()
/* Encapsulated PostScript for page end */
{
if (pagenumbering) {
setfont(12, 3);
pagebottom();
fprintf(f, "(%d) %.1f 0 M cshow\n", pagecount, scaledwidth/2.0);
};
fprintf(f, "%%%%PageTrailer\n");
fprintf(f, "grestore\n");
fprintf(f, "showpage\n\n");
pagecount = pagecount + 1;
}
void newpage()
/* create PostScript for a new page of paper */
/* everything will now be printed on this fresh sheet */
/* ignore the command if the sheet is completely blank */
{
if (totlen > 0.0) {
closepage();
startpage();
};
}
static void pagebottom()
/* move to the bottom of the page */
{
fprintf(f, "0 %.1f T\n", -(scaledlen - totlen));
totlen = scaledlen;
descend = 0.0;
}
static void newblock(double height, double descender)
/* The page is modelled as a series of vertical bands */
/* This routine finds room for a fresh band below the current one */
/* It also does a translation to set a new y=0 line */
/* Subsequent calls may draw up to height units above or */
/* descender units below the line y=0 */
{
if (totlen+(descend+height+descender) > scaledlen - (double)(pagenumbering*12)) {
newpage();
};
fprintf(f, "0 %.1f T\n", - descend - height);
totlen = totlen + (descend + height);
descend = descender;
}
static void staveline()
/* draw 5 lines of a stave */
{
fprintf(f, "%.1f staff\n", scaledwidth);
}
static void printclef(struct aclef* t, double x, double yup, double ydown)
/* draw a clef of the specified type */
{
switch (t->type) {
case treble:
fprintf(f, "%.1f tclef\n", x);
break;
case bass:
fprintf(f, "%.1f bclef\n", x);
break;
case alto:
fprintf(f, "%.1f cclef\n", x);
break;
case baritone:
fprintf(f, "0 %d T %.1f cclef 0 %d T\n", 4*TONE_HT, x, -4*TONE_HT);
break;
case tenor:
fprintf(f, "0 %d T %.1f cclef 0 %d T\n", 2*TONE_HT, x, -2*TONE_HT);
break;
case mezzo:
fprintf(f, "0 %d T %.1f cclef 0 %d T\n", -2*TONE_HT, x, 2*TONE_HT);
break;
case soprano:
fprintf(f, "0 %d T %.1f cclef 0 %d T\n", -4*TONE_HT, x, 4*TONE_HT);
break;
default:
break;
};
if (t->octave > 0) {
fprintf(f, "%.1f %.1f (%d) bnum\n", x, yup - CLEFNUM_HT + 3, t->octave);
};
if (t->octave < 0) {
fprintf(f, "%.1f %.1f (%d) bnum\n", x, -ydown, - t->octave);
};
}
void set_keysig(struct key* k, struct key* newval)
/* copy across key signature */
{
int i;
for (i=0; i<7; i++) {
k->map[i] = newval->map[i];
k->mult[i] = newval->mult[i];
};
k->sharps = newval->sharps;
}
static double size_keysig(char oldmap[], char newmap[])
/* compute width taken up by drawing the key signature */
{
int i, n;
n = 0;
for (i=0; i<7; i++) {
if (((newmap[i] == '=')&&(oldmap[i] != '=')) ||
(newmap[i] == '^') || (newmap[i] == '_')) {
n = n + 1;
};
};
return((double)n * 5.0);
}
static double size_timesig(struct fract* meter)
/* compute width of the time signature */
{
double len1, len2;
char temp[20];
sprintf(temp, "%d", meter->num);
len1 = stringwidth(temp, 16.0, 2);
sprintf(temp, "%d", meter->denom);
len2 = stringwidth(temp, 16.0, 2);
if (len1 > len2) {
return(len1);
} else {
return(len2);
};
}
static void draw_keysig(char oldmap[], char newmap[], int newmult[],
double x, struct aclef* clef)
/* draw key specified key signature at position x on line */
/* arrays oldmap[], newmap[], newmult[] are indexed with a=0 to g=7 */
/* sharp_pos[] and flat_pos[] give order of notes */
/* e.g. sharp_pos[0] = 8 means 1st sharp drawn is conventionally f */
/* which is in position 8 on the stave (bottom line is E = 0) */
{
double xpos;
static int sharp_pos[7] = { 8, 5, 9, 6, 3, 7, 4 };
static int flat_pos[7] = { 4, 7, 3, 6, 2, 5, 1};
int i;
int offset, pos;
int note;
switch (clef->type) {
case treble:
offset = 0;
break;
case soprano:
offset = 2;
break;
case mezzo:
offset = 4;
break;
case alto:
offset = 6;
break;
case tenor:
offset = 8;
break;
case baritone:
offset = 10;
break;
case bass:
offset = 12;
break;
};
xpos = x;
/* draw naturals to cancel out old accidentals */
for (i=0; i<7; i++) {
note = (sharp_pos[i] + 4) % 7;
if ((newmap[note] == '=')&&(oldmap[note] != '=')) {
pos = (sharp_pos[i] + offset - 3) % 7 + 3;
fprintf(f, " %.1f %d nt0", xpos, pos*TONE_HT);
xpos = xpos + 5;
};
};
/* draw sharps */
for (i=0; i<7; i++) {
note = (sharp_pos[i] + 4) % 7;
if (newmap[note] == '^') {
pos = (sharp_pos[i] + offset - 3) % 7 + 3;
if (newmult[note] == 2) {
fprintf(f, " %.1f %d dsh0", xpos, pos*TONE_HT);
} else {
fprintf(f, " %.1f %d sh0", xpos, pos*TONE_HT);
};
xpos = xpos + 5;
};
};
/* draw flats */
for (i=0; i<7; i++) {
note = (flat_pos[i] + 4) % 7;
if (newmap[note] == '_') {
pos = (flat_pos[i] + offset - 1)%7 + 1;
if (newmult[note] == 2) {
fprintf(f, " %.1f %d dft0", xpos, pos*TONE_HT);
} else {
fprintf(f, " %.1f %d ft0", xpos, pos*TONE_HT);
};
xpos = xpos + 5;
};
};
fprintf(f, "\n");
}
static void draw_meter(struct fract* meter, double x)
/* draw meter (time signature) at specified x value */
{
fprintf(f, "%.1f (%d) (%d) tsig\n", x, meter->num, meter->denom);
}
static double maxstrwidth(struct llist* strings, double ptsize, int fontno)
/* return the width of longest string in the list */
{
double width, max;
char* str;
max = 0.0;
str = firstitem(strings);
while (str != NULL) {
width = stringwidth(str, ptsize, fontno);
if (width > max) {
max = width;
};
str = nextitem(strings);
};
return(max);
}
static void sizerest(struct rest* r, struct feature* ft)
/* compute width of rest element */
{
double width;
switch (r->base_exp) {
case 1:
case 0:
ft->xleft = 2.5;
ft->xright = 2.5;
break;
case -1:
ft->xleft = 2.5;
ft->xright = 2.5;
break;
case -2:
ft->xleft = 3.0;
ft->xright = 4.0;
break;
case -3:
ft->xleft = 4.0;
ft->xright = 3.0;
break;
case -4:
ft->xleft = 5.0;
ft->xright = 3.0;
break;
case -5:
ft->xleft = 6.0;
ft->xright = 5.0;
break;
case -6:
default:
ft->xleft = 7.0;
ft->xright = 5.0;
break;
};
if (r->dots > 0) {
ft->xright = ft->xright + (r->dots*DOT_SPACE);
};
if (r->gchords != NULL) {
width = maxstrwidth(r->gchords, (double)(gchordfont.pointsize),
gchordfont.default_num);
if (width > ft->xleft + ft->xright) {
ft->xright = width - ft->xleft;
};
};
}
static int acc_upsize(char ch)
/* returns height above note of accent */
{
int size;
switch (ch) {
case '=':
size = NAT_UP;
break;
case '^':
size = SH_UP;
break;
case '_':
size = FLT_UP;
break;
default:
size = 0;
break;
};
return(size);
}
static int acc_downsize(char ch)
/* returns depth below note of accent */
{
int size;
switch (ch) {
case '=':
size = NAT_DOWN;
break;
case '^':
size = SH_DOWN;
break;
case '_':
size = FLT_DOWN;
break;
default:
size = 0;
break;
};
return(size);
}
static void setstemlen(struct note* n, int ingrace)
/* work out how long stem needs to be for an isolated note */
/* if the note is in a beamed set, the length may be altered later */
{
if (n->base_exp >= 0) {
n->stemlength = 0.0;
} else {
if (ingrace) {
if (n->beaming != single) {
n->stemlength = GRACE_STEMLEN; /* default stem length */
/* value will be recalculated later by setbeams() */
} else {
switch(n->base_exp) {
case -6:
n->stemlength = GRACE_STEMLEN + 2*TAIL_SEP*0.7;
break;
case -5:
n->stemlength = GRACE_STEMLEN + TAIL_SEP*0.7;
break;
default:
n->stemlength = GRACE_STEMLEN; /* default stem length */
break;
};
};
} else {
if (n->beaming != single) {
n->stemlength = STEMLEN; /* default stem length */
/* value will be recalculated later by setbeams() */
} else {
switch(n->base_exp) {
case -6:
n->stemlength = STEMLEN + 2*TAIL_SEP;
break;
case -5:
n->stemlength = STEMLEN + TAIL_SEP;
break;
default:
n->stemlength = STEMLEN; /* default stem length */
break;
};
};
};
};
}
static void sizenote(struct note* n, struct feature* f, int ingrace)
/* compute width and height of note element */
{
double width;
char* decorators;
int i;
f->ydown = TONE_HT*(n->y - 2);
f->yup = TONE_HT*(n->y + 2);
if (ingrace) {
f->xleft = GRACE_HALF_HEAD;
f->xright = GRACE_HALF_HEAD;
} else {
if (n->base_exp >= 1) {
f->xleft = HALF_BREVE;
f->xright = HALF_BREVE;
} else {
f->xleft = HALF_HEAD;
f->xright = HALF_HEAD;
};
if (n->fliphead) {
if (n->stemup) {
f->xright = f->xright + HALF_HEAD * 2;
} else {
f->xleft = f->xleft + HALF_HEAD * 2;
};
};
};
if (n->dots > 0) {
f->xright = f->xright + (n->dots*DOT_SPACE);
};
if ((n->stemup) && (n->base_exp <= -3) && (n->beaming==single)) {
if (f->xright < (HALF_HEAD + TAILWIDTH)) {
f->xright = HALF_HEAD + TAILWIDTH;
};
};
if (n->accidental != ' ') {
f->xleft = HALF_HEAD + ACC_OFFSET + (n->acc_offset-1) * ACC_OFFSET2;
if (n->stemup) {
f->ydown = TONE_HT*(n->y) - (double)(acc_downsize(n->accidental));
} else {
f->yup = TONE_HT*(n->y) + (double)(acc_upsize(n->accidental));
};
};
if (n->stemlength > 0.0) {
if (n->stemup) {
f->yup = TONE_HT*(n->y) + n->stemlength;
} else {
f->ydown = TONE_HT*(n->y) - n->stemlength;
};
};
if (n->accents != NULL) {
decorators = n->accents;
for (i=0; i<strlen(decorators); i++) {
switch(decorators[i]) {
case 'H':
case '~':
case 'u':
case 'v':
case 'T':
f->yup = f->yup + BIG_DEC_HT;
break;
case 'R':
if (n->stemup) {
f->ydown = f->ydown + BIG_DEC_HT;
} else {
f->yup = f->yup + BIG_DEC_HT;
};
break;
case 'M':
case '.':
if (n->stemup) {
f->ydown = f->ydown + SMALL_DEC_HT;
} else {
f->yup = f->yup + SMALL_DEC_HT;
};
break;
default:
/* this should never happen */
event_error("Un-recognized accent");
break;
};
};
};
if (n->syllables != NULL) {
width = maxstrwidth(n->syllables, (double)(vocalfont.pointsize),
vocalfont.default_num);
if (width > f->xleft + f->xright) {
f->xright = width - f->xleft;
};
};
if (n->gchords != NULL) {
width = maxstrwidth(n->gchords, (double)(gchordfont.pointsize),
gchordfont.default_num);
if (width > f->xleft + f->xright) {
f->xright = width - f->xleft;
};
};
}
static void spacechord(struct feature* chordplace)
/* prevents collision of note heads and accidentals in a chord */
/* sets fliphead and acc_offset for all notes in chord */
{
struct feature* place;
struct note* anote;
int thisy, lasty, lastflip;
int stemdir;
int doneflip;
int ygap[10];
int accplace;
int i;
/* first flip heads */
place = chordplace;
lasty = 200;
lastflip = 1;
doneflip = 0;
while ((place != NULL) && (place->type != CHORDOFF)) {
if ((place->type == CHORDNOTE) || (place->type == NOTE)) {
anote = place->item;
thisy = anote->y;
if ((lasty - thisy <= 1) && (lastflip != 1)) {
anote->fliphead = 1;
stemdir = anote->stemup;
lastflip = 1;
doneflip = 1;
} else {
lastflip = 0;
};
lasty = thisy;
};
place = place->next;
};
/* now deal with accidentals */
for (i=0; i<10; i++) {
ygap[i] = 200;
};
if ((doneflip) && (stemdir == 0)) {
/* block off space where note is */
ygap[0] = -200;
};
place = chordplace;
while ((place != NULL) && (place->type != CHORDOFF)) {
if ((place->type == CHORDNOTE) || (place->type == NOTE)) {
anote = place->item;
thisy = anote->y;
if (anote->accidental != ' ') {
/* find space for this accidental */
accplace = 0;
while ((accplace <10) && (ygap[accplace] < thisy)) {
accplace = accplace + 1;
};
anote->acc_offset = accplace + 1;
ygap[accplace] = thisy - 6;
};
};
place = place->next;
};
}
static void sizechord(struct chord* ch, int ingrace)
/* decide on stem direction and set default stem length for a chord */
{
if ((ch->ytop + ch->ybot < 8)||(ingrace)) {
ch->stemup = 1;
} else {
ch->stemup = 0;
};
ch->stemlength = STEMLEN;
}
static void setxy(double* x, double* y, struct note* n, struct feature* ft,
double offset, double half_head)
/* compute x,y co-ordinates above note for drawing a beam */
{
if (n->stemup) {
*x = ft->x + half_head;
*y = (double)(TONE_HT*n->y) + n->stemlength - offset;
} else {
*x = ft->x - half_head;
*y = (double)(TONE_HT*n->y) - n->stemlength + offset;
};
}
static void drawtuple(struct feature* beamset[], int beamctr, int tupleno)
/* label a beam which is a tuplet of notes (e.g. triplet) */
{
double x0, x1, y0, y1;
struct note* n;
int stemup;
x0 = beamset[0]->x;
n = beamset[0]->item;
stemup = n->stemup;
if (stemup) {
y0 = (double)(TONE_HT*n->y) + n->stemlength;
} else {
y0 = (double)(TONE_HT*n->y) - n->stemlength;
};
x1 = beamset[beamctr-1]->x;
n = beamset[beamctr-1]->item;
if (stemup) {
y1 = (double)(TONE_HT*n->y) + n->stemlength;
} else {
y1 = (double)(TONE_HT*n->y) - n->stemlength;
};
if (stemup) {
fprintf(f, " %.1f %.1f (%d) bnum", (x0+x1)/2, (y0+y1)/2 + TUPLE_UP, tupleno);
} else {
fprintf(f, " %.1f %.1f (%d) bnum", (x0+x1)/2, (y0+y1)/2 + TUPLE_DOWN,
tupleno);
};
}
static void drawhtuple(double xstart, double xend, int num, double y)
/* draw a tuple using half-brackets */
/* used for tuples which do not correspond to a beam */
{
double xmid;
xmid = (xstart + xend)/2;
fprintf(f, " %.1f %.1f %.1f %.1f hbr", xstart, y, xmid-6.0, y);
fprintf(f, " %.1f %.1f %.1f %.1f hbr", xend, y, xmid+6.0, y);
fprintf(f, " %.1f %.1f (%d) bnum\n", xmid, y-4.0, num);
}
static void drawbeam(struct feature* beamset[], int beamctr, int dograce)
/* draw a beam spanning the notes in array beamset[] */
{
int i, d;
int donenotes;
int start, stop;
double x0, x1, y0, y1, offset;
struct note* n;
int stemup, beamdir;
double half_head;
if (beamctr==0) {
event_error("Internal error: beam with 0 notes");
showtune(&thetune);
return;
exit(0);
};
if (beamset[0]->type != NOTE) {
event_error("Internal error: beam does not start with NOTE");
exit(0);
};
fprintf(f, "\n");
n = beamset[0]->item;
stemup = n->stemup;
beamdir = 2*stemup - 1;
donenotes = 1;
d = -3;
offset = 0.0;
if (dograce) {
half_head = GRACE_HALF_HEAD;
} else {
half_head = HALF_HEAD;
};
while (donenotes) {
donenotes = 0;
start = -1;
for (i=0; i<beamctr; i++) {
n = beamset[i]->item;
if (n->base_exp <= d) {
if (start == -1) {
start = i;
setxy(&x0, &y0, n, beamset[i], offset, half_head);
};
stop = i;
setxy(&x1, &y1, n, beamset[i], offset, half_head);
};
if ((n->beaming == endbeam) || (n->base_exp > d)) {
if (start != -1) {
/* draw unit */
if (start == stop) {
if (start != 0) {
/* half line in front of note */
n = beamset[start-1]->item;
setxy(&x0, &y0, n, beamset[start-1], offset, half_head);
x0 = x0 + (x1-x0)/2;
y0 = y0 + (y1-y0)/2;
} else {
/* half line behind note */
n = beamset[start+1]->item;
setxy(&x1, &y1, n, beamset[start+1], offset, half_head);
x1 = x1 + (x0-x1)/2;
y1 = y1 + (y0-y1)/2;
};
if (dograce) {
fprintf(f, "%.1f %.1f %.1f %.1f gbm2\n", x0, y0, x1, y1);
} else {
fprintf(f, "%.1f %.1f %.1f %.1f %.1f bm\n", x0, y0, x1, y1,
(double)(beamdir * TAIL_WIDTH));
};
} else {
if (dograce) {
fprintf(f, "%.1f %.1f %.1f %.1f gbm2\n", x0, y0, x1, y1);
} else {
fprintf(f, "%.1f %.1f %.1f %.1f %.1f bm\n", x0, y0, x1, y1,
(double)(beamdir * TAIL_WIDTH));
};
};
donenotes = 1;
start = -1;
};
};
};
d = d - 1;
offset = offset + TAIL_SEP;
};
}
static void sizevoice(struct voice* v, struct tune* t)
/* compute width and height values for all elements in voice */
{
struct feature* ft;
struct note* anote;
struct key* akey;
struct aclef* theclef;
char* astring;
struct fract* afract;
struct rest* arest;
struct note* lastnote;
struct chord* thischord;
struct feature* chordplace;
struct tuple* thistuple;
enum tail_type chordbeaming;
int intuple, tuplecount;
struct feature* tuplefeature;
ingrace = 0;
inchord = 0;
intuple = 0;
tuplefeature = NULL;
chordhead = NULL;
thischord = NULL;
chordplace = NULL;
v->clef->type = t->clef.type;
v->clef->octave = t->clef.octave;
if (v->keysig == NULL) {
event_error("Voice has no key signature");
};
ft = v->first;
lastnote = NULL;
while (ft != NULL) {
ft->xleft = 0.0;
ft->xright = 0.0;
ft->ydown = 0.0;
ft->yup = 0.0;
switch (ft->type) {
case SINGLE_BAR:
ft->xleft = 0.8;
ft->xright = 0.0;
break;
case DOUBLE_BAR:
ft->xleft = 3.0;
ft->xright = 0.0;
break;
case BAR_REP:
ft->xleft = 1.0;
ft->xright = 10.0;
break;
case REP_BAR:
ft->xleft = 1.0;
ft->xright = 10.0;
break;
case REP1:
break;
case REP2:
break;
case PLAY_ON_REP:
break;
case BAR1:
break;
case REP_BAR2:
ft->xleft = 6.0;
ft->xright = 5.0;
break;
case DOUBLE_REP:
ft->xleft = 10.0;
ft->xright = 10.0;
break;
case THICK_THIN:
ft->xleft = 0.0;
ft->xright = 6.0;
break;
case THIN_THICK:
ft->xleft = 6.0;
ft->xright = 0.0;
break;
case PART:
astring = ft->item;
case TEMPO:
break;
case TIME:
afract = ft->item;
if (afract == NULL) {
afract = &v->meter;
};
ft->xleft = 0;
ft->xright = size_timesig(afract);
break;
case KEY:
ft->xleft = 0;
akey = ft->item;
ft->xright = size_keysig(v->keysig->map, akey->map);
set_keysig(v->keysig, akey);
break;
case REST:
arest = ft->item;
sizerest(arest, ft);
if (intuple) {
if (ft->yup > thistuple->height) {
thistuple->height = ft->yup;
};
tuplecount = tuplecount - 1;
if (tuplecount <= 0) {
tuplefeature->yup = thistuple->height + HTUPLE_HT;
intuple = 0;
thistuple = NULL;
tuplefeature = NULL;
};
};
break;
case TUPLE:
thistuple = ft->item;
if (thistuple->beamed == 0) {
intuple = 1;
tuplecount = thistuple ->r;
thistuple->height = (double)(10*TONE_HT);
tuplefeature = ft;
};
break;
case NOTE:
anote = ft->item;
setstemlen(anote, ingrace);
sizenote(anote, ft, ingrace);
if (inchord) {
if (chordcount == 0) {
chordhead = ft;
thischord->ytop = anote->y;
thischord->ybot = anote->y;
chordbeaming = anote->beaming;
} else {
if (anote->y > thischord->ytop) {
thischord->ytop = anote->y;
};
if (anote->y < thischord->ybot) {
thischord->ybot = anote->y;
};
if (ft->xleft > chordhead->xleft) {
chordhead->xleft = ft->xleft;
};
if (ft->xright > chordhead->xright) {
chordhead->xright = ft->xright;
};
if (ft->yup > chordhead->yup) {
chordhead->yup = ft->yup;
};
if (ft->ydown > chordhead->ydown) {
chordhead->ydown = ft->ydown;
};
ft->type = CHORDNOTE;
};
chordcount = chordcount + 1;
};
if (intuple) {
if (ft->yup > thistuple->height) {
thistuple->height = ft->yup;
};
tuplecount = tuplecount - 1;
if (tuplecount <= 0) {
tuplefeature->yup = thistuple->height + HTUPLE_HT;
intuple = 0;
thistuple = NULL;
tuplefeature =NULL;
};
};
break;
case NONOTE:
break;
case OLDTIE:
break;
case TEXT:
break;
case SLUR_ON:
break;
case SLUR_OFF:
break;
case TIE:
break;
case CLOSE_TIE:
break;
case TITLE:
break;
case CHANNEL:
break;
case TRANSPOSE:
break;
case RTRANSPOSE:
break;
case GRACEON:
ingrace = 1;
break;
case GRACEOFF:
ingrace = 0;
break;
case SETGRACE:
break;
case SETC:
break;
case GCHORD:
break;
case GCHORDON:
break;
case GCHORDOFF:
break;
case VOICE:
break;
case CHORDON:
inchord = 1;
chordcount = 0;
thischord = ft->item;
chordplace = ft;
spacechord(chordplace);
break;
case CHORDOFF:
if (thischord != NULL) {
anote = chordhead->item;
thischord->beaming = chordbeaming;
if (thischord->beaming == single) {
sizechord(thischord, ingrace);
};
};
inchord = 0;
chordhead = NULL;
thischord = NULL;
chordplace = NULL;
break;
case SLUR_TIE:
break;
case TNOTE:
break;
case LT:
break;
case GT:
break;
case DYNAMIC:
break;
case LINENUM:
lineno = (int)(ft->item);
break;
case MUSICLINE:
break;
case MUSICSTOP:
break;
case WORDLINE:
break;
case WORDSTOP:
break;
case INSTRUCTION:
break;
case NOBEAM:
break;
case CLEF:
theclef = ft->item;
if (theclef == NULL) {
theclef = v->clef;
};
ft->yup = (double)8*TONE_HT;
ft->ydown = 0.0;
switch (theclef->type) {
case treble:
ft->yup = (double)TREBLE_UP;
ft->ydown = (double)TREBLE_DOWN;
ft->xright = TREBLE_RIGHT;
ft->xleft = TREBLE_LEFT;
break;
case baritone:
ft->yup = (double)12*TONE_HT;
ft->xright = CCLEF_RIGHT;
ft->xleft = CCLEF_LEFT;
break;
case tenor:
ft->yup = (double)10*TONE_HT;
ft->xright = CCLEF_RIGHT;
ft->xleft = CCLEF_LEFT;
break;
case alto:
ft->xright = CCLEF_RIGHT;
ft->xleft = CCLEF_LEFT;
break;
case mezzo:
ft->ydown = (double)2*TONE_HT;
ft->xright = CCLEF_RIGHT;
ft->xleft = CCLEF_LEFT;
break;
case soprano:
ft->ydown = (double)4*TONE_HT;
ft->xright = CCLEF_RIGHT;
ft->xleft = CCLEF_LEFT;
break;
case bass:
ft->xright = BASS_RIGHT;
ft->xleft = BASS_LEFT;
break;
};
if (theclef->octave > 0) {
ft->yup = ft->yup + CLEFNUM_HT;
};
if (theclef->octave < 0) {
ft->ydown = ft->ydown + CLEFNUM_HT;
};
v->clef->type = theclef->type;
v->clef->octave = theclef->octave;
break;
case PRINTLINE:
break;
case NEWPAGE:
break;
case LEFT_TEXT:
break;
case CENTRE_TEXT:
break;
case VSKIP:
break;
default:
printf("unknown type %d\n", ft->type);
break;
};
ft = ft->next;
};
}
static void sizetune(struct tune* t)
/* compute width and height values for all elements in the tune */
{
struct voice* v;
v = firstitem(&t->voices);
while (v != NULL) {
sizevoice(v, t);
v = nextitem(&t->voices);
};
}
static void singlehead(double x, double y, int base, int base_exp, int dots)
/* draws a note head */
{
int i;
double dot_offset;
fprintf(f, "%.1f %.1f ", x, y);
/* note head */
dot_offset = HALF_HEAD;
switch(base_exp) {
case 1:
fprintf(f, "BHD");
dot_offset = HALF_BREVE;
break;
case 0:
fprintf(f, "HD");
break;
case -1:
fprintf(f, "Hd");
break;
default:
if (base_exp > 1) {
fprintf(f, "BHD");
dot_offset = HALF_BREVE;
event_warning("Note value too long to represent");
} else {
fprintf(f, "hd");
};
break;
};
if (dots == -1) {
event_warning("Note value cannot be represented");
};
for (i=1; i <= dots; i++) {
fprintf(f, " %.1f 3.0 dt", (double)(dot_offset+DOT_SPACE*i));
};
}
static void drawhead(struct note* n, double x, struct feature* ft)
/* draw just the head of a note together with any decorations */
/* and accidentals */
{
int i;
char* decorators;
double ytop, ybot;
double notex, accspace;
int offset;
if (n->fliphead) {
if (n->stemup) {
notex = x + 2.0 * HALF_HEAD;
} else {
notex = x - 2.0 * HALF_HEAD;
}
} else {
notex = x;
};
singlehead(notex, (double)(TONE_HT*n->y), n->base, n->base_exp, n->dots);
if (n->acc_offset == 0) {
accspace = ACC_OFFSET;
} else {
if (n->fliphead) {
/* compensate for flipped note head */
if (n->stemup) {
offset = n->acc_offset;
} else {
offset = n->acc_offset - 2;
};
} else {
offset = n->acc_offset - 1;
};
accspace = ACC_OFFSET + ACC_OFFSET2 * offset;
};
switch (n->accidental) {
case '=':
fprintf(f, " %.1f nt", accspace);
break;
case '^':
if (n->mult == 1) {
fprintf(f, " %.1f sh", accspace);
} else {
fprintf(f, " %.1f dsh", accspace);
};
break;
case '_':
if (n->mult == 1) {
fprintf(f, " %.1f ft", accspace);
} else {
fprintf(f, " %.1f dft", accspace);
};
break;
default:
break;
};
i = 10;
while (n->y >= i) {
fprintf(f, " %d hl", i*TONE_HT);
i = i + 2;
};
i = -2;
while (n->y <= i) {
fprintf(f, " %d hl", i*TONE_HT);
i = i - 2;
};
if (n->accents != NULL) {
decorators = n->accents;
ytop = (n->y + 2) * TONE_HT;
ybot = (n->y - 2) * TONE_HT;
if (n->stemup) {
ytop = ytop + n->stemlength;
} else {
ybot = ybot - n->stemlength;
};
for (i=0; i<strlen(decorators); i++) {
switch (decorators[i]) {
case '.':
if (n->stemup) {
fprintf(f, " %.1f stc", ybot+STC_OFF);
ybot = ybot - SMALL_DEC_HT;
} else {
fprintf(f, " %.1f stc", ytop+STC_OFF);
ytop = ytop + SMALL_DEC_HT;
};
break;
case 'R':
if (n->stemup) {
fprintf(f, " %.1f cpd", ybot+CPD_OFF);
ybot = ybot - SMALL_DEC_HT;
} else {
fprintf(f, " %.1f cpu", ytop+CPU_OFF);
ytop = ytop + SMALL_DEC_HT;
};
break;
case 'M':
if (n->stemup) {
fprintf(f, " %.1f emb", ybot+EMB_OFF);
ybot = ybot - SMALL_DEC_HT;
} else {
fprintf(f, " %.1f emb", ytop+EMB_OFF);
ytop = ytop + SMALL_DEC_HT;
};
break;
case 'H':
fprintf(f, " %.1f hld", ytop+HLD_OFF);
ytop = ytop + BIG_DEC_HT;
break;
case '~':
fprintf(f, " %.1f grm", ytop+GRM_OFF);
ytop = ytop + BIG_DEC_HT;
break;
case 'u':
fprintf(f, " %.1f upb", ytop+UPB_OFF);
ytop = ytop + BIG_DEC_HT;
break;
case 'v':
fprintf(f, " %.1f dnb", ytop+DNB_OFF);
ytop = ytop + BIG_DEC_HT;
break;
case 'T':
fprintf(f, " %.1f trl", ytop+TRL_OFF);
ytop = ytop + BIG_DEC_HT;
break;
default:
break;
};
};
};
fprintf(f, "\n");
}
static void drawgracehead(struct note* n, double x, struct feature* ft,
enum tail_type tail)
/* draw the head of a grace note */
{
int i;
double y;
y = (double)(TONE_HT*n->y);
switch (tail) {
case nostem:
/* note head only */
fprintf(f, "%.1f %.1f gn", x, y);
break;
case single:
/* note head with stem and tail */
fprintf(f, "%.1f %.1f %.1f gn1", x, y, n->stemlength);
break;
case midbeam:
case startbeam:
case endbeam:
/* note head with stem and tail */
fprintf(f, "%.1f %.1f %.1f gnt", x, y, n->stemlength);
break;
};
switch (n->accidental) {
case '=':
fprintf(f, " %.1f %.1f gnt0", x-ACC_OFFSET, y);
break;
case '^':
if (n->mult == 1) {
fprintf(f, " %.1f %.1f gsh0", x-ACC_OFFSET, y);
} else {
fprintf(f, " %.1f %.1f gds0h", x-ACC_OFFSET, y);
};
break;
case '_':
if (n->mult == 1) {
fprintf(f, " %.1f %.1f gft0", x-ACC_OFFSET, y);
} else {
fprintf(f, " %.1f %.1f gdf0", x-ACC_OFFSET, y);
};
break;
default:
break;
};
i = 10;
while (n->y >= i) {
fprintf(f, " %.1f %.1f ghl", x, (double)i*TONE_HT);
i = i + 2;
};
i = -2;
while (n->y <= i) {
fprintf(f, " %.1f %.1f ghl", x, (double)i*TONE_HT);
i = i - 2;
};
fprintf(f, "\n");
}
static void handlegracebeam(struct note *n, struct feature* ft)
/* this is called to set up the variables needed to lay out */
/* beams for grace notes */
{
switch (n->beaming) {
case single:
gracebeamctr = -1;
break;
case startbeam:
gracebeamset[0] = ft;
gracebeamctr = 1;
break;
case midbeam:
case endbeam:
if (gracebeamctr > 0) {
gracebeamset[gracebeamctr] = ft;
if (gracebeamctr < 32) {
gracebeamctr = gracebeamctr + 1;
} else {
event_error("Too many notes under one gracebeam");
};
} else {
event_error("Internal beaming error");
exit(1);
};
break;
};
}
static void drawgracenote(struct note* n, double x, struct feature* ft,
struct chord* thischord)
/* draw an entire grace note */
{
handlegracebeam(n, ft);
drawgracehead(n, x, ft, n->beaming);
if (n->beaming == endbeam) {
drawbeam(gracebeamset, gracebeamctr, 1);
};
fprintf(f, "\n");
}
static void singletail(int base, int base_exp, int stemup, double stemlength)
/* draw the tail of a note if it has one */
{
switch(base_exp) {
case 0:
case -1:
case -2:
break;
case -3:
if (stemup) {
fprintf(f, " %.1f f1u", stemlength);
} else {
fprintf(f, " %.1f f1d", stemlength);
};
break;
case -4:
if (stemup) {
fprintf(f, " %.1f f2u", stemlength);
} else {
fprintf(f, " %.1f f2d", stemlength);
};
break;
case -5:
if (stemup) {
fprintf(f, " %.1f f3u", stemlength);
} else {
fprintf(f, " %.1f f3d", stemlength);
};
break;
case -6:
if (stemup) {
fprintf(f, " %.1f f4u", stemlength);
} else {
fprintf(f, " %.1f f4d", stemlength);
};
break;
default:
if (base_exp < -6) {
event_warning("Note value too small to represent");
if (stemup) {
fprintf(f, " %.1f f4u", stemlength);
} else {
fprintf(f, " %.1f f4d", stemlength);
};
};
break;
};
}
static void drawchordtail(struct chord* ch, double x)
/* draw the tail to a set of notes belonging to a single chord */
{
if (ch->base > 1) {
fprintf(f, "%.1f setx ", x);
if (ch->stemup) {
fprintf(f, "%.1f sety ", (double)(ch->ybot*TONE_HT));
fprintf(f, " %.1f su ", ch->stemlength +
(double)((ch->ytop - ch->ybot)*TONE_HT));
} else {
fprintf(f, "%.1f sety ", (double)(ch->ytop*TONE_HT));
fprintf(f, " %.1f sd ", ch->stemlength +
(double)((ch->ytop - ch->ybot)*TONE_HT));
};
if (ch->beaming == single) {
singletail(ch->base, ch->base_exp, ch->stemup, ch->stemlength+
(double)((ch->ytop - ch->ybot)*TONE_HT));
};
fprintf(f, "\n");
};
}
static void showtext(struct llist* textitems, double x, double ystart, double ygap)
/* This routine deals with lyrics, guitar chords and instructions */
/* print text item at specified point */
/* if a string starts with ':' this means it is a special symbol */
{
double ygc;
char* gc;
gc = firstitem(textitems);
ygc = ystart;
while (gc != NULL) {
if (*gc == ':') {
switch (*(gc+1)) {
case 'p': /* part label */
fprintf(f, " %.1f %.1f %.1f (", x, ygc, ygap);
ISOfprintf(gc+2);
fprintf(f, ") boxshow ");
break;
case 's':
fprintf(f, " %.1f %.1f segno\n", x, ygc);
break;
case 'c':
fprintf(f, " %.1f %.1f coda\n", x, ygc);
break;
default:
break;
};
} else {
fprintf(f, " %.1f %.1f (", x, ygc);
ISOfprintf(gc);
fprintf(f, ") gc ");
};
gc = nextitem(textitems);
ygc = ygc - ygap;
};
}
static void define_font(struct font* thefont, char* s)
/* set up a font structure with user-defined font and pointsize */
{
char fontname[80];
int fontsize, params;
params = sscanf(s, "%s %d", fontname, &fontsize);
if (params >= 1) {
if (strcmp(fontname, "-") != 0) {
if (thefont->name != NULL) {
free(thefont->name);
};
thefont->name = addstring(fontname);
thefont->defined = 0;
};
if (params == 2) {
thefont->pointsize = fontsize;
};
};
}
int read_boolean(s)
char *s;
/* set logical parameter from %%command */
/* part of the handling for event_specific */
{
char p[10];
int result;
p[0] = '\0';
sscanf(s, " %10s", p);
result = 1;
if ((strcmp(p, "0") == 0) || (strcmp(p, "no") == 0) ||
(strcmp(p, "false") == 0)) {
result = 0;
};
return(result);
}
void font_command(p, s)
/* execute font-related %%commands */
/* called from event_specific */
char* p;
char*s;
{
if (strcmp(p, "textfont") == 0) {
define_font(&textfont, s);
};
if (strcmp(p, "titlefont") == 0) {
define_font(&titlefont, s);
};
if (strcmp(p, "subtitlefont") == 0) {
define_font(&subtitlefont, s);
};
if (strcmp(p, "wordsfont") == 0) {
define_font(&wordsfont, s);
};
if (strcmp(p, "composerfont") == 0) {
define_font(&composerfont, s);
};
if (strcmp(p, "vocalfont") == 0) {
define_font(&vocalfont, s);
};
if (strcmp(p, "gchordfont") == 0) {
define_font(&gchordfont, s);
};
if (strcmp(p, "partsfont") == 0) {
define_font(&partsfont, s);
};
if (strcmp(p, "titlespace") == 0) {
set_space(&titlefont, s);
};
if (strcmp(p, "subtitlespace") == 0) {
set_space(&subtitlefont, s);
};
if (strcmp(p, "composerspace") == 0) {
set_space(&composerfont, s);
};
if (strcmp(p, "vocalspace") == 0) {
set_space(&vocalfont, s);
};
if (strcmp(p, "wordsspace") == 0) {
set_space(&wordsfont, s);
};
if (strcmp(p, "gchordspace") == 0) {
set_space(&gchordfont, s);
};
if (strcmp(p, "textspace") == 0) {
set_space(&textfont, s);
};
if (strcmp(p, "partsspace") == 0) {
set_space(&textfont, s);
};
if (strcmp(p, "staffsep") == 0) {
sscanf(s, "%d", &staffsep);
};
if (strcmp(p, "titleleft") == 0) {
titleleft = read_boolean(s);
};
if (strcmp(p, "titlecaps") == 0) {
titlecaps = read_boolean(s);
};
}
static void setfont(int size, int num)
/* define font point size and style */
{
if ((fontsize != size) || (fontnum != num)) {
fprintf(f, "%d.0 F%d\n", size, num);
fontsize = size;
fontnum = num;
};
}
static void setfontstruct(struct font* thefont)
/* set font according to font structure */
{
if (thefont->name == NULL) {
setfont(thefont->pointsize, thefont->default_num);
} else {
if (thefont->defined == 0) {
/* define font */
fprintf(f, "/%s-ISO /%s setISOfont\n", thefont->name, thefont->name);
fprintf(f, "/F%d { /%s-ISO exch selectfont} def\n",
thefont->special_num, thefont->name);
thefont->defined = 1;
}
setfont(thefont->pointsize, thefont->special_num);
};
}
static void notetext(struct note* n, int* tupleno, double x, struct feature* ft,
struct vertspacing* spacing)
/* print text associated with note */
{
if (n->beaming == endbeam) {
drawbeam(beamset, beamctr, 0);
if (*tupleno != 0) {
drawtuple(beamset, beamctr, *tupleno);
*tupleno = 0;
};
};
fprintf(f, "\n");
if (n->instructions != NULL) {
setfontstruct(&partsfont);
showtext(n->instructions, x - ft->xleft, spacing->yinstruct,
(double)(partsfont.pointsize+partsfont.space));
};
if (n->gchords != NULL) {
setfontstruct(&gchordfont);
showtext(n->gchords, x - ft->xleft, spacing->ygchord,
(double)(gchordfont.pointsize+gchordfont.space));
};
if (n->syllables != NULL) {
setfontstruct(&vocalfont);
showtext(n->syllables, x - ft->xleft, spacing->ywords,
(double)(vocalfont.pointsize + vocalfont.space));
};
}
static void handlebeam(struct note* n, struct feature* ft)
/* set up some variables needed to lay out the beam for a set of */
/* notes beamed together */
{
switch (n->beaming) {
case single:
beamctr = -1;
break;
case startbeam:
beamset[0] = ft;
beamctr = 1;
rootstem = n->stemup;
break;
case midbeam:
case endbeam:
if (beamctr > 0) {
beamset[beamctr] = ft;
if (beamctr < 64) {
beamctr = beamctr + 1;
} else {
event_error("Too many notes under one beam");
};
} else {
event_error("Internal beaming error");
};
n->stemup = rootstem;
break;
};
}
static void drawnote(struct note* n, double x, struct feature* ft,
struct chord* thischord,
int* tupleno, struct vertspacing* spacing)
/* draw a note */
{
handlebeam(n, ft);
drawhead(n, x, ft);
if (thischord == NULL) {
if (n->base > 1) {
if (n->stemup) {
fprintf(f, " %.1f su", n->stemlength);
} else {
fprintf(f, " %.1f sd", n->stemlength);
};
};
};
if (n->beaming == single) {
singletail(n->base, n->base_exp, n->stemup, n->stemlength);
};
notetext(n, tupleno, x, ft, spacing);
fprintf(f, "\n");
}
static void drawrest(struct rest* r, double x, struct vertspacing* spacing)
/* draw a rest of specified duration */
{
int i;
reducef(&r->len);
switch (r->base_exp) {
case 1:
fprintf(f, "%.1f %d r0 ", x, 4*TONE_HT);
break;
case 0:
fprintf(f, "%.1f %d r1 ", x, 4*TONE_HT);
break;
case -1:
fprintf(f, "%.1f %d r2 ", x, 4*TONE_HT);
break;
case -2:
fprintf(f, "%.1f %d r4 ", x, 4*TONE_HT);
break;
case -3:
fprintf(f, "%.1f %d r8 ", x, 4*TONE_HT);
break;
case -4:
fprintf(f, "%.1f %d r16 ", x, 4*TONE_HT);
break;
case -5:
fprintf(f, "%.1f %d r32 ", x, 4*TONE_HT);
break;
case -6:
fprintf(f, "%.1f %d r64 ", x, 4*TONE_HT);
break;
default:
event_error("Cannot represent rest length");
break;
};
for (i=1; i <= r->dots; i++) {
fprintf(f, " %.1f 3.0 dt", (double)(HALF_HEAD+DOT_SPACE*i));
};
fprintf(f, "\n");
if (r->instructions != NULL) {
setfontstruct(&partsfont);
showtext(r->instructions, x, spacing->yinstruct,
(double)(partsfont.pointsize+partsfont.space));
};
if (r->gchords != NULL) {
setfontstruct(&gchordfont);
showtext(r->gchords, x, spacing->ygchord,
(double)(gchordfont.pointsize+gchordfont.space));
};
}
static void setbeams(struct feature* note[], struct chord* chording[], int m,
double stemlen)
/* choose the spatial postioning of beams and compute appropriate stem */
/* lengths for all notes within the beam */
{
int i;
double min[64];
double lift;
struct note* anote;
int stemup;
double x1, y1, x2, y2, xi, yi;
double max;
/* printf("Doing setbeams m=%d\n", m); */
anote = note[0]->item;
stemup = anote->stemup;
/* calculate minimum feasible stem lengths */
/* bearing in mind space needed for the tails */
for (i=0; i<m; i++) {
anote = note[i]->item;
anote->stemup = stemup;
switch (anote->base) {
default:
case 8:
min[i] = TAIL_SEP;
break;
case 16:
min[i] = 2*TAIL_SEP;
break;
case 32:
min[i] = 3*TAIL_SEP;
break;
case 64:
min[i] = 4*TAIL_SEP;
break;
};
if (anote->accidental == ' ') {
min[i] = min[i] + TONE_HT;
} else {
if (stemup) {
min[i] = min[i] + (double)acc_upsize(anote->accidental);
} else {
min[i] = min[i] + (double)acc_downsize(anote->accidental);
};
};
min[i] = min[i] + TONE_HT; /* require at least this much clearance */
if (stemup) {
if (chording[i] == NULL) {
min[i] = TONE_HT*anote->y + min[i];
/* avoid collision with previous note */
if ((i > 0) && (min[i-1] - TONE_HT < min[i])) {
min[i-1] = min[i];
};
} else {
min[i] = TONE_HT*chording[i]->ytop + min[i];
};
} else {
if (chording[i] == NULL) {
min[i] = TONE_HT*anote->y - min[i];
/* avoid collision with previous note */
if (i > 0) {
anote = note[i-1]->item;
if (anote->y*TONE_HT < min[i]) {
min[i] = anote->y*TONE_HT;
};
};
} else {
min[i] = TONE_HT*chording[i]->ybot - min[i];
};
};
};
/* work out clearance from a straight line between 1st and last note */
x1 = note[0]->x;
anote = note[0]->item;
y1 = anote->y*TONE_HT;
x2 = note[m-1]->x;
anote = note[m-1]->item;
y2 = anote->y*TONE_HT;
if (x1 == x2) {
printf("Internal error: x1 = x2 = %.1f\n", x1);
x2 = x2 + 1;
};
lift = 0.0;
max = 0.0;
if (stemup) {
for (i=0; i<m; i++) {
xi = note[i]->x;
yi = y1 + (y2-y1)*(xi-x1)/(x2-x1);
if (min[i] - yi > lift) {
lift = min[i] - yi;
};
if (min[i] - yi < max) {
max = min[i] - yi;
};
};
if (lift - max < stemlen) {
lift = stemlen - max;
};
} else {
for (i=0; i<m; i++) {
xi = note[i]->x;
yi = y1 + (y2-y1)*(xi-x1)/(x2-x1);
if (min[i] - yi < lift) {
lift = min[i] - yi;
};
if (min[i] - yi > max) {
max = min[i] - yi;
};
};
if (max - lift < stemlen) {
lift = max - stemlen;
};
};
/* raise the line just enough to clear notes */
for (i=0; i<m; i++) {
anote = note[i]->item;
xi = note[i]->x;
if (stemup) {
anote->stemlength = y1 + (y2-y1)*(xi-x1)/(x2-x1) + lift -
TONE_HT*anote->y;
} else {
anote->stemlength = -(y1 + (y2-y1)*(xi-x1)/(x2-x1) + lift -
TONE_HT*anote->y);
};
};
/* now transfer results to chords */
for (i=0; i<m; i++) {
if (chording[i] != NULL) {
anote = note[i]->item;
chording[i]->stemup = anote->stemup;
if (chording[i]->stemup) {
chording[i]->stemlength = anote->stemlength;
} else {
chording[i]->stemlength = anote->stemlength -
(double)((chording[i]->ytop - chording[i]->ybot)*TONE_HT);
};
};
};
};
static void beamline(struct feature* ft)
/* compute positioning of beams for one stave line of music */
{
struct feature* p;
struct note* n;
struct feature* beamnote[64];
struct chord* chording[64];
struct chord* lastchord;
struct feature* gracebeamnote[64];
struct chord* gracechording[64];
struct chord* gracelastchord;
int i, j;
int ingrace;
p = ft;
ingrace = 0;
lastchord = NULL;
gracelastchord = NULL;
while ((p != NULL) && (p->type != PRINTLINE)) {
switch (p->type) {
case NOTE:
if (ingrace) {
n = p->item;
if (n == NULL) {
event_error("Missing NOTE!!!!");
exit(0);
};
if (n->beaming == startbeam) {
j = 0;
};
if (n->beaming != single) {
gracebeamnote[j] = p;
gracechording[j] = gracelastchord;
j = j + 1;
};
if ((n->beaming == endbeam)||(j==10)) {
setbeams(gracebeamnote, gracechording, j, GRACE_STEMLEN);
j = 0;
};
} else {
/* non-grace notes*/
n = p->item;
if (n == NULL) {
event_error("Missing NOTE!!!!");
exit(0);
};
if (n->beaming == startbeam) {
i = 0;
};
if (n->beaming != single) {
beamnote[i] = p;
chording[i] = lastchord;
i = i + 1;
};
if ((n->beaming == endbeam)||(i==64)) {
setbeams(beamnote, chording, i, STEMLEN);
i = 0;
};
};
break;
case CHORDON:
if (ingrace) {
gracelastchord = p->item;
} else {
lastchord = p->item;
};
break;
case CHORDOFF:
if (ingrace) {
gracelastchord = NULL;
} else {
lastchord = NULL;
};
break;
case GRACEON:
ingrace = 1;
break;
case GRACEOFF:
ingrace = 0;
gracelastchord = NULL;
break;
default:
break;
};
p = p->next;
};
}
static void measureline(struct feature* ft, double* height, double* descender,
double* yend, double* yinstruct, double* ygchord, double* ywords)
/* calculate vertical space (height/descender) requirement of current line */
{
struct feature* p;
struct note* n;
struct rest* r;
double max, min;
int gotgchords, gcount;
int gotinstructions, icount;
int gotwords, wcount;
int gotends;
char* gc;
p = ft;
min = 0.0;
max = 8*TONE_HT;
gotgchords = 0;
gotwords = 0;
gotinstructions = 0;
gotends = 0;
while ((p != NULL) && (p->type != PRINTLINE)) {
switch (p->type) {
case NOTE:
n = p->item;
if (n == NULL) {
event_error("Missing NOTE!!!!");
exit(0);
} else {
if (n->gchords != NULL) {
gcount = 0;
gc = firstitem(n->gchords);
while (gc != NULL) {
gcount = gcount + 1;
gc = nextitem(n->gchords);
};
if (gcount > gotgchords) {
gotgchords = gcount;
};
};
if (n->instructions != NULL) {
icount = 0;
gc = firstitem(n->instructions);
while (gc != NULL) {
icount = icount + 1;
gc = nextitem(n->instructions);
};
if (icount > gotwords) {
gotinstructions = icount;
};
};
if (n->syllables != NULL) {
wcount = 0;
gc = firstitem(n->syllables);
while (gc != NULL) {
wcount = wcount + 1;
gc = nextitem(n->syllables);
};
if (wcount > gotwords) {
gotwords = wcount;
};
};
/* recalculate note size in case of new stemlen */
sizenote(n, p, ingrace);
if (p->yup > max) {
max = p->yup;
};
if (p->ydown < min) {
min = p->ydown;
};
};
break;
case REST:
r = p->item;
if (r == NULL) {
event_error("Missing REST!!!!");
exit(0);
} else {
if (r->gchords != NULL) {
gcount = 0;
gc = firstitem(r->gchords);
while (gc != NULL) {
gcount = gcount + 1;
gc = nextitem(r->gchords);
};
if (gcount > gotgchords) {
gotgchords = gcount;
};
};
if (r->instructions != NULL) {
icount = 0;
gc = firstitem(r->instructions);
while (gc != NULL) {
icount = icount + 1;
gc = nextitem(r->instructions);
};
if (icount > gotwords) {
gotinstructions = icount;
};
};
};
break;
case REP1:
case REP2:
case PLAY_ON_REP:
case BAR1:
case REP_BAR2:
gotends = 1;
break;
case TUPLE:
case CLEF:
if (p->yup > max) {
max = p->yup;
};
if (-(p->ydown) < min) {
min = -(p->ydown);
};
break;
default:
break;
};
p = p->next;
};
if ((gotgchords > 0) && (gchords_above)) {
max = max + (gchordfont.pointsize + gchordfont.space)*gotgchords;
*ygchord = max - (gchordfont.pointsize + gchordfont.space);
};
if (gotinstructions > 0) {
max = max + INSTRUCT_HT*gotinstructions;
*yinstruct = max - INSTRUCT_HT;
};
if (gotends) {
max = max + END_HT;
*yend = max - END_HT;
};
if ((gotgchords > 0) && (!gchords_above)) {
*ygchord = min - (gchordfont.pointsize + gchordfont.space);
min = min - (gchordfont.pointsize + gchordfont.space)*gotgchords;
};
if (gotwords > 0) {
*ywords = min - (vocalfont.pointsize + vocalfont.space);
min = min - (vocalfont.pointsize + vocalfont.space)*gotwords;
};
*height = staffsep + max;
*descender = -min;
}
static void printtext(place, s, afont)
enum placetype place;
char* s;
struct font* afont;
/* print text a line of text in specified font at specified place */
{
newblock((double)(afont->pointsize + afont->space), 0.0);
setfontstruct(afont);
fprintf(f, "(");
ISOfprintf(s);
switch (place) {
case left:
fprintf(f, ") 0 0 M show\n");
break;
case right:
fprintf(f, ") %.1f 0 M lshow\n", (double) scaledwidth);
break;
case centre:
fprintf(f, ") %.1f 0 M cshow\n", scaledwidth/2.0);
break;
};
}
void vskip(double gap)
/* skip over specified amount of vertical space */
{
newblock(gap, 0.0);
}
void centretext(s)
char* s;
/* print text centred in the middle of the page */
/* used by %%centre command */
{
printtext(centre, s, &textfont);
}
void lefttext(s)
char* s;
/* print text up against the left hand margin */
/* used by %%text command */
{
printtext(left, s, &textfont);
}
static void draw_tempo(double x, double y, struct atempo* t)
/* print out tempo as specified in Q: field */
/* this goes to the left of the tune's title */
{
int base, base_exp, dots;
if (t != NULL) {
/* fprintf(f, "gsave 0.7 0.7 scale\n"); */
setfont(12, 3);
dots = count_dots(&base, &base_exp, t->basenote.num, t->basenote.denom);
singlehead(x, y, base, base_exp, dots);
if (base >= 2) {
fprintf(f, " %.1f su", TEMPO_STEMLEN);
};
singletail(base, base_exp, 1, TEMPO_STEMLEN);
fprintf(f, " %.1f %.1f M (= %d) show\n", x + 20.0, y, t->count);
/* fprintf(f, "grestore\n"); */
};
}
static void voicedivider()
/* This draws a horizontal line. It is used to mark where one voice */
/* ends and the next one starts */
{
newblock((double)staffsep, 0.0);
fprintf(f, " %.1f %.1f M %.1f %.1f L\n",
scaledwidth/4.0, -descend,
scaledwidth*3/4.0, -descend);
newblock((double)staffsep, 0.0);
}
static void resetvoice(struct tune* t, struct voice * v)
/* sets up voice with initial attributes as defined in abc tune header */
{
v->place = v->first;
if (v->clef == NULL) {
v->clef = newclef(t->clef.type, t->clef.octave);
} else {
v->clef->type = t->clef.type;
v->clef->octave = t->clef.octave;
};
if (v->keysig == NULL) {
v->keysig = newkey(t->keysig->name, t->keysig->sharps,
t->keysig->map, t->keysig->mult);
} else {
free(v->keysig->name);
v->keysig->name = addstring(t->keysig->name);
set_keysig(v->keysig, t->keysig);
/* v->keysig->sharps = t->keysig->sharps; */
};
v->meter.num = t->meter.num;
v->meter.denom = t->meter.denom;
}
static void resettune(struct tune* t)
/* initializes all voices to their start state */
{
struct voice* v;
v = firstitem(&t->voices);
while (v != NULL) {
resetvoice(t, v);
v = nextitem(&t->voices);
};
}
void setup_fonts()
{
init_font(&textfont, TEXT_HT, 1, 1, 5);
init_font(&titlefont, TITLE1_HT, 0, 0, 6);
init_font(&subtitlefont, TITLE2_HT, 0, 0, 7);
init_font(&wordsfont, WORDS_HT, 1, 0, 8);
init_font(&composerfont, COMP_HT, 1, 1, 9);
init_font(&vocalfont, LYRIC_HT, 1, 2, 10);
init_font(&gchordfont, CHORDNAME_HT, 1, 3, 11);
init_font(&partsfont, INSTRUCT_HT, 1, 3, 12);
staffsep = VERT_GAP;
}
void open_output_file(filename, boundingbox)
char* filename;
struct bbox* boundingbox;
/* open output file and write the abc2ps library to it */
{
f = fopen(filename, "w");
if (f == NULL) {
printf("Could not open file!!\n");
exit(0);
};
printf("writing file %s\n", filename);
printlib(f, filename, boundingbox);
fontsize = 0;
fontnum = 0;
startpage();
}
void close_output_file()
/* complete last page and close file */
{
closepage();
fclose(f);
}
static int endrep(inend, end_string, x1, x2, yend)
int inend;
char* end_string;
double x1, x2, yend;
/* draws either 1st or 2nd ending marker */
{
if (inend != 0) {
fprintf(f, "%.1f %.1f %.1f (%s) endy1\n", yend, x1, x2, end_string);
};
return(0);
}
static void drawslurtie(struct slurtie* s)
/* draws slur or tie corresponding to the given structure */
{
double x0, y0, x1, y1;
struct feature* ft;
struct note* n;
struct rest* r;
ft = s->begin;
if (ft == NULL) {
event_error("Slur or tie missing start note");
return;
};
x0 = ft->x;
if ((ft->type == NOTE) || (ft->type == CHORDNOTE)) {
n = ft->item;
y0 = (double)(n->y * TONE_HT);
} else {
if (ft->type == REST) {
r = ft->item;
y0 = (double)(4 * TONE_HT);
} else {
printf("Internal error: NOT A NOTE/REST (%d)in slur/tie\n" ,ft->type);
return;
};
};
if (s->crossline) {
/* draw to end of stave */
x1 = scaledwidth + xmargin/(2.0*scale);
y1 = y0;
} else {
/* draw slur/tie to other element */
ft = s->end;
if (ft == NULL) {
event_error("Slur or tie missing end note");
return;
};
x1 = ft->x;
if ((ft->type == NOTE) || (ft->type == CHORDNOTE)) {
n = ft->item;
y1 = (double)(n->y * TONE_HT);
} else {
if (ft->type == REST) {
r = ft->item;
y1 = (double)(4 * TONE_HT);
} else {
printf("Internal error: NOT A NOTE/REST (%d)in slur/tie\n" ,ft->type);
return;
};
};
};
if (n->stemup) {
fprintf(f, " %.1f %.1f %.1f %.1f slurdown\n", x0, y0, x1, y1);
} else {
fprintf(f, " %.1f %.1f %.1f %.1f slurup\n", x0, y0, x1, y1);
};
}
static void close_slurtie(struct slurtie* s)
/* This deals with the special case of a slur or tie running beyond */
/* one line of music and into the next. This draws the part on the */
/* second line of music */
{
double x0, y0, x1, y1;
struct feature* ft;
struct note* n;
struct rest* r;
if ((s == NULL) || (s->crossline == 0)) {
return;
} else {
/* draw slur/tie to other element */
ft = s->end;
if (ft == NULL) {
event_error("Slur or tie missing end note");
return;
};
x1 = ft->x;
if ((ft->type == NOTE) || (ft->type == CHORDNOTE)) {
n = ft->item;
y1 = (double)(n->y * TONE_HT);
} else {
if (ft->type == REST) {
r = ft->item;
y1 = (double)(4 * TONE_HT);
} else {
printf("Internal error: NOT A NOTE/REST (%d)in slur/tie\n" ,ft->type);
return;
};
};
};
x0 = TREBLE_LEFT + TREBLE_RIGHT;
y0 = y1;
if (n->stemup) {
fprintf(f, " %.1f %.1f %.1f %.1f slurdown\n", x0, y0, x1, y1);
} else {
fprintf(f, " %.1f %.1f %.1f %.1f slurup\n", x0, y0, x1, y1);
};
}
static void blockline(struct voice* v, struct vertspacing** spacing)
/* gets vertical spacing for current line */
{
struct feature* ft;
/* struct vertspacing* spacing; */
ft = v->place;
/* find end of line */
while ((ft != NULL) && (ft->type != PRINTLINE)) {
ft = ft->next;
};
if ((ft != NULL) && (ft->type == PRINTLINE)) {
*spacing = ft->item;
} else {
*spacing = NULL;
event_error("Expecting line of music - possible voices mis-match");
};
}
static void underbar(struct feature* ft)
/* This is never normally called, but is useful as a debugging routine */
/* shows width of a graphical element */
{
fprintf(f, " %.1f -10 moveto %.1f -10 lineto stroke\n", ft->x - ft->xleft,
ft->x + ft->xright);
}
static int printvoiceline(struct voice* v)
/* draws one line of music from specified voice */
{
struct feature* ft;
struct note* anote;
struct key* akey;
char* astring;
struct fract* afract;
struct rest* arest;
struct tuple* atuple;
double x;
int sharps;
struct chord* thischord;
int chordcount;
double xchord;
struct aclef* theclef;
int printedline;
double xend;
int inend;
char endstr[80];
int ingrace;
struct vertspacing* spacing;
/* skip over line number so we can check for end of tune */
while ((v->place != NULL) &&
((v->place->type == LINENUM) || (v->place->type == NEWPAGE) ||
(v->place->type == LEFT_TEXT) || (v->place->type == CENTRE_TEXT) ||
(v->place->type == VSKIP))) {
if (v->place->type == LINENUM) {
lineno = (int)(v->place->item);
};
if (v->place->type == NEWPAGE) {
newpage();
};
if (v->place->type == LEFT_TEXT) {
printtext(left, v->place->item, &textfont);
};
if (v->place->type == CENTRE_TEXT) {
printtext(centre, v->place->item, &textfont);
};
if (v->place->type == VSKIP) {
vskip((double)((int)v->place->item));
};
v->place = v->place->next;
};
if (v->place == NULL) {
return(0);
};
inend = 0;
ingrace = 0;
chordcount = 0;
v->beamed_tuple_pending = 0;
x = 20;
thischord = NULL;
if (v->keysig == NULL) {
event_error("Voice has no key signature");
} else {
sharps = v->keysig->sharps;
};
/* draw stave */
ft = v->place;
blockline(v, &spacing);
if (spacing != NULL) {
newblock(spacing->height, spacing->descender);
staveline();
fprintf(f, "0 0 M 0 24 L\n");
};
x = 0.0;
/* now draw the line */
printedline = 0;
while ((ft != NULL) && (!printedline)) {
/* printf("type = %d\n", ft->type); */
switch (ft->type) {
case SINGLE_BAR:
fprintf(f, "%.1f bar\n", ft->x);
break;
case DOUBLE_BAR:
fprintf(f, "%.1f dbar\n", ft->x);
inend = endrep(inend, endstr, xend, ft->x, spacing->yend);
break;
case BAR_REP:
fprintf(f, "%.1f fbar1 %.1f rdots\n", ft->x, ft->x+10);
inend = endrep(inend, endstr, xend, ft->x, spacing->yend);
break;
case REP_BAR:
fprintf(f, "%.1f rdots %.1f fbar2\n", ft->x, ft->x+10);
inend = endrep(inend, endstr, xend, ft->x, spacing->yend);
break;
case REP1:
inend = endrep(inend, endstr, xend, ft->x - ft->xleft, spacing->yend);
inend = 1;
strcpy(endstr, "1");
xend = ft->x + ft->xright;
break;
case REP2:
inend = endrep(inend, endstr, xend, ft->x - ft->xleft, spacing->yend);
inend = 2;
strcpy(endstr, "2");
xend = ft->x + ft->xright;
break;
case PLAY_ON_REP:
inend = endrep(inend, endstr, xend, ft->x - ft->xleft, spacing->yend);
inend = 1;
strcpy(endstr, ft->item);
xend = ft->x + ft->xright;
break;
case BAR1:
fprintf(f, "%.1f bar\n", ft->x);
inend = endrep(inend, endstr, xend, ft->x - ft->xleft, spacing->yend);
inend = 1;
strcpy(endstr, "1");
xend = ft->x + ft->xright;
break;
case REP_BAR2:
fprintf(f, "%.1f rdots %.1f fbar2\n", ft->x, ft->x+10);
inend = endrep(inend, endstr, xend, ft->x - ft->xleft, spacing->yend);
inend = 2;
strcpy(endstr, "2");
xend = ft->x + ft->xright;
break;
case DOUBLE_REP:
fprintf(f, "%.1f fbar1 %.1f rdots %.1f fbar2 %.1f rdots\n",
ft->x, ft->x+10, ft->x+2, ft->x-8);
inend = endrep(inend, endstr, xend, ft->x, spacing->yend);
break;
case THICK_THIN:
fprintf(f, "%.1f fbar1\n", ft->x);
inend = endrep(inend, endstr, xend, ft->x, spacing->yend);
break;
case THIN_THICK:
fprintf(f, "%.1f fbar2\n", ft->x);
inend = endrep(inend, endstr, xend, ft->x, spacing->yend);
break;
case PART:
astring = ft->item;
break;
case TEMPO:
break;
case TIME:
afract = ft->item;
if (afract==NULL) {
if (v->line == midline) {
draw_meter(&v->meter, ft->x);
};
} else {
setfract(&v->meter, afract->num, afract->denom);
if (v->line == midline) {
draw_meter(afract, ft->x);
};
};
break;
case KEY:
akey = ft->item;
if (v->line == midline) {
draw_keysig(v->keysig->map, akey->map, akey->mult, ft->x, v->clef);
};
set_keysig(v->keysig, akey);
break;
case REST:
arest = ft->item;
drawrest(arest, ft->x, spacing);
if (v->tuple_count > 0) {
if (v->tuple_count == v->tuplenotes) {
v->tuple_xstart = ft->x - ft->xleft;
};
if (v->tuple_count == 1) {
v->tuple_xend = ft->x + ft->xright;
drawhtuple(v->tuple_xstart, v->tuple_xend, v->tuplelabel,
v->tuple_height+4.0);
};
v->tuple_count = v->tuple_count - 1;
};
break;
case TUPLE:
atuple = ft->item;
if (atuple->beamed) {
v->beamed_tuple_pending = atuple->n;
v->tuplenotes = atuple->r;
v->tuple_count = 0;
} else {
v->tuple_height = atuple->height;
v->tuplenotes = atuple->r;
v->tuplelabel = atuple->label;
v->tuple_count = atuple->r;
};
break;
case NOTE:
anote = ft->item;
if (thischord == NULL) {
if (ingrace) {
drawgracenote(anote, ft->x, ft, thischord);
} else {
drawnote(anote, ft->x, ft, thischord, &v->beamed_tuple_pending,
spacing);
if (v->tuple_count > 0) {
if (v->tuple_count == v->tuplenotes) {
v->tuple_xstart = ft->x - ft->xleft;
};
if (v->tuple_count == 1) {
v->tuple_xend = ft->x + ft->xright;
drawhtuple(v->tuple_xstart, v->tuple_xend, v->tuplelabel,
v->tuple_height+4.0);
};
v->tuple_count = v->tuple_count - 1;
};
};
} else {
xchord = ft->x; /* make sure all chord heads are aligned */
if (ingrace) {
handlegracebeam(anote, ft);
drawgracehead(anote, ft->x, ft, nostem);
} else {
handlebeam(anote, ft);
drawhead(anote, ft->x, ft);
if (chordcount == 0) {
notetext(anote, &v->beamed_tuple_pending, ft->x, ft, spacing);
};
chordcount = chordcount + 1;
};
};
break;
case CHORDNOTE:
anote = ft->item;
if (ingrace) {
drawgracehead(anote, xchord, ft, nostem);
} else {
drawhead(anote, xchord, ft);
};
break;
case NONOTE:
break;
case OLDTIE:
break;
case TEXT:
break;
case SLUR_ON:
drawslurtie(ft->item);
break;
case SLUR_OFF:
close_slurtie(ft->item);
break;
case TIE:
drawslurtie(ft->item);
break;
case CLOSE_TIE:
close_slurtie(ft->item);
break;
case TITLE:
break;
case CHANNEL:
break;
case TRANSPOSE:
break;
case RTRANSPOSE:
break;
case GRACEON:
ingrace = 1;
break;
case GRACEOFF:
ingrace = 0;
break;
case SETGRACE:
break;
case SETC:
break;
case GCHORD:
break;
case GCHORDON:
break;
case GCHORDOFF:
break;
case VOICE:
break;
case CHORDON:
thischord = ft->item;
chordcount = 0;
drawchordtail(thischord, ft->next->x);
break;
case CHORDOFF:
thischord = NULL;
break;
case SLUR_TIE:
break;
case TNOTE:
break;
case LT:
break;
case GT:
break;
case DYNAMIC:
break;
case LINENUM:
lineno = (int)(ft->item);
break;
case MUSICLINE:
v->line = midline;
break;
case PRINTLINE:
inend = endrep(inend, endstr, xend, scaledwidth, spacing->yend);
printedline = 1;
v->line = newline;
break;
case MUSICSTOP:
break;
case WORDLINE:
break;
case WORDSTOP:
break;
case INSTRUCTION:
break;
case NOBEAM:
break;
case CLEF:
theclef = ft->item;
if (theclef != NULL) {
v->clef->type = theclef->type;
v->clef->octave = theclef->octave;
};
if (v->line == midline) {
printclef(v->clef, ft->x, ft->yup, ft->ydown);
};
break;
case NEWPAGE:
event_warning("newpage in music line ignored");
break;
case LEFT_TEXT:
event_warning("text in music line ignored");
break;
case CENTRE_TEXT:
event_warning("centred text in music line ignored");
break;
case VSKIP:
event_warning("%%vskip in music line ignored");
break;
default:
printf("unknown type: %d\n", (int)ft->type);
break;
};
ft = ft->next;
};
v->place = ft;
return(1);
}
static int finalsizeline(struct voice* v)
/* does final beaming and works out vertical height for */
/* one line of specified voice */
{
struct feature* ft;
double height, descender;
double yend, yinstruct, ygchord, ywords;
struct vertspacing* avertspacing;
/* skip over line number so we can check for end of tune */
while ((v->place != NULL) &&
((v->place->type == LINENUM) || (v->place->type == NEWPAGE) ||
(v->place->type == LEFT_TEXT) || (v->place->type == CENTRE_TEXT) ||
(v->place->type == VSKIP))) {
v->place = v->place->next;
};
if (v->place == NULL) {
return(0);
};
ft = v->place;
beamline(ft);
measureline(ft, &height, &descender, ¥d, &yinstruct, &ygchord, &ywords);
/* newblock(height, descender); */
/* find end of line */
while ((ft != NULL) && (ft->type != PRINTLINE)) {
ft = ft->next;
};
if ((ft != NULL) && (ft->type == PRINTLINE)) {
avertspacing = ft->item;
avertspacing->height = height;
avertspacing->descender = descender;
avertspacing->yend = yend;
avertspacing->yinstruct = yinstruct;
avertspacing->ygchord = ygchord;
avertspacing->ywords = ywords;
ft = ft->next;
};
v->place = ft;
return(1);
}
static void finalsizetune(t)
struct tune* t;
/* calculate beaming and calculate height of each music line */
{
struct voice* thisvoice;
int doneline;
thisvoice = firstitem(&t->voices);
while (thisvoice != NULL) {
doneline = 1;
while (doneline==1) {
doneline = finalsizeline(thisvoice);
};
thisvoice = nextitem(&t->voices);
};
}
static int getlineheight(struct voice* v, double* height)
/* calculate vertical space for one line of music from specified voice */
{
struct vertspacing* spacing;
/* go over between line stuff */
while ((v->place != NULL) &&
((v->place->type == LINENUM) || (v->place->type == NEWPAGE) ||
(v->place->type == LEFT_TEXT) || (v->place->type == CENTRE_TEXT) ||
(v->place->type == VSKIP))) {
if (v->place->type == LINENUM) {
lineno = (int)(v->place->item);
};
if (v->place->type == LEFT_TEXT) {
*height = *height + textfont.pointsize + textfont.space;
};
if (v->place->type == CENTRE_TEXT) {
*height = *height + textfont.pointsize + textfont.space;
};
if (v->place->type == VSKIP) {
*height = *height + (double)((int)v->place->item);
};
v->place = v->place->next;
};
if (v->place == NULL) {
return(0);
};
/* skip over rest of line */
while ((v->place != NULL) && (v->place->type != PRINTLINE)) {
v->place = v->place->next;
};
if (v->place != NULL) {
spacing = v->place->item;
*height = *height + spacing->height + spacing->descender;
v->place = v->place->next;
};
return(1);
}
static double tuneheight(t)
struct tune* t;
/* measures the vertical space needed by the tune */
{
char* atitle;
char* wordline;
struct voice* thisvoice;
int doneline;
double height;
height = 0.0;
resettune(t);
atitle = firstitem(&t->title);
while (atitle != NULL) {
height = height + titlefont.pointsize + titlefont.space;
atitle = nextitem(&t->title);
};
if ((titleleft == 1) && (t->tempo != NULL)) {
height = height + titlefont.pointsize + 2*titlefont.space;
};
if (t->composer != NULL) {
height = height + composerfont.pointsize + composerfont.space;
};
if (t->origin != NULL) {
height = height + composerfont.pointsize + composerfont.space;
};
if (t->parts != NULL) {
height = height + composerfont.pointsize + composerfont.space;
};
thisvoice = firstitem(&t->voices);
if (separate_voices) {
thisvoice = firstitem(&t->voices);
while (thisvoice != NULL) {
doneline = 1;
while (doneline==1) {
doneline = getlineheight(thisvoice, &height);
};
thisvoice = nextitem(&t->voices);
if (thisvoice != NULL) {
height = height + 2.0 * staffsep;
};
};
} else {
doneline = 1;
while(doneline) {
thisvoice = firstitem(&t->voices);
doneline = 0;
while (thisvoice != NULL) {
doneline = (getlineheight(thisvoice, &height) || doneline);
thisvoice = nextitem(&t->voices);
};
};
};
wordline = firstitem(&t->words);
while (wordline != NULL) {
height = height + wordsfont.pointsize + wordsfont.space;
wordline = nextitem(&t->words);
};
return(height);
}
void printtune(struct tune* t)
/* draws the PostScript for an entire abc tune */
{
int i;
char* atitle;
char* wordline;
int notesdone;
int titleno;
struct voice* thisvoice;
int doneline;
double firstvline, lastvline;
struct voice* firstvoice;
char xtitle[200];
struct bbox boundingbox;
enum placetype titleplace;
resettune(t);
sizetune(t);
resettune(t);
if (separate_voices) {
monospace(t);
} else {
spacevoices(t);
};
resettune(t);
finalsizetune(t);
if (debugging) {
showtune(t);
};
if (eps_out) {
if (landscape) {
boundingbox.llx = ymargin;
boundingbox.lly = xmargin;
boundingbox.urx = ymargin + tuneheight(t) * scale;
boundingbox.ury = xmargin + pagewidth;
} else {
boundingbox.llx = xmargin;
boundingbox.lly = ymargin + pagelen - tuneheight(t) * scale;
boundingbox.urx = xmargin + pagewidth;
boundingbox.ury = ymargin + pagelen;
};
sprintf(outputname, "%s%d.eps", outputroot, t->no);
open_output_file(outputname, &boundingbox);
} else {
make_open();
if ((totlen > 0.0) &&
(totlen+descend+tuneheight(t) > scaledlen-(double)(pagenumbering))) {
newpage();
};
};
resettune(t);
notesdone = 0;
if (titleleft) {
titleplace = left;
} else {
titleplace = centre;
};
atitle = firstitem(&t->title);
titleno = 1;
while (atitle != NULL) {
if (titleno == 1) {
if (titlecaps) {
for (i=0; i<strlen(atitle); i++) {
if (islower(atitle[i])) {
atitle[i] = atitle[i] + 'A' - 'a';
};
};
};
if ((print_xref) && (strlen(atitle) < 180)) {
sprintf(xtitle, "%d. %s", t->no, atitle);
printtext(titleplace, xtitle, &titlefont);
} else {
printtext(titleplace, atitle, &titlefont);
};
} else {
printtext(titleplace, atitle, &subtitlefont);
};
titleno = titleno + 1;
atitle = nextitem(&t->title);
};
if (t->tempo != NULL) {
if (titleleft) {
newblock((double)(titlefont.pointsize + titlefont.space*2), 0.0);
};
draw_tempo(10.0, 0.0, t->tempo);
};
if (t->composer != NULL) {
printtext(right, t->composer, &composerfont);
};
if (t->origin != NULL) {
printtext(right, t->origin, &composerfont);
};
if (t->parts != NULL) {
printtext(right, t->parts, &composerfont);
};
donemeter = 0;
/* musicsetup(); */
thisvoice = firstitem(&t->voices);
while (thisvoice != NULL) {
thisvoice->clef->type = t->clef.type;
thisvoice->clef->octave = t->clef.octave;
setfract(&thisvoice->meter, t->meter.num, t->meter.denom);
thisvoice->place = thisvoice->first;
thisvoice = nextitem(&t->voices);
};
if (separate_voices) {
thisvoice = firstitem(&t->voices);
while (thisvoice != NULL) {
doneline = 1;
while (doneline==1) {
doneline = printvoiceline(thisvoice);
};
thisvoice = nextitem(&t->voices);
if (thisvoice != NULL) {
voicedivider();
};
};
} else {
doneline = 1;
while(doneline) {
thisvoice = firstitem(&t->voices);
firstvoice = thisvoice;
doneline = 0;
while (thisvoice != NULL) {
doneline = (printvoiceline(thisvoice) || doneline);
if (thisvoice == firstvoice) {
firstvline = totlen;
} else {
lastvline = totlen;
if (lastvline > firstvline) {
fprintf(f, "0 24 M 0 %.1f L\n",
lastvline - firstvline);
};
firstvline = totlen;
};
thisvoice = nextitem(&t->voices);
};
};
};
/* musicrestore(); */
wordline = firstitem(&t->words);
while (wordline != NULL) {
printtext(left, wordline, &wordsfont);
wordline = nextitem(&t->words);
};
if (eps_out) {
close_output_file();
};
}
|