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
|
/*
* Python binding for the ALSA library - sequencer
* Copyright (c) 2008 by Aldrin Martoq <amartoq@dcc.uchile.cl>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include "common.h"
#include <alsa/asoundlib.h>
#include <stdio.h>
/*
*
*/
#if 0
#define ddebug(x, args...) fprintf(stderr, x "\n",##args);
#else
#define ddebug(x, args...)
#endif
/* frees only if pointer is not NULL. */
#define FREECHECKED(name, pointer) \
if (pointer != NULL) { \
free(pointer); \
pointer = NULL; \
}
/* raises SequencerError with the specified string */
#define RAISESTR(str, args...) \
PyErr_Format(SequencerError, str,##args);
/* raises SequencerError with the specified string and appends
the alsaaudio error as string */
#define RAISESND(ret, str, args...) \
PyErr_Format(SequencerError, str ": %s",##args, snd_strerror(ret));
/* the C variable of a constant dict */
#define TDICT(subtype) _dictPYALSASEQ_CONST_##subtype
/* defines constant dict by type */
#define TCONSTDICT(subtype) \
static PyObject * TDICT(subtype);
/* adds constant dict to module */
#define TCONSTDICTADD(module, subtype, name) \
_dictPYALSASEQ_CONST_##subtype = PyDict_New(); \
if (TDICT(subtype) == NULL) { \
return MOD_ERROR_VAL; \
} \
if (PyModule_AddObject(module, name, TDICT(subtype)) < 0) { \
return MOD_ERROR_VAL; \
}
/* creates a typed constant and add it to the module and dictionary */
#define TCONSTADD(module, subtype, name) { \
PyObject *tmp = \
Constant_create(#name, SND_##name); \
if (tmp == NULL) { \
return MOD_ERROR_VAL; \
} \
if (PyModule_AddObject(module, #name, tmp) < 0) { \
return MOD_ERROR_VAL; \
} \
PyObject *key = PyInt_FromLong(SND_##name); \
PyDict_SetItem(TDICT(subtype), key, tmp); \
Py_DECREF(key); \
}
#define TCONSTRETURN(subtype, value) { \
PyObject *key = PyInt_FromLong(value); \
ConstantObject *constantObject = (ConstantObject *) \
PyDict_GetItem(TDICT(subtype), key); \
if (constantObject == NULL) { \
return key; \
} else { \
Py_DECREF(key); \
Py_INCREF(constantObject); \
return (PyObject *)constantObject; \
} \
}
#define TCONSTASSIGN(subtype, value, param) { \
PyObject *key = PyInt_FromLong(value); \
ConstantObject *constantObject = (ConstantObject *) \
PyDict_GetItem(TDICT(subtype), key); \
if (constantObject == NULL) { \
param = key; \
} else { \
Py_DECREF(key); \
Py_INCREF(constantObject); \
param = (PyObject *)constantObject; \
} \
}
/* sets the object into the dict */
#define SETDICTOBJ(name, object) \
PyDict_SetItemString(dict, name, object)
/* sets a integer into the dict */
#define SETDICTINT(name, value) { \
PyObject *val = PyInt_FromLong(value); \
PyDict_SetItemString(dict, name, val); \
Py_DECREF(val); \
}
/* sets note info dict (used by SeqEvent_get_data) */
#define SETDICT_NOTE3 { \
snd_seq_ev_note_t *data = &(event->data.note); \
SETDICTINT("note.channel", data->channel); \
SETDICTINT("note.note", data->note); \
SETDICTINT("note.velocity", data->velocity); \
}
/* sets note info dict (used by SeqEvent_get_data) */
#define SETDICT_NOTE5 { \
snd_seq_ev_note_t *data = &(event->data.note); \
SETDICTINT("note.channel", data->channel); \
SETDICTINT("note.note", data->note); \
SETDICTINT("note.velocity", data->velocity); \
SETDICTINT("note.off_velocity", data->off_velocity); \
SETDICTINT("note.duration", data->duration); \
}
/* sets control info dict (used by SeqEvent_get_data) */
#define SETDICT_CTRL1 { \
snd_seq_ev_ctrl_t *data = &(event->data.control); \
SETDICTINT("control.value", data->value); \
}
/* sets control info dict (used by SeqEvent_get_data) */
#define SETDICT_CTRL2 { \
snd_seq_ev_ctrl_t *data = &(event->data.control); \
SETDICTINT("control.channel", data->channel); \
SETDICTINT("control.value", data->value); \
}
/* sets control info dict (used by SeqEvent_get_data) */
#define SETDICT_CTRL3 { \
snd_seq_ev_ctrl_t *data = &(event->data.control); \
SETDICTINT("control.channel", data->channel); \
SETDICTINT("control.param", data->param); \
SETDICTINT("control.value", data->value); \
}
/* sets queue info dict (used by SeqEvent_get_data) */
#define SETDICT_QUEU1 { \
snd_seq_ev_queue_control_t *data = &(event->data.queue); \
SETDICTINT("queue.queue", data->queue); \
}
/* sets addr info dict (used by SeqEvent_get_data) */
#define SETDICT_ADDR1 { \
snd_seq_addr_t *data = &(event->data.addr); \
SETDICTINT("addr.client", data->client); \
}
/* sets addr info dict (used by SeqEvent_get_data) */
#define SETDICT_ADDR2 { \
snd_seq_addr_t *data = &(event->data.addr); \
SETDICTINT("addr.client", data->client); \
SETDICTINT("addr.port", data->port); \
}
/* sets connect info dict (used by SeqEvent_get_data) */
#define SETDICT_CONN4 { \
snd_seq_connect_t *data = &(event->data.connect); \
SETDICTINT("connect.sender.client", data->sender.client); \
SETDICTINT("connect.sender.port", data->sender.port); \
SETDICTINT("connect.dest.client", data->dest.client); \
SETDICTINT("connect.dest.port", data->dest.port); \
}
/* sets result info dict (used by SeqEvent_get_data) */
#define SETDICT_RESU2 { \
snd_seq_result_t *data = &(event->data.result); \
SETDICTINT("result.event", data->event); \
SETDICTINT("result.result", data->result); \
}
/* sets ext info dict (used by SeqEvent_get_data) */
#define SETDICT_EXT { \
snd_seq_ev_ext_t *data = &(event->data.ext); \
PyObject *list = PyList_New(data->len); \
unsigned i = 0; \
unsigned char *t = (unsigned char *) data->ptr; \
for (i = 0; i < data->len; i++) { \
PyList_SetItem(list, i, PyInt_FromLong(t[i])); \
} \
SETDICTOBJ("ext", list); \
Py_DECREF(list); \
}
/* gets integer from python param */
#define GETDICTINT(name, param) { \
PyObject *value = PyDict_GetItemString(dict, name); \
if (value != NULL) { \
long val; \
if (get_long(value, &val)) \
return NULL; \
param = val; \
} \
}
/* gets float from python param */
#define GETDICTFLOAT(name, param1, param2) { \
PyObject *value = PyDict_GetItemString(dict, name); \
if (value != NULL) { \
if (PyInt_Check(value)) { \
param2 = 0; \
param1 = PyInt_AsLong(value); \
} else if (PyFloat_Check(value)) { \
double d = PyFloat_AsDouble(value); \
unsigned int i = d; \
d -= i; \
param2 = d * 1000000; \
param1 = i; \
} else { \
PyErr_SetString(PyExc_TypeError, \
name " must be a integer or float"); \
return NULL; \
} \
} \
}
/* gets ext data from python list */
#define GETDICTEXT(name) { \
PyObject *list = PyDict_GetItemString(dict, name); \
if (list != NULL) { \
if (!PyList_Check(list)) { \
PyErr_SetString(PyExc_TypeError, \
name " must be a list of integers"); \
return NULL; \
} \
FREECHECKED("buff", self->buff); \
int len = PyList_Size(list); \
self->event->data.ext.len = len; \
if (len > 0) { \
self->buff = malloc(len); \
if (self->buff == NULL) { \
PyErr_SetString(PyExc_TypeError, \
name " no memory"); \
self->event->data.ext.len = 0; \
return NULL; \
} \
int i; \
long val; \
for (i = 0; i < len; i++) { \
PyObject *item = PyList_GetItem(list, i); \
if (get_long1(item, &val)) { \
PyErr_SetString(PyExc_TypeError, \
name " must be a list of integers"); \
self->event->data.ext.len = 0; \
free(self->buff); \
self->buff = NULL; \
return NULL; \
} \
self->buff[i] = val; \
} \
self->event->data.ext.ptr = self->buff; \
} \
} \
}
//////////////////////////////////////////////////////////////////////////////
// alsaseq.Constant implementation
//////////////////////////////////////////////////////////////////////////////
// constants dictionaries
TCONSTDICT(STREAMS);
TCONSTDICT(MODE);
TCONSTDICT(QUEUE);
TCONSTDICT(CLIENT_TYPE);
TCONSTDICT(PORT_CAP);
TCONSTDICT(PORT_TYPE);
TCONSTDICT(EVENT_TYPE);
TCONSTDICT(EVENT_TIMESTAMP);
TCONSTDICT(EVENT_TIMEMODE);
TCONSTDICT(ADDR_CLIENT);
TCONSTDICT(ADDR_PORT);
/** alsaseq.Constant __doc__ */
PyDoc_STRVAR(Constant__doc__,
"Constant() -> Constant object\n"
"\n"
"Represents one of the many integer constants from the\n"
"libasound sequencer API.\n"
"\n"
"This class serves the following purposes:\n"
" a. wrap the SND_SEQ* constants to a python int;\n"
" b. provide a string representation of the constant;\n"
"\n"
"For a), this class is a subclass of the python int. Example:\n"
" >>> import alsaseq\n"
" >>> print alsaseq.SEQ_EVENT_NOTE\n"
" 5\n"
" >>> event = alsaseq.SeqEvent(alsaseq.SEQ_EVENT_NOTE)\n"
" >>> print event.queue\n"
" 253\n"
" >>> print event.dest\n"
" (0, 0)\n"
"\n"
"For b), you can get the name of the constant by calling the appropriate\n"
"method (__str__ or __repr__). Example:\n"
" >>> print str(event.queue), repr(event.queue)\n"
" SEQ_QUEUE_DIRECT SEQ_QUEUE_DIRECT(0xfd)\n"
" >>> print str(event.dest)\n"
" (SEQ_CLIENT_SYSTEM(0x0), SEQ_PORT_SYSTEM_TIMER(0x0))\n"
"\n"
"This class implements some of the bitwise operations from the\n"
"Python number protocol."
);
/** alsaseq.Constant additional fields */
/* This follows the variable length portion of the Long type */
typedef struct {
/* name of constant */
const char *name;
} ConstantExtraFields;
/** alsaseq.Constant object structure type */
typedef struct {
#if PY_MAJOR_VERSION < 3
PyIntObject base;
#else
/* NOTE: this only works if the value fits in one digit */
PyLongObject base;
#endif
/* This field is actually offset by the base type's variable size portion */
ConstantExtraFields extra;
} ConstantObject;
#if PY_MAJOR_VERSION < 3
# define CONST_VALUE(x) PyInt_AsLong((PyObject *)x)
#else
# define CONST_VALUE(x) PyLong_AsLong((PyObject *)x)
#endif
# define CONST_EXTRA(x) (&(x->extra))
/** alsaseq.Constant type (initialized later...) */
static PyTypeObject ConstantType;
/** alsaseq.Constant internal create */
static PyObject *
Constant_create(const char *name, long value) {
#if PY_MAJOR_VERSION < 3
PyObject *val = PyInt_FromLong(value);
#else
PyObject *val = PyLong_FromLong(value);
#endif
PyObject *args = PyTuple_Pack(1, val);
Py_DECREF(val);
#if PY_MAJOR_VERSION < 3
ConstantObject *self = (ConstantObject *)PyInt_Type.tp_new(&ConstantType, args, NULL);
#else
ConstantObject *self = (ConstantObject *)PyLong_Type.tp_new(&ConstantType, args, NULL);
#endif
Py_DECREF(args);
if (self == NULL) {
return NULL;
}
CONST_EXTRA(self)->name = name;
return (PyObject *)self;
}
/** alsaseq.Constant tp_repr */
static PyObject *
Constant_repr(ConstantObject *self) {
return PyUnicode_FromFormat("%s(0x%x)",
CONST_EXTRA(self)->name,
(unsigned int)CONST_VALUE(self));
}
/** alsaseq.Constant tp_str */
static PyObject *
Constant_str(ConstantObject *self) {
return PyUnicode_FromFormat("%s",
CONST_EXTRA(self)->name);
}
/** alsaseq.Constant type */
static PyTypeObject ConstantType = {
PyVarObject_HEAD_INIT(NULL, 0)
tp_name: "alsaseq.Constant",
#if PY_MAJOR_VERSION < 3
tp_base: &PyInt_Type,
#else
tp_base: &PyLong_Type,
#endif
tp_basicsize: sizeof(ConstantObject) + sizeof(ConstantExtraFields),
tp_flags:
#if PY_MAJOR_VERSION < 3
Py_TPFLAGS_HAVE_GETCHARBUFFER
| Py_TPFLAGS_HAVE_CLASS
| Py_TPFLAGS_CHECKTYPES,
#else
0,
#endif
tp_doc: Constant__doc__,
tp_free: PyObject_Del,
tp_str: (reprfunc)Constant_str,
tp_repr: (reprfunc)Constant_repr
};
//////////////////////////////////////////////////////////////////////////////
// alsaseq.SequencerError implementation
//////////////////////////////////////////////////////////////////////////////
/** alsaseq.SequencerError instance (initialized in initalsaseq) */
static PyObject *SequencerError;
//////////////////////////////////////////////////////////////////////////////
// alsaseq.SeqEvent implementation
//////////////////////////////////////////////////////////////////////////////
/** alsaseq.SeqEvent __doc__ */
PyDoc_STRVAR(SeqEvent__doc__,
"SeqEvent(type[, timestamp[,timemode]]) -> SeqEvent object\n"
"\n"
"Creates an Alsa Sequencer Event object. The type must be one of the\n"
"alsaseq.SEQ_EVENT_* constants. The timestamp specifies if tick (midi)\n"
"or real time is used, must be alsaseq.SEQ_TIME_STAMP_TICK or\n"
"alsaseq.SEQ_TIME_STAMP_REAL. The timemode specifies if the time will\n"
"be absolute or relative, must be alsaseq.SEQ_TIME_MODE_ABS or\n"
"alsaseq.SEQ_TIME_MODE_REL.\n"
"\n"
"The timestamp and timemode defaults to SEQ_TIME_STAMP_TICK and\n"
"SEQ_TIME_MODE_ABS when they are not specified.\n"
"\n"
"SeqEvent objects are received or sent using a Sequencer object. The\n"
"data of the event can be set or retrieved using the set_data() or\n"
"get_data() methods; both use a dictionary. The rest of properties of\n"
"a SeqEvent can be accesed and changed using the SeqEvent attributes.\n"
"\n"
"The attributes and defaults values are:\n"
"type -- event type.\n"
"timestamp -- tick(midi) or real(nanoseconds). Default: SEQ_TIME_STAMP_TICK.\n"
"timemode -- relative or absolute. Default: SEQ_TIME_MODE_ABS.\n"
"queue -- queue id. Default: SEQ_QUEUE_DIRECT\n"
"time -- time of this event. Default: 0.\n"
"source -- source address tuple (client,port). Default: (0, 0).\n"
"dest -- dest address tuple (client, port). Default: (0, 0).\n"
"\n"
"There are dictionaries available as attributes, that contains\n"
"alsaseq.SEQ* constants that can be used for each attribute:\n"
"_dtype -- event type constants.\n"
"_dtimestamp -- event timestamp constants.\n"
"_dtimemode -- event timemode constants.\n"
"_dqueue -- queue id's.\n"
"_dclient -- client address (for source an dest).\n"
"_dport -- port address (for source an dest).\n"
);
/** alsaseq.SeqEvent object structure type */
typedef struct {
PyObject_HEAD
;
/* alsa event */
snd_seq_event_t *event;
/* pointer copied/created from/for variable length events */
unsigned char *buff;
} SeqEventObject;
/** alsaseq.SeqEvent type (initialized later...) */
static PyTypeObject SeqEventType;
/** internal use: set type and update flags based on event type */
static int
_SeqEvent_set_type(SeqEventObject *self,
long type) {
self->event->type = type;
/* clean previous buff... */
FREECHECKED("buff", self->buff);
memset(&(self->event->data), '\0', sizeof(self->event->data));
/* update flags */
if (snd_seq_ev_is_variable_type(self->event)) {
snd_seq_ev_set_variable(self->event, 0, NULL);
} else if (snd_seq_ev_is_varusr_type(self->event)) {
snd_seq_ev_set_varusr(self->event, 0, NULL);
} else if (snd_seq_ev_is_fixed_type(self->event)) {
snd_seq_ev_set_fixed(self->event);
} else {
PyErr_SetString(PyExc_ValueError,
"Invalid value for type; "
"use one of alsaseq.SEQ_EVENT_* constants.");
return -1;
}
return 0;
}
/** internal use: set timestamp flag */
static int
_SeqEvent_set_timestamp(SeqEventObject *self,
long timestamp) {
if (timestamp == SND_SEQ_TIME_STAMP_TICK) {
self->event->flags &= ~(SND_SEQ_TIME_STAMP_MASK);
self->event->flags |= SND_SEQ_TIME_STAMP_TICK;
} else if (timestamp == SND_SEQ_TIME_STAMP_REAL) {
self->event->flags &= ~(SND_SEQ_TIME_STAMP_MASK);
self->event->flags |= SND_SEQ_TIME_STAMP_REAL;
} else {
PyErr_SetString(PyExc_ValueError,
"Invalid value for timestamp; "
"use alsaseq.SEQ_TIME_STAMP_TICK or "
"alsaseq.SEQ_TIME_STAMP_REAL.");
return -1;
}
return 0;
}
/** internal use: set timemode flag */
static int
_SeqEvent_set_timemode(SeqEventObject *self,
long timemode) {
if (timemode == SND_SEQ_TIME_MODE_ABS) {
self->event->flags &= ~(SND_SEQ_TIME_MODE_MASK);
self->event->flags |= SND_SEQ_TIME_MODE_ABS;
} else if (timemode == SND_SEQ_TIME_MODE_REL) {
self->event->flags &= ~(SND_SEQ_TIME_MODE_MASK);
self->event->flags |= SND_SEQ_TIME_MODE_REL;
} else {
PyErr_SetString(PyExc_ValueError,
"Invalid value for timemode; "
"use alsaseq.SEQ_TIME_MODE_ABS or "
"alsaseq.SEQ_TIME_MODE_REL.");
return -1;
}
return 0;
}
/** alsaseq.SeqEvent tp_init */
static int
SeqEvent_init(SeqEventObject *self,
PyObject *args,
PyObject *kwds) {
int type = 0;
int timestamp = SND_SEQ_TIME_STAMP_TICK;
int timemode = SND_SEQ_TIME_MODE_ABS;
char *kwlist [] = {"type", "timestamp", "timemode", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "i|ii", kwlist, &type,
×tamp, &timemode)) {
return -1;
}
if (_SeqEvent_set_type(self, type) !=0 ) {
return -1;
}
if (_SeqEvent_set_timestamp(self, timestamp) != 0) {
return -1;
}
if (_SeqEvent_set_timemode(self, timemode) != 0) {
return -1;
}
snd_seq_ev_set_direct(self->event);
snd_seq_ev_set_subs(self->event);
return 0;
}
/** internal use: create a alsaseq.SeqEvent from a snd_seq_event_t structure */
static PyObject *
SeqEvent_create(snd_seq_event_t *event) {
SeqEventObject *self = PyObject_New(SeqEventObject, &SeqEventType);
if (self == NULL) {
return NULL;
}
self->event = malloc(sizeof(snd_seq_event_t));
if (self->event == NULL) {
PyObject_Del(self);
return PyErr_NoMemory();
}
memcpy(self->event, event, sizeof(snd_seq_event_t));
if (snd_seq_ev_is_variable_type(self->event)) {
self->buff = malloc(self->event->data.ext.len);
if (self->buff == NULL) {
PyObject_Del(self);
return PyErr_NoMemory();
}
memcpy(self->buff, self->event->data.ext.ptr, self->event->data.ext.len);
self->event->data.ext.ptr = self->buff;
} else {
self->buff = NULL;
}
return (PyObject *) self;
}
/** alsaseq.SeqEvent tp_new */
static PyObject *
SeqEvent_new(PyTypeObject *type,
PyObject *args,
PyObject *kwds) {
SeqEventObject *self;
self = (SeqEventObject *)type->tp_alloc(type, 0);
self->event = malloc(sizeof(snd_seq_event_t));
if (self->event == NULL) {
type->tp_free(self);
return PyErr_NoMemory();
}
snd_seq_ev_clear(self->event);
self->buff = NULL;
return (PyObject *) self;
}
/** alsaseq.SeqEvent tp_dealloc */
static void
SeqEvent_dealloc(SeqEventObject *self) {
FREECHECKED("event", self->event);
FREECHECKED("buff", self->buff);
Py_TYPE(self)->tp_free((PyObject*)self);
}
/** alsaseq.SeqEvent type attribute: __doc__ */
PyDoc_STRVAR(SeqEvent_type__doc__,
"type -> Constant object\n"
"\n"
"The type of this alsaseq.SeqEvent; Use one of the\n"
"alsaseq.SEQ_EVENT_* constants.\n\n"
"Note: changing a SeqEvent type will *ERASE* AND *CLEAN* its data!!"
);
/** alsaseq.SeqEvent type attribute: tp_getset getter() */
static PyObject *
SeqEvent_get_type(SeqEventObject *self) {
TCONSTRETURN(EVENT_TYPE, self->event->type);
}
/** alsaseq.SeqEvent type attribute: tp_getset setter() */
static int
SeqEvent_set_type(SeqEventObject *self,
PyObject *val) {
long v;
if (get_long(val, &v))
return -1;
return _SeqEvent_set_type(self, v);
}
/** alsaseq.SeqEvent tag attribute: __doc__ */
PyDoc_STRVAR(SeqEvent_tag__doc__,
"tag -> int\n"
"\n"
"The tag of this alsaseq.SeqEvent (range:0-255)."
);
/** alsaseq.SeqEvent tag attribute: tp_getset getter() */
static PyObject *
SeqEvent_get_tag(SeqEventObject *self) {
return PyInt_FromLong(self->event->tag);
}
/** alsaseq.SeqEvent tag attribute: tp_getset setter() */
static int
SeqEvent_set_tag(SeqEventObject *self,
PyObject *val) {
long tag;
if (get_long(val, &tag))
return -1;
if (tag < 0 || tag > 255) {
PyErr_Format(PyExc_ValueError,
"invalid value '%ld'; allowed range: 0 - 255",
tag);
return -1;
}
self->event->tag = tag;
return 0;
}
/** alsaseq.seqEvent timestamp attribute: __doc__ */
PyDoc_STRVAR(SeqEvent_timestamp__doc__,
"timestamp -> Constant object\n"
"\n"
"The time stamp flag of this alsaseq.SeqEvent;\n"
"use alsaseq.SEQ_TIME_STAMP_TICK or alsaseq.SEQ_TIME_STAMP_REAL."
);
/** alsaseq.SeqEvent timestamp attribute: tp_getset getter() */
static PyObject *
SeqEvent_get_timestamp(SeqEventObject *self) {
if (snd_seq_ev_is_tick(self->event)) {
TCONSTRETURN(EVENT_TIMESTAMP, SND_SEQ_TIME_STAMP_TICK);
} else if (snd_seq_ev_is_real(self->event)) {
TCONSTRETURN(EVENT_TIMESTAMP, SND_SEQ_TIME_STAMP_REAL);
}
/* should never get here ... */
return NULL;
}
/** alsaseq.SeqEvent timestamp attribute: tp_getset setter() */
static int
SeqEvent_set_timestamp(SeqEventObject *self,
PyObject *val) {
long v;
if (get_long(val, &v))
return -1;
return _SeqEvent_set_timestamp(self, v);
}
/** alsaseq.SeqEvent timemode attribute: __doc__ */
PyDoc_STRVAR(SeqEvent_timemode__doc__,
"timemode -> Constant object\n"
"\n"
"The time mode flag of this alsaseq.SeqEvent;\n"
"use alsaseq.SEQ_TIME_MODE_ABS or alsaseq.SEQ_TIME_MODE_REL."
);
/** alsaseq.SeqEvent timemode attribute: tp_getset getter() */
static PyObject *
SeqEvent_get_timemode(SeqEventObject *self) {
if (snd_seq_ev_is_abstime(self->event)) {
TCONSTRETURN(EVENT_TIMEMODE, SND_SEQ_TIME_MODE_ABS);
} else if (snd_seq_ev_is_reltime(self->event)) {
TCONSTRETURN(EVENT_TIMEMODE, SND_SEQ_TIME_MODE_REL);
}
/* should never get here ... */
return NULL;
}
/** alsaseq.SeqEvent timemode attribute: tp_getset setter() */
static int
SeqEvent_set_timemode(SeqEventObject *self,
PyObject *val) {
long v;
if (get_long(val, &v))
return -1;
return _SeqEvent_set_timemode(self, v);
}
/** alsaseq.SeqEvent queue attribute: __doc__ */
PyDoc_STRVAR(SeqEvent_queue__doc__,
"queue -> int\n"
"\n"
"The send queue id of this alsaseq.SeqEvent."
);
/** alsaseq.SeqEvent queue: tp_getset getter() */
static PyObject *
SeqEvent_get_queue(SeqEventObject *self) {
TCONSTRETURN(QUEUE, self->event->queue);
}
/** alsaseq.SeqEvent queue attribute: tp_getset setter() */
static int
SeqEvent_set_queue(SeqEventObject *self,
PyObject *val) {
long v;
if (get_long(val, &v))
return -1;
self->event->queue = v;
return 0;
}
/** alsaseq.SeqEvent time attribute: __doc__ */
PyDoc_STRVAR(SeqEvent_time__doc__,
"time -> int or float\n"
"\n"
"The send time of this alsaseq.SeqEvent.\n"
"If the timestamp of the SeqEvent is SEQ_TIME_STAMP_TICK, an\n"
"integer value is used which represents the midi tick time; \n"
"if the timestamp is SEQ_TIME_STAMP_REAL, a float value is used\n"
"which represents seconds the same way Python time module.\n"
);
/** alsaseq.SeqEvent time attribute: tp_getset getter() */
static PyObject *
SeqEvent_get_time(SeqEventObject *self) {
if (snd_seq_ev_is_real(self->event)) {
double time = self->event->time.time.tv_sec;
time += self->event->time.time.tv_nsec / 1000000000.0;
return PyFloat_FromDouble(time);
} else if (snd_seq_ev_is_tick(self->event)) {
long tick = self->event->time.tick;
return PyInt_FromLong(tick);
}
/* should never get here... */
return NULL;
}
/** alsaseq.SeqEvent time attribute: tp_getset setter() */
static int
SeqEvent_set_time(SeqEventObject *self,
PyObject *val) {
long lval = 0;
const int is_float = PyFloat_Check(val);
const int is_int = is_float ? 0 : get_long1(val, &lval);
if (!(is_int || is_float)) {
PyErr_Format(PyExc_TypeError,
"integer or float expected");
return -1;
}
if (snd_seq_ev_is_real(self->event)) {
if (is_int) {
double time = lval;
self->event->time.time.tv_sec = time;
self->event->time.time.tv_nsec = 0;
} else {
double time = PyFloat_AsDouble(val);
self->event->time.time.tv_sec = (unsigned int)time;
time -= self->event->time.time.tv_sec;
self->event->time.time.tv_nsec = time * 1000000000;
}
} else if (snd_seq_ev_is_tick(self->event)) {
if (is_int) {
self->event->time.tick = lval;
} else {
self->event->time.tick = PyFloat_AsDouble(val);
}
} else {
/* should never get here... */
return -1;
}
return 0;
}
/** alsaseq.SeqEvent source attribute: __doc __ */
PyDoc_STRVAR(SeqEvent_source__doc__,
"source -> tuple (client_id, port_id)\n"
"\n"
"Tuple representing the send source address of this alsaseq.SeqEvent.\n"
"The tuple is (client_id, port_id). If the client or port id are known,\n"
"the appropriate constant may be used, otherwise integers are expected."
);
/** alsaseq.SeqEvent source attribute: tp_getset getter() */
static PyObject *
SeqEvent_get_source(SeqEventObject *self) {
int source_client = self->event->source.client;
int source_port = self->event->source.port;
PyObject *client, *port;
PyObject *tuple = PyTuple_New(2);
TCONSTASSIGN(ADDR_CLIENT, source_client, client);
TCONSTASSIGN(ADDR_PORT, source_port, port);
PyTuple_SetItem(tuple, 0, client);
PyTuple_SetItem(tuple, 1, port);
return tuple;
}
/** alsaseq.SeqEvent source attribute: tp_getset setter() */
static int
SeqEvent_set_source(SeqEventObject *self,
PyObject *val) {
long client;
long port;
if (!PyTuple_Check(val) || PyTuple_Size(val) != 2) {
PyErr_SetString(PyExc_TypeError, "expected tuple (client,port)");
return -1;
}
if (get_long(PyTuple_GetItem(val, 0), &client))
return -1;
if (get_long(PyTuple_GetItem(val, 1), &port))
return -1;
self->event->source.client = client;
self->event->source.port = port;
return 0;
}
/** alsaseq.SeqEvent dest attribute: __doc __ */
PyDoc_STRVAR(SeqEvent_dest__doc__,
"dest -> tuple (client_id, port_id)\n"
"\n"
"Tuple representing the destination address of this alsaseq.SeqEvent.\n"
"The tuple is (client_id, port_id). If the client or port id are known,\n"
"the appropriate constant may be used, otherwise integers are expected."
);
/** alsaseq.SeqEvent dest attribute: tp_getset getter() */
static PyObject *
SeqEvent_get_dest(SeqEventObject *self) {
int dest_client = self->event->dest.client;
int dest_port = self->event->dest.port;
PyObject *client, *port;
PyObject *tuple = PyTuple_New(2);
TCONSTASSIGN(ADDR_CLIENT, dest_client, client);
TCONSTASSIGN(ADDR_PORT, dest_port, port);
PyTuple_SetItem(tuple, 0, client);
PyTuple_SetItem(tuple, 1, port);
return tuple;
}
/** alsaseq.SeqEvent dest attribute: tp_getset setter() */
static int
SeqEvent_set_dest(SeqEventObject *self,
PyObject *val) {
long client;
long port;
if (!PyTuple_Check(val) || PyTuple_Size(val) != 2) {
PyErr_SetString(PyExc_TypeError, "expected tuple (client,port)");
return -1;
}
if (get_long(PyTuple_GetItem(val, 0), &client))
return -1;;
if (get_long(PyTuple_GetItem(val, 1), &port))
return -1;
self->event->dest.client = client;
self->event->dest.port = port;
return 0;
}
/** alsaseq.SeqEvent is_result_type attribute: __doc__ */
PyDoc_STRVAR(SeqEvent_is_result_type__doc__,
"is_result_type -> boolean\n"
"\n"
"Indicates if this alsaseq.SeqEvent is of type result (True) or not\n"
"(False). Note: read-only attribute."
);
/** alsaseq.SeqEvent is_result_type attribute: tp_getset getter() */
static PyObject *
SeqEvent_is_result_type(SeqEventObject *self) {
if (snd_seq_ev_is_result_type(self->event)) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
}
/** alsaseq.SeqEvent is_note_type attribute: __doc__ */
PyDoc_STRVAR(SeqEvent_is_note_type__doc__,
"is_note_type -> boolean\n"
"\n"
"Indicates if this alsaseq.SeqEvent is of type note (True) or not\n"
"(False). Note: read-only attribute."
);
/** alsaseq.SeqEvent is_note_type attribute: tp_getset getter() */
static PyObject *
SeqEvent_is_note_type(SeqEventObject *self) {
if (snd_seq_ev_is_note_type(self->event)) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
}
/** alsaseq.SeqEvent is_control_type attribute: __doc__ */
PyDoc_STRVAR(SeqEvent_is_control_type__doc__,
"is_control_type -> boolean\n"
"\n"
"Indicates if this alsaseq.SeqEvent is of type control (True) or not\n"
"(False). Note: read-only attribute."
);
/** alsaseq.SeqEvent is_note_type attribute: tp_getset getter() */
static PyObject *
SeqEvent_is_control_type(SeqEventObject *self) {
if (snd_seq_ev_is_control_type(self->event)) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
}
/** alsaseq.SeqEvent is_channel_type attribute: __doc__ */
PyDoc_STRVAR(SeqEvent_is_channel_type__doc__,
"is_channel_type -> boolean\n"
"\n"
"Indicates if this alsaseq.SeqEvent is of type channel (True) or not\n"
"(False). Note: read-only attribute."
);
/** alsaseq.SeqEvent is_channel_type attribute: tp_getset getter() */
static PyObject *
SeqEvent_is_channel_type(SeqEventObject *self) {
if (snd_seq_ev_is_channel_type(self->event)) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
}
/** alsaseq.SeqEvent is_queue_type attribute: __doc__ */
PyDoc_STRVAR(SeqEvent_is_queue_type__doc__,
"is_queue_type -> boolean\n"
"\n"
"Indicates if this alsaseq.SeqEvent is a queue event (True) or not\n"
"(False). Note: read-only attribute."
);
/** alsaseq.SeqEvent is_queue_type attribute: tp_getset getter() */
static PyObject *
SeqEvent_is_queue_type(SeqEventObject *self) {
if (snd_seq_ev_is_queue_type(self->event)) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
}
/** alsaseq.SeqEvent is_message_type attribute: __doc__ */
PyDoc_STRVAR(SeqEvent_is_message_type__doc__,
"is_message_type -> boolean\n"
"\n"
"Indicates if this alsaseq.SeqEvent is of type message (True) or not\n"
"(False). Note: read-only attribute."
);
/** alsaseq.SeqEvent is_message_type attribute: tp_getset getter() */
static PyObject *
SeqEvent_is_message_type(SeqEventObject *self) {
if (snd_seq_ev_is_message_type(self->event)) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
}
/** alsaseq.SeqEvent is_subscribe_type attribute: __doc__ */
PyDoc_STRVAR(SeqEvent_is_subscribe_type__doc__,
"is_subscribe_type -> boolean\n"
"\n"
"Indicates if this alsaseq.SeqEvent is of type subscribe (True) or not\n"
"(False). Note: read-only attribute."
);
/** alsaseq.SeqEvent is_subscribe_type attribute: tp_getset getter() */
static PyObject *
SeqEvent_is_subscribe_type(SeqEventObject *self) {
if (snd_seq_ev_is_subscribe_type(self->event)) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
}
/** alsaseq.SeqEvent is_sample_type attribute: __doc__ */
PyDoc_STRVAR(SeqEvent_is_sample_type__doc__,
"is_sample_type -> boolean\n"
"\n"
"Indicates if this alsaseq.SeqEvent is of type sample (True) or not\n"
"(False). Note: read-only attribute."
);
/** alsaseq.SeqEvent is_sample_type attribute: tp_getset getter() */
static PyObject *
SeqEvent_is_sample_type(SeqEventObject *self) {
if (snd_seq_ev_is_sample_type(self->event)) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
}
/** alsaseq.SeqEvent is_user_type attribute: __doc__ */
PyDoc_STRVAR(SeqEvent_is_user_type__doc__,
"is_user_type -> boolean\n"
"\n"
"Indicates if this alsaseq.SeqEvent is of type user (True) or not\n"
"(False). Note: read-only attribute."
);
/** alsaseq.SeqEvent is_user_type attribute: tp_getset getter() */
static PyObject *
SeqEvent_is_user_type(SeqEventObject *self) {
if (snd_seq_ev_is_user_type(self->event)) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
}
/** alsaseq.SeqEvent is_instr_type attribute: __doc__ */
PyDoc_STRVAR(SeqEvent_is_instr_type__doc__,
"is_instr_type -> boolean\n"
"\n"
"Indicates if this alsaseq.SeqEvent is of type instr (True) or not\n"
"(False). Note: read-only attribute."
);
/** alsaseq.SeqEvent is_instr_type attribute: tp_getset getter() */
static PyObject *
SeqEvent_is_instr_type(SeqEventObject *self) {
if (snd_seq_ev_is_instr_type(self->event)) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
}
/** alsaseq.SeqEvent is_fixed_type attribute: __doc__ */
PyDoc_STRVAR(SeqEvent_is_fixed_type__doc__,
"is_fixed_type -> boolean\n"
"\n"
"Indicates if this alsaseq.SeqEvent is of type fixed (True) or not\n"
"(False). Note: read-only attribute."
);
/** alsaseq.SeqEvent is_fixed_type attribute: tp_getset getter() */
static PyObject *
SeqEvent_is_fixed_type(SeqEventObject *self) {
if (snd_seq_ev_is_fixed_type(self->event)) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
}
/** alsaseq.SeqEvent is_variable_type attribute: __doc__ */
PyDoc_STRVAR(SeqEvent_is_variable_type__doc__,
"is_variable_type -> boolean\n"
"\n"
"Indicates if this alsaseq.SeqEvent is of type variable (True) or not\n"
"(False). Note: read-only attribute."
);
/** alsaseq.SeqEvent is_variable_type attribute: tp_getset getter() */
static PyObject *
SeqEvent_is_variable_type(SeqEventObject *self) {
if (snd_seq_ev_is_variable_type(self->event)) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
}
/** alsaseq.SeqEvent is_varusr_type attribute: __doc__ */
PyDoc_STRVAR(SeqEvent_is_varusr_type__doc__,
"is_message_type -> boolean\n"
"\n"
"Indicates if this alsaseq.SeqEvent is of type varusr (True) or not\n"
"(False). Note: read-only attribute."
);
/** alsaseq.SeqEvent is_varusr_type attribute: tp_getset getter() */
static PyObject *
SeqEvent_is_varusr_type(SeqEventObject *self) {
if (snd_seq_ev_is_varusr_type(self->event)) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
}
/** alsaseq.SeqEvent is_reserved attribute: __doc__ */
PyDoc_STRVAR(SeqEvent_is_reserved__doc__,
"is_reserved -> boolean\n"
"\n"
"Indicates if this alsaseq.SeqEvent is reserved (True) or not (False).\n"
"Note: read-only attribute."
);
/** alsaseq.SeqEvent is_reserved attribute: tp_getset getter() */
static PyObject *
SeqEvent_is_reserved(SeqEventObject *self) {
if (snd_seq_ev_is_reserved(self->event)) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
}
/** alsaseq.SeqEvent is_prior attribute: __doc__ */
PyDoc_STRVAR(SeqEvent_is_prior__doc__,
"is_prior -> boolean\n"
"\n"
"Indicates if this alsaseq.SeqEvent is prior (True) or not (False).\n"
"Note: read-only attribute."
);
/** alsaseq.SeqEvent is_prior attribute: tp_getset getter() */
static PyObject *
SeqEvent_is_prior(SeqEventObject *self) {
if (snd_seq_ev_is_prior(self->event)) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
}
/** alsaseq.SeqEvent is_fixed attribute: __doc__ */
PyDoc_STRVAR(SeqEvent_is_fixed__doc__,
"is_fixed -> boolean\n"
"\n"
"Indicates if this alsaseq.SeqEvent is fixed (True) or not (False).\n"
"Note: read-only attribute."
);
/** alsaseq.SeqEvent is_fixed attribute: tp_getset getter() */
static PyObject *
SeqEvent_is_fixed(SeqEventObject *self) {
if (snd_seq_ev_is_fixed(self->event)) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
}
/** alsaseq.SeqEvent is_variable attribute: __doc__ */
PyDoc_STRVAR(SeqEvent_is_variable__doc__,
"is_variable -> boolean\n"
"\n"
"Indicates if this alsaseq.SeqEvent is variable (True) or not (False).\n"
"Note: read-only attribute."
);
/** alsaseq.SeqEvent is_variable attribute: tp_getset getter() */
static PyObject *
SeqEvent_is_variable(SeqEventObject *self) {
if (snd_seq_ev_is_variable(self->event)) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
}
/** alsaseq.SeqEvent is_varusr attribute: __doc__ */
PyDoc_STRVAR(SeqEvent_is_varusr__doc__,
"is_varusr -> boolean\n"
"\n"
"Indicates if this alsaseq.SeqEvent is varusr (True) or not (False).\n"
"Note: read-only attribute."
);
/** alsaseq.SeqEvent is_varusr attribute: tp_getset getter() */
static PyObject *
SeqEvent_is_varusr(SeqEventObject *self) {
if (snd_seq_ev_is_varusr(self->event)) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
}
/** alsaseq.SeqEvent is_tick attribute: __doc__ */
PyDoc_STRVAR(SeqEvent_is_tick__doc__,
"is_tick -> boolean\n"
"\n"
"Indicates if this alsaseq.SeqEvent is tick timed (True) or not (False).\n"
"Note: read-only attribute."
);
/** alsaseq.SeqEvent is_tick attribute: tp_getset getter() */
static PyObject *
SeqEvent_is_tick(SeqEventObject *self) {
if (snd_seq_ev_is_tick(self->event)) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
}
/** alsaseq.SeqEvent is_real attribute: __doc__ */
PyDoc_STRVAR(SeqEvent_is_real__doc__,
"is_real -> boolean\n"
"\n"
"Indicates if this alsaseq.SeqEvent is real timed (True) or not (False).\n"
"Note: read-only attribute."
);
/** alsaseq.SeqEvent is_real attribute: tp_getset getter() */
static PyObject *
SeqEvent_is_real(SeqEventObject *self) {
if (snd_seq_ev_is_real(self->event)) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
}
/** alsaseq.SeqEvent is_abstime attribute: __doc__ */
const char SeqEvent_is_abstime__doc__ [] =
"is_abstime -> boolean\n"
"\n"
"Indicates if this alsaseq.SeqEvent is abstime timed (True) or not\n"
"(False). Note: read-only attribute."
;
/** alsaseq.SeqEvent is_abstime attribute: tp_getset getter() */
static PyObject *
SeqEvent_is_abstime(SeqEventObject *self) {
if (snd_seq_ev_is_abstime(self->event)) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
}
/** alsaseq.SeqEvent is_reltime attribute: __doc__ */
const char SeqEvent_is_reltime__doc__ [] =
"is_reltime -> boolean\n"
"\n"
"Indicates if this alsaseq.SeqEvent is a reltime timed (True) or not\n"
"(False). Note: read-only attribute."
;
/** alsaseq.SeqEvent is_reltime attribute: tp_getset getter() */
static PyObject *
SeqEvent_is_reltime(SeqEventObject *self) {
if (snd_seq_ev_is_reltime(self->event)) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
}
/** alsaseq.SeqEvent is_direct attribute: __doc__ */
const char SeqEvent_is_direct__doc__ [] =
"is_direct -> boolean\n"
"\n"
"Indicates if this alsaseq.SeqEvent is sent directly (True) or not\n"
"(False). Note: read-only attribute."
;
/** alsaseq.SeqEvent is_direct attribute: tp_getset getter() */
static PyObject *
SeqEvent_is_direct(SeqEventObject *self) {
if (snd_seq_ev_is_direct(self->event)) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
}
/** alsaseq.SeqEvent _dtype attribute: __doc__ */
const char SeqEvent__dtype__doc__ [] =
"_dtype -> dictionary\n"
"\n"
"Dictionary will available event type constants."
;
/** alsaseq.Seqevent _dtype attribute: tp_getset getter() */
static PyObject *
SeqEvent__dtype(SeqEventObject *self) {
Py_INCREF(_dictPYALSASEQ_CONST_EVENT_TYPE);
return _dictPYALSASEQ_CONST_EVENT_TYPE;
}
/** alsaseq.SeqEvent _dtimestamp attribute: __doc__ */
const char SeqEvent__dtimestamp__doc__ [] =
"_dtimestamp -> dictionary\n"
"\n"
"Dictionary will available event timestamp constants."
;
/** alsaseq.Seqevent _dtimestamp attribute: tp_getset getter() */
static PyObject *
SeqEvent__dtimestamp(SeqEventObject *self) {
Py_INCREF(_dictPYALSASEQ_CONST_EVENT_TIMESTAMP);
return _dictPYALSASEQ_CONST_EVENT_TIMESTAMP;
}
/** alsaseq.SeqEvent _dtimemode attribute: __doc__ */
const char SeqEvent__dtimemode__doc__ [] =
"_dtimemode -> dictionary\n"
"\n"
"Dictionary of available event timemode constants."
;
/** alsaseq.Seqevent _dtimemode attribute: tp_getset getter() */
static PyObject *
SeqEvent__dtimemode(SeqEventObject *self) {
Py_INCREF(_dictPYALSASEQ_CONST_EVENT_TIMEMODE);
return _dictPYALSASEQ_CONST_EVENT_TIMEMODE;
}
/** alsaseq.SeqEvent _dqueue attribute: __doc__ */
const char SeqEvent__dqueue__doc__ [] =
"_dqueue -> dictionary\n"
"\n"
"Dictionary of known queue id constants."
;
/** alsaseq.Seqevent _dqueue attribute: tp_getset getter() */
static PyObject *
SeqEvent__dqueue(SeqEventObject *self) {
Py_INCREF(_dictPYALSASEQ_CONST_QUEUE);
return _dictPYALSASEQ_CONST_QUEUE;
}
/** alsaseq.SeqEvent _dclient attribute: __doc__ */
const char SeqEvent__dclient__doc__ [] =
"_dclient -> dictionary\n"
"\n"
"Dictionary of known client addresses constants."
;
/** alsaseq.Seqevent _dclient attribute: tp_getset getter() */
static PyObject *
SeqEvent__dclient(SeqEventObject *self) {
Py_INCREF(TDICT(ADDR_CLIENT));
return TDICT(ADDR_CLIENT);
}
/** alsaseq.SeqEvent _dport attribute: __doc__ */
const char SeqEvent__dport__doc__ [] =
"_dport -> dictionary\n"
"\n"
"Dictionary of known port addresses constants."
;
/** alsaseq.Seqevent _dport attribute: tp_getset getter() */
static PyObject *
SeqEvent__dport(SeqEventObject *self) {
Py_INCREF(TDICT(ADDR_PORT));
return TDICT(ADDR_PORT);
}
/** alsaseq.SeqEvent tp_getset list */
static PyGetSetDef SeqEvent_getset[] = {
{"type",
(getter) SeqEvent_get_type,
(setter) SeqEvent_set_type,
(char *) SeqEvent_type__doc__,
NULL},
{"timestamp",
(getter) SeqEvent_get_timestamp,
(setter) SeqEvent_set_timestamp,
(char *) SeqEvent_timestamp__doc__,
NULL},
{"timemode",
(getter) SeqEvent_get_timemode,
(setter) SeqEvent_set_timemode,
(char *) SeqEvent_timemode__doc__,
NULL},
{"tag",
(getter) SeqEvent_get_tag,
(setter) SeqEvent_set_tag,
(char *) SeqEvent_tag__doc__,
NULL},
{"queue",
(getter) SeqEvent_get_queue,
(setter) SeqEvent_set_queue,
(char *) SeqEvent_queue__doc__,
NULL},
{"time",
(getter) SeqEvent_get_time,
(setter) SeqEvent_set_time,
(char *) SeqEvent_time__doc__,
NULL},
{"source",
(getter) SeqEvent_get_source,
(setter) SeqEvent_set_source,
(char *) SeqEvent_source__doc__,
NULL},
{"dest",
(getter) SeqEvent_get_dest,
(setter) SeqEvent_set_dest,
(char *) SeqEvent_dest__doc__,
NULL},
{"is_result_type",
(getter) SeqEvent_is_result_type,
NULL,
(char *) SeqEvent_is_result_type__doc__,
NULL},
{"is_note_type",
(getter) SeqEvent_is_note_type,
NULL,
(char *) SeqEvent_is_note_type__doc__,
NULL},
{"is_control_type",
(getter) SeqEvent_is_control_type,
NULL,
(char *) SeqEvent_is_control_type__doc__,
NULL},
{"is_channel_type",
(getter) SeqEvent_is_channel_type,
NULL,
(char *) SeqEvent_is_channel_type__doc__,
NULL},
{"is_queue_type",
(getter) SeqEvent_is_queue_type,
NULL,
(char *) SeqEvent_is_queue_type__doc__,
NULL},
{"is_message_type",
(getter) SeqEvent_is_message_type,
NULL,
(char *) SeqEvent_is_message_type__doc__,
NULL},
{"is_subscribe_type",
(getter) SeqEvent_is_subscribe_type,
NULL,
(char *) SeqEvent_is_subscribe_type__doc__,
NULL},
{"is_sample_type",
(getter) SeqEvent_is_sample_type,
NULL,
(char *) SeqEvent_is_sample_type__doc__,
NULL},
{"is_user_type",
(getter) SeqEvent_is_user_type,
NULL,
(char *) SeqEvent_is_user_type__doc__,
NULL},
{"is_instr_type",
(getter) SeqEvent_is_instr_type,
NULL,
(char *) SeqEvent_is_instr_type__doc__,
NULL},
{"is_fixed_type",
(getter) SeqEvent_is_fixed_type,
NULL,
(char *) SeqEvent_is_fixed_type__doc__,
NULL},
{"is_variable_type",
(getter) SeqEvent_is_variable_type,
NULL,
(char *) SeqEvent_is_variable_type__doc__,
NULL},
{"is_varusr_type",
(getter) SeqEvent_is_varusr_type,
NULL,
(char *) SeqEvent_is_varusr_type__doc__,
NULL},
{"is_reserved",
(getter) SeqEvent_is_reserved,
NULL,
(char *) SeqEvent_is_reserved__doc__,
NULL},
{"is_prior",
(getter) SeqEvent_is_prior,
NULL,
(char *) SeqEvent_is_prior__doc__,
NULL},
{"is_fixed",
(getter) SeqEvent_is_fixed,
NULL,
(char *) SeqEvent_is_fixed__doc__,
NULL},
{"is_variable",
(getter) SeqEvent_is_variable,
NULL,
(char *) SeqEvent_is_variable__doc__,
NULL},
{"is_varusr",
(getter) SeqEvent_is_varusr,
NULL,
(char *) SeqEvent_is_varusr__doc__,
NULL},
{"is_tick",
(getter) SeqEvent_is_tick,
NULL,
(char *) SeqEvent_is_tick__doc__,
NULL},
{"is_real",
(getter) SeqEvent_is_real,
NULL,
(char *) SeqEvent_is_real__doc__,
NULL},
{"is_abstime",
(getter) SeqEvent_is_abstime,
NULL,
(char *) SeqEvent_is_abstime__doc__,
NULL},
{"is_reltime",
(getter) SeqEvent_is_reltime,
NULL,
(char *) SeqEvent_is_reltime__doc__,
NULL},
{"is_direct",
(getter) SeqEvent_is_direct,
NULL,
(char *) SeqEvent_is_direct__doc__,
NULL},
{"_dtype",
(getter) SeqEvent__dtype,
NULL,
(char *) SeqEvent__dtype__doc__,
NULL},
{"_dtimestamp",
(getter) SeqEvent__dtimestamp,
NULL,
(char *) SeqEvent__dtimestamp__doc__,
NULL},
{"_dtimemode",
(getter) SeqEvent__dtimemode,
NULL,
(char *) SeqEvent__dtimemode__doc__,
NULL},
{"_dqueue",
(getter) SeqEvent__dqueue,
NULL,
(char *) SeqEvent__dqueue__doc__,
NULL},
{"_dclient",
(getter) SeqEvent__dclient,
NULL,
(char *) SeqEvent__dclient__doc__,
NULL},
{"_dport",
(getter) SeqEvent__dport,
NULL,
(char *) SeqEvent__dport__doc__,
NULL},
{NULL}
};
/** alsaseq.SeqEvent tp_repr */
static PyObject *
SeqEvent_repr(SeqEventObject *self) {
PyObject *key = PyInt_FromLong(self->event->type);
ConstantObject *typeObject = (ConstantObject *)PyDict_GetItem(TDICT(EVENT_TYPE), key);
const char *timemode = "";
unsigned int dtime = 0;
unsigned int ntime = 0;
Py_DECREF(key);
if (snd_seq_ev_is_real(self->event)) {
timemode = "real";
dtime = self->event->time.time.tv_sec;
ntime += self->event->time.time.tv_nsec / 1000000000.0;
} else {
timemode = "tick";
dtime = self->event->time.tick;
}
return PyUnicode_FromFormat("<alsaseq.SeqEvent type=%S(%d) flags=%d tag=%d "
"queue=%d time=%s(%u.%u) from=%d:%d to=%d:%d "
"at %p>",
typeObject,
self->event->type, self->event->flags,
self->event->tag, self->event->queue,
timemode, dtime, ntime,
(self->event->source).client,
(self->event->source).port,
(self->event->dest).client,
(self->event->dest).port,
self);
}
/** alsaseq.SeqEvent get_data() method: __doc__ */
PyDoc_STRVAR(SeqEvent_get_data__doc__,
"get_data() -> dict\n"
"\n"
"Returns a new dictionary with the data of this SeqEvent.\n"
"Changes to the returned dictionary will not change this SeqEvent data,\n"
"for changing an event data use the set_data() method.\n"
"\n"
"The dictionary items are key: value; where key is the name of the\n"
"data structure from alsa API and value is an integer or a list of them.\n"
"\n"
"The following name of structures are available:\n"
" 'note.channel' -> int\n"
" 'note.note' -> int\n"
" 'note.velocity' -> int\n"
" 'note.off_velocity' -> int\n"
" 'note.duration' -> int\n"
" 'control.channel' -> int\n"
" 'control.value' -> int\n"
" 'control.param' -> int\n"
" 'queue.queue' -> int\n"
" 'addr.client' -> int\n"
" 'addr.port' -> int\n"
" 'connect.sender.client' -> int\n"
" 'connect.sender.port' -> int\n"
" 'connect.dest.client' -> int\n"
" 'connect.dest.port' -> int\n"
" 'result.event' -> int\n"
" 'result.result' -> int\n"
" 'ext' -> list of int with sysex or variable data\n"
"\n"
"The exact items returned dependens on the event type of this SeqEvent.\n"
"For a control event, only 'control.*' may be returned; for a sysex \n"
"event, only 'ext' may be returned; for a note event, only 'note.*' may \n"
"be returned and so on."
);
/** alsaseq.SeqEvent get_data() method */
static PyObject *
SeqEvent_get_data(SeqEventObject *self,
PyObject *args) {
PyObject *dict = PyDict_New();
snd_seq_event_t *event = self->event;
switch (event->type) {
case SND_SEQ_EVENT_SYSTEM:
case SND_SEQ_EVENT_RESULT:
SETDICT_RESU2;
break;
case SND_SEQ_EVENT_NOTE:
SETDICT_NOTE5;
break;
case SND_SEQ_EVENT_NOTEON:
case SND_SEQ_EVENT_NOTEOFF:
case SND_SEQ_EVENT_KEYPRESS:
SETDICT_NOTE3;
break;
case SND_SEQ_EVENT_CONTROLLER:
SETDICT_CTRL3;
break;
case SND_SEQ_EVENT_PGMCHANGE:
case SND_SEQ_EVENT_CHANPRESS:
case SND_SEQ_EVENT_PITCHBEND:
SETDICT_CTRL2;
break;
case SND_SEQ_EVENT_CONTROL14:
case SND_SEQ_EVENT_NONREGPARAM:
case SND_SEQ_EVENT_REGPARAM:
SETDICT_CTRL3;
break;
case SND_SEQ_EVENT_SONGPOS:
case SND_SEQ_EVENT_SONGSEL:
case SND_SEQ_EVENT_QFRAME:
case SND_SEQ_EVENT_TIMESIGN:
case SND_SEQ_EVENT_KEYSIGN:
SETDICT_CTRL1;
break;
case SND_SEQ_EVENT_START:
case SND_SEQ_EVENT_CONTINUE:
case SND_SEQ_EVENT_STOP:
case SND_SEQ_EVENT_SETPOS_TICK:
case SND_SEQ_EVENT_TEMPO:
SETDICT_QUEU1;
break;
case SND_SEQ_EVENT_CLOCK:
case SND_SEQ_EVENT_TICK:
break;
case SND_SEQ_EVENT_QUEUE_SKEW:
SETDICT_QUEU1;
break;
case SND_SEQ_EVENT_TUNE_REQUEST:
case SND_SEQ_EVENT_RESET:
case SND_SEQ_EVENT_SENSING:
break;
case SND_SEQ_EVENT_CLIENT_START:
case SND_SEQ_EVENT_CLIENT_EXIT:
case SND_SEQ_EVENT_CLIENT_CHANGE:
SETDICT_ADDR1;
break;
case SND_SEQ_EVENT_PORT_START:
case SND_SEQ_EVENT_PORT_EXIT:
case SND_SEQ_EVENT_PORT_CHANGE:
SETDICT_ADDR2;
break;
case SND_SEQ_EVENT_PORT_SUBSCRIBED:
case SND_SEQ_EVENT_PORT_UNSUBSCRIBED:
SETDICT_CONN4;
break;
case SND_SEQ_EVENT_SYSEX:
SETDICT_EXT;
break;
}
return dict;
}
/** alsaseq.SeqEvent set_data() method: __doc__ */
PyDoc_STRVAR(SeqEvent_set_data__doc__,
"set_data(dict)"
"\n"
"Changes the data of this SeqEvent, updating internal data structure \n"
"from the given dictionary.\n"
"\n"
"The dictionary items should be the same as described in the get_data() \n"
"method and be the appropriate for this SeqEvent type.\n"
"\n"
"This method does not check if a given structure correspond to is valid \n"
"for this SeqEvent type; so setting the 'control.param' or the 'ext' \n"
"structures for a NOTE SeqEvent may change another data structure \n"
"or will simple have no effect once sent."
);
/** alsaseq.SeqEvent set_data() method */
static PyObject *
SeqEvent_set_data(SeqEventObject *self,
PyObject *args) {
PyObject *dict = NULL;
snd_seq_event_t *event = self->event;
if (!PyArg_ParseTuple(args, "O",
&dict)) {
return NULL;
}
if (!PyDict_Check(dict)) {
PyErr_SetString(PyExc_TypeError, "must be a dictionary");
return NULL;
}
GETDICTINT("note.channel", event->data.note.channel);
GETDICTINT("note.note", event->data.note.note);
GETDICTINT("note.velocity", event->data.note.velocity);
GETDICTINT("note.off_velocity", event->data.note.off_velocity);
GETDICTINT("note.duration", event->data.note.duration);
GETDICTINT("control.channel", event->data.control.channel);
GETDICTINT("control.param", event->data.control.param);
GETDICTINT("control.value", event->data.control.value);
GETDICTEXT("ext");
GETDICTINT("queue.queue", event->data.queue.queue);
GETDICTINT("queue.param.value", event->data.queue.param.value);
GETDICTINT("addr.client", event->data.addr.client);
GETDICTINT("addr.port", event->data.addr.port);
GETDICTINT("connect.sender.client", event->data.connect.sender.client);
GETDICTINT("connect.sender.port", event->data.connect.sender.port);
GETDICTINT("connect.dest.client", event->data.connect.dest.client);
GETDICTINT("connect.dest.port", event->data.connect.dest.port);
GETDICTINT("result.event", event->data.result.event);
GETDICTINT("result.result", event->data.result.result);
Py_RETURN_NONE;
}
/** alsaseq.SeqEvent tp_methods */
static PyMethodDef SeqEvent_methods[] = {
{"get_data",
(PyCFunction) SeqEvent_get_data,
METH_VARARGS,
SeqEvent_get_data__doc__},
{"set_data",
(PyCFunction) SeqEvent_set_data,
METH_VARARGS,
SeqEvent_set_data__doc__},
{NULL}
};
/** alsaseq.SeEvent type */
static PyTypeObject SeqEventType = {
PyVarObject_HEAD_INIT(NULL, 0)
tp_name: "alsaseq.SeqEvent",
tp_basicsize: sizeof(SeqEventObject),
tp_dealloc: (destructor) SeqEvent_dealloc,
tp_flags: Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
tp_doc: SeqEvent__doc__,
tp_init: (initproc)SeqEvent_init,
tp_new : SeqEvent_new,
tp_alloc: PyType_GenericAlloc,
tp_free: PyObject_Del,
tp_methods: SeqEvent_methods,
tp_getset: SeqEvent_getset,
tp_repr: (reprfunc)SeqEvent_repr,
};
//////////////////////////////////////////////////////////////////////////////
// alsaseq.Sequencer implementation
//////////////////////////////////////////////////////////////////////////////
/** alsaseq.Sequencer __doc__ */
PyDoc_STRVAR(Sequencer__doc__,
"Sequencer([name, clientname, streams, mode, maxreceiveevents]) "
"-> Sequencer object\n"
"\n"
"Creates and opens an ALSA sequencer. The features of the Sequencer are:\n"
"- send/receive events (as SeqEvent objects)\n"
"- create ports\n"
"- list all ALSA clients and their port connections\n"
"- connect/disconnect arbitrary ports\n"
"- create and control queues\n"
"- get info about a port or a client\n"
"\n"
"The name must correspond to the special ALSA name (for example: 'hw'); \n"
"if not specified, 'default' is used. The clientname is the name of this \n"
"client; if not specified, 'pyalsa-PID' is used.\n"
"\n"
"The streams specifies if you want to receive, send or both; use \n"
"SEQ_OPEN_INPUT, SEQ_OPEN_OUTPUT or SEQ_OPEN_DUPLEX. If not specified, \n"
"SEQ_OPEN_DUPLEX is used."
"\n"
"The mode specifies if this client should block or not, use SEQ_BLOCK or \n"
"SEQ_NONBLOCK. If not specified, SEQ_NONBLOCK is used."
"\n"
"The maxreceiveevents is a number that represents how many SeqEvent \n"
"objects are returned by the receive() method. If not specified, the \n"
"default is 4. \n"
"\n"
"There is no method for closing the sequencer, it will remain open as \n"
"long as the Sequencer object exists. For closing the sequencer you \n"
"must explicitly del() the returned object."
);
/** alsaseq.Sequencer object structure type */
typedef struct {
PyObject_HEAD
/* streams */
int streams;
/* mode */
int mode;
/* alsa handler */
snd_seq_t *handle;
/* max fd's */
int receive_max;
/* receive poll fd's */
struct pollfd *receive_fds;
/* max events for returning in receive_events() */
int receive_max_events;
/* remaining bytes from input */
int receive_bytes;
} SequencerObject;
/** alsaseq.Sequencer type (initialized later...) */
static PyTypeObject SequencerType;
/** alsaseq.Sequencer: tp_init */
static int
Sequencer_init(SequencerObject *self,
PyObject *args, PyObject *kwds) {
int ret;
/* defaults */
char *name = "default";
char *clientname = NULL;
char tmpclientname[1024];
self->streams = SND_SEQ_OPEN_DUPLEX;
self->mode = SND_SEQ_NONBLOCK;
int maxreceiveevents = 4;
char *kwlist[] = { "name", "clientname", "streams", "mode",
"maxreceiveevents", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|ssiii", kwlist, &name,
&clientname, &self->streams,
&self->mode, &maxreceiveevents)) {
return -1;
}
if (clientname == NULL) {
tmpclientname[0] = 0;
sprintf(tmpclientname, "pyalsa-%d", getpid());
clientname = tmpclientname;
}
self->receive_fds = NULL;
self->receive_max = 0;
self->receive_bytes = 0;
self->receive_max_events = maxreceiveevents;
ret = snd_seq_open(&(self->handle), name, self->streams,
self->mode);
if (ret < 0) {
RAISESND(ret, "Failed to create sequencer");
return -1;
}
ret = snd_seq_set_client_name(self->handle, clientname);
if (ret < 0) {
RAISESND(ret, "Failed to set client name");
return -1;
}
return 0;
}
/** alsaseq.Sequencer: tp_dealloc */
static void
Sequencer_dealloc(SequencerObject *self) {
FREECHECKED("receive_fds", self->receive_fds);
if (self->handle) {
snd_seq_close(self->handle);
self->handle = NULL;
}
Py_TYPE(self)->tp_free((PyObject*)self);
}
/** alsaseq.Sequencer name attribute: __doc__ */
PyDoc_STRVAR(Sequencer_name__doc__,
"name -> string\n"
"\n"
"The alsa device name of this alsaseq.Sequencer.\n"
"Note: read-only attribute."
);
/** alsaseq.Sequencer name attribute: tp_getset getter() */
static PyObject *
Sequencer_get_name(SequencerObject *self) {
return PyUnicode_FromString(snd_seq_name(self->handle));
}
/** alsaseq.Sequencer clientname attribute: __doc__ */
PyDoc_STRVAR(Sequencer_clientname__doc__,
"clientname -> string\n"
"\n"
"The client name of this alsaseq.Sequencer\n"
);
/** alsaseq.Sequencer clientname attribute: tp_getset getter() */
static PyObject *
Sequencer_get_clientname(SequencerObject *self) {
snd_seq_client_info_t *cinfo;
snd_seq_client_info_alloca(&cinfo);
snd_seq_get_client_info(self->handle, cinfo);
return PyUnicode_FromString(snd_seq_client_info_get_name(cinfo));
}
/** alsaseq.Sequencer clientname attribute: tp_getset setter() */
static int
Sequencer_set_clientname(SequencerObject *self,
PyObject *val) {
char *s;
if (get_utf8_string(val, &s))
return -1;
snd_seq_set_client_name(self->handle, s);
free(s);
return 0;
}
/** alsaseq.Sequencer streams attribute: __doc__ */
PyDoc_STRVAR(Sequencer_streams__doc__,
"streams -> Constant object\n"
"\n"
"The streams of this alsaseq.Sequencer. Possible values:\n"
"alsaseq.SEQ_OPEN_OUTPUT, alsaseq.SEQ_OPEN_INPUT, \n"
"alsaseq.SEQ_OPEN_DUPLEX.\n"
"Note: read-only attribute."
);
/** alsaseq.Sequencer streams attribute: tp_getset getter() */
static PyObject *
Sequencer_get_streams(SequencerObject *self) {
TCONSTRETURN(STREAMS, self->streams);
}
/** alsaseq.Sequencer mode attribute: __doc__ */
PyDoc_STRVAR(Sequencer_mode__doc__,
"mode -> Constant object\n"
"\n"
"The blocking mode of this alsaseq.Sequencer. Use\n"
"alsaseq.SEQ_BLOCK, alsaseq.SEQ_NONBLOCK."
);
/** alsaseq.Sequencer mode attribute: tp_getset getter() */
static PyObject *Sequencer_get_mode(SequencerObject *self) {
TCONSTRETURN(MODE, self->mode);
}
/** alsaseq.Sequencer mode attribute: tp_getset setter() */
static int
Sequencer_set_mode(SequencerObject *self,
PyObject *val) {
int ret;
long mode;
if (get_long(val, &mode))
return -1;
if (mode != 0 && mode != SND_SEQ_NONBLOCK) {
PyErr_SetString(PyExc_ValueError, "Invalid value for mode.");
return -1;
}
ret = snd_seq_nonblock(self->handle, mode);
if (ret == 0) {
self->mode = mode;
} else {
RAISESND(ret, "Failed to set mode");
return -1;
}
return 0;
}
/** alsaseq.Sequencer client_id attribute: __doc__ */
PyDoc_STRVAR(Sequencer_client_id__doc__,
"client_id -> int\n"
"\n"
"The client id of this alsaseq.Sequencer.\n"
"Note: read-only attribute."
);
/** alsaseq.Sequencer client_id attribute: tp_getset getter() */
static PyObject *
Sequencer_get_client_id(SequencerObject *self) {
snd_seq_client_info_t *cinfo;
snd_seq_client_info_alloca(&cinfo);
snd_seq_get_client_info(self->handle, cinfo);
return PyInt_FromLong(snd_seq_client_info_get_client(cinfo));
}
/** alsaseq.Sequencer: tp_getset list*/
static PyGetSetDef Sequencer_getset[] = {
{"name",
(getter) Sequencer_get_name,
NULL,
(char *) Sequencer_name__doc__,
NULL},
{"clientname",
(getter) Sequencer_get_clientname,
(setter) Sequencer_set_clientname,
(char *) Sequencer_clientname__doc__,
NULL},
{"streams",
(getter) Sequencer_get_streams,
NULL,
(char *) Sequencer_streams__doc__,
NULL},
{"mode",
(getter) Sequencer_get_mode,
(setter) Sequencer_set_mode,
(char *) Sequencer_mode__doc__,
NULL},
{"client_id",
(getter) Sequencer_get_client_id,
NULL,
(char *) Sequencer_client_id__doc__,
NULL},
{NULL}
};
/** alsaseq.Sequencer: tp_repr */
static PyObject *
Sequencer_repr(SequencerObject *self) {
snd_seq_client_info_t *cinfo;
snd_seq_client_info_alloca(&cinfo);
snd_seq_get_client_info(self->handle, cinfo);
return PyUnicode_FromFormat("<alsaseq.Sequencer name=%s client_id=%d "
"clientname=%s streams=%d mode=%d at 0x%p>",
snd_seq_name(self->handle),
snd_seq_client_info_get_client(cinfo),
snd_seq_client_info_get_name(cinfo),
self->streams,
self->mode,
self
);
}
/** alsaseq.Sequencer create_simple_port() method: __doc__ */
PyDoc_STRVAR(Sequencer_create_simple_port__doc__,
"create_simple_port(name, type, caps=0) -> int"
"\n"
"Creates a port for receiving or sending events.\n"
"\n"
"Parameters:\n"
" name -- name of the port\n"
" type -- type of port (use one of the alsaseq.SEQ_PORT_TYPE_*\n"
" constants)\n"
" caps -- capabilities of the port (use bitwise alsaseq.SEQ_PORT_CAP_*\n"
" constants). Default=0\n"
"Returns:\n"
" the port id.\n"
"Raises:\n"
" TypeError: if an invalid type was used in a parameter\n"
" ValueError: if an invalid value was used in a parameter\n"
" SequencerError: if ALSA can't create the port"
);
/** alsaseq.Sequencer create_simple_port() method */
static PyObject *
Sequencer_create_simple_port(SequencerObject *self,
PyObject *args,
PyObject *kwds) {
char *name;
unsigned int type;
unsigned int caps=0;
char *kwlist[] = { "name", "type", "caps", NULL };
int port;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "sI|I", kwlist,
&name, &type, &caps)) {
return NULL;
}
port = snd_seq_create_simple_port(self->handle, name, caps, type);
if (port < 0) {
RAISESND(port, "Failed to create simple port");
return NULL;
}
return PyInt_FromLong(port);
}
/** alsaseq.Sequencer connection_list() method: __doc__ */
PyDoc_STRVAR(Sequencer_connection_list__doc__,
"connection_list() -> list\n"
"\n"
"List all clients and their ports connections.\n"
"\n"
"Returns:\n"
" (list) a list of tuples: client_name, client_id, port_list:.\n"
" client_name -- the client's name.\n"
" client_id -- the client's id.\n"
" port_list -- a list of tuples: port_name, port_id, connection_list:\n"
" port_name -- the name of the port.\n"
" port_id -- the port id.\n"
" connection_list -- a list of tuples: read_conn, write_conn:\n"
" read_conn -- a list of (client_id, port_id, info) tuples this\n"
" port is connected to (sends events);\n"
" info is the same of the get_connect_info() method.\n"
" write_conn -- a list of (client_id, port_id, info) tuples this\n"
" port is connected from (receives events);\n"
" info is the same of the get_connect_info() method.\n"
);
static PyObject *
_query_connections_list(snd_seq_t *handle,
snd_seq_query_subscribe_t *query,
int type) {
PyObject *list = PyList_New(0);
int index = 0;
snd_seq_query_subscribe_set_type(query, type);
snd_seq_query_subscribe_set_index(query, index);
while (snd_seq_query_port_subscribers(handle, query) >= 0) {
const snd_seq_addr_t *addr =
snd_seq_query_subscribe_get_addr(query);
PyObject *tuple = Py_BuildValue(
"(ii{sisisisi})",
(int)addr->client,
(int)addr->port,
"queue", (int)snd_seq_query_subscribe_get_queue(query),
"exclusive", (int)snd_seq_query_subscribe_get_exclusive(query),
"time_update", (int)snd_seq_query_subscribe_get_time_update(query),
"time_real", (int)snd_seq_query_subscribe_get_time_real(query));
PyList_Append(list, tuple);
Py_DECREF(tuple);
snd_seq_query_subscribe_set_index(query, ++index);
}
return list;
}
static PyObject *
_query_connections(snd_seq_t *handle,
const snd_seq_addr_t *addr) {
snd_seq_query_subscribe_t *query;
snd_seq_query_subscribe_alloca(&query);
snd_seq_query_subscribe_set_root(query, addr);
// create tuple for read,write lists
PyObject *tuple = PyTuple_New(2);
PyObject *readlist = _query_connections_list(handle, query,
SND_SEQ_QUERY_SUBS_READ);
PyObject *writelist = _query_connections_list(handle, query,
SND_SEQ_QUERY_SUBS_WRITE);
PyTuple_SetItem(tuple, 0, readlist);
PyTuple_SetItem(tuple, 1, writelist);
return tuple;
}
/** alsaseq.Sequencer connection_list() method */
static PyObject *
Sequencer_connection_list(SequencerObject *self,
PyObject *args) {
snd_seq_client_info_t *cinfo;
snd_seq_port_info_t *pinfo;
PyObject *client, *port, *name;
PyObject *list = PyList_New(0);
if (list == NULL) {
return NULL;
}
snd_seq_client_info_alloca(&cinfo);
snd_seq_port_info_alloca(&pinfo);
snd_seq_client_info_set_client(cinfo, -1);
while (snd_seq_query_next_client(self->handle, cinfo) >= 0) {
/* reset query info */
snd_seq_port_info_set_client(pinfo,
snd_seq_client_info_get_client(cinfo));
snd_seq_port_info_set_port(pinfo, -1);
/* create tuple for client info */
PyObject *tuple = PyTuple_New(3);
PyObject *portlist = PyList_New(0);
name = PyUnicode_FromFormat("%s", snd_seq_client_info_get_name(cinfo));
client = PyInt_FromLong(snd_seq_client_info_get_client(cinfo));
PyTuple_SetItem(tuple, 0, name);
PyTuple_SetItem(tuple, 1, client);
while (snd_seq_query_next_port(self->handle, pinfo) >= 0) {
/* create tuple for port info */
PyObject *porttuple = PyTuple_New(3);
name = PyUnicode_FromFormat("%s", snd_seq_port_info_get_name(pinfo));
port = PyInt_FromLong(snd_seq_port_info_get_port(pinfo));
PyTuple_SetItem(porttuple, 0, name);
PyTuple_SetItem(porttuple, 1, port);
/* create tuple for read,write connections */
PyObject *conntuple =
_query_connections(self->handle, snd_seq_port_info_get_addr(pinfo));
PyTuple_SetItem(porttuple, 2, conntuple);
PyList_Append(portlist, porttuple);
Py_DECREF(porttuple);
}
PyTuple_SetItem(tuple, 2, portlist);
/* append list of port tuples */
PyList_Append(list, tuple);
Py_DECREF(tuple);
}
return list;
}
/** alsaseq.Sequencer get_client_info() method: __doc__ */
PyDoc_STRVAR(Sequencer_get_client_info__doc__,
"get_client_info(client_id = self.client_id) -> dictionary\n"
"\n"
"Retrieve info about an existing client.\n"
"\n"
"Parameters:\n"
" client_id -- the client id (defaults to: self.client_id)\n"
"Returns:\n"
" (dict) a dictionary with the following values:\n"
" id -- id of client.\n"
" type -- type of client (SEQ_USER_CLIENT or SEQ_KERNEL_CLIENT).\n"
" name -- name of client.\n"
" broadcast_filter -- broadcast filter flag of client as int.\n"
" error_bounce -- error bounce of client as int.\n"
" event_filter -- event filter of client as string.\n"
" num_ports -- number of opened ports of client.\n"
" event_lost -- number of lost events of client.\n"
"Raises:\n"
" SequencerError: ALSA error occurred."
);
/** alsaseq.Sequencer get_client_info() method */
static PyObject *
Sequencer_get_client_info(SequencerObject *self,
PyObject *args,
PyObject *kwds) {
snd_seq_client_info_t *cinfo;
int client_id = -1;
int ret;
char *kwlist[] = { "client_id", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i", kwlist,
&client_id)) {
return NULL;
}
snd_seq_client_info_alloca(&cinfo);
if (client_id == -1) {
ret = snd_seq_get_client_info(self->handle, cinfo);
if (ret < 0) {
RAISESND(ret, "Failed to retrieve client info for self.client_id");
return NULL;
}
client_id = snd_seq_client_info_get_client(cinfo);
} else {
ret = snd_seq_get_any_client_info(self->handle, client_id, cinfo);
if (ret < 0) {
RAISESND(ret, "Failed to retrieve client info for '%d'", client_id);
return NULL;
}
}
PyObject *d_id, *d_type;
TCONSTASSIGN(ADDR_CLIENT, client_id, d_id);
TCONSTASSIGN(CLIENT_TYPE, snd_seq_client_info_get_type(cinfo), d_type);
const char *d_name = snd_seq_client_info_get_name(cinfo);
PyObject *dict = Py_BuildValue(
"{sNsNsssisiss#sisi}",
"id", d_id,
"type", d_type,
"name", d_name == NULL ? "" : d_name,
"broadcast_filter", (int)snd_seq_client_info_get_broadcast_filter(cinfo),
"error_bounce", (int)snd_seq_client_info_get_error_bounce(cinfo),
"event_filter", snd_seq_client_info_get_event_filter(cinfo), 32,
"num_ports", (int)snd_seq_client_info_get_num_ports(cinfo),
"event_lost", (int)snd_seq_client_info_get_event_lost(cinfo));
return dict;
}
/** alsaseq.Sequencer get_port_info() method: __doc__ */
PyDoc_STRVAR(Sequencer_get_port_info__doc__,
"get_port_info(port_id, client_id = self.client_id) -> dictionary\n"
"\n"
"Retrieve info about an existing client's port.\n"
"\n"
"Parameters:\n"
" port_id -- the port id\n"
" client_id -- the client id (defaults to: self.client_id)\n"
"Returns:\n"
" (dict) a dictionary with the following values:\n"
" name -- the port name\n"
" type -- the port type bit flags\n"
" capability -- the port capability bit flags as integer\n"
"Raises:\n"
" SequencerError: ALSA error occurred."
);
/** alsaseq.Sequencer get_port_info() method */
static PyObject *
Sequencer_get_port_info(SequencerObject *self,
PyObject *args,
PyObject *kwds) {
snd_seq_port_info_t *pinfo;
snd_seq_client_info_t *cinfo;
int port_id;
int client_id;
int ret;
char *kwlist[] = { "port_id", "client_id", NULL };
snd_seq_client_info_alloca(&cinfo);
ret = snd_seq_get_client_info(self->handle, cinfo);
if (ret < 0) {
RAISESND(ret, "Failed to determine self.client_id");
return NULL;
}
client_id = snd_seq_client_info_get_client(cinfo);
if (!PyArg_ParseTupleAndKeywords(args, kwds, "i|i", kwlist,
&port_id, &client_id)) {
return NULL;
}
snd_seq_port_info_alloca(&pinfo);
ret = snd_seq_get_any_port_info(self->handle, client_id,
port_id, pinfo);
if (ret < 0) {
RAISESND(ret, "Failed to get port info for %d:%d", client_id, port_id);
return NULL;
}
return Py_BuildValue(
"{sssIsI}",
"name", snd_seq_port_info_get_name(pinfo),
"capability", (unsigned int)snd_seq_port_info_get_capability(pinfo),
"type", (unsigned int)snd_seq_port_info_get_type(pinfo));
}
/** alsaseq.Sequencer connect_ports() method: __doc__ */
PyDoc_STRVAR(Sequencer_connect_ports__doc__,
"connect_ports(srcaddr,dstaddr,queue,exclusive,time_update,time_real)\n"
"\n"
"Connect the ports specified by srcaddr and dstaddr.\n"
"\n"
"Parameters:\n"
" srcaddr -- (tuple) the (client_id, port_id) tuple for the source\n"
" port (the port sending events)\n"
" dstaddr -- (tuple) the (client_id, port_id) tuple for the destination\n"
" port (the port receiveng events)\n"
" queue -- the queue of the connection.\n"
" If not specified, defaults to 0.\n"
" exclusive -- 1 if the connection is exclusive, 0 otherwise.\n"
" If not specified, defaults to 0.\n"
" time_update -- 1 if the connection should update time, 0 otherwise.\n"
" If not specified, defaults to 0.\n"
" time_real -- 1 if the update time is in real, 0 if is in tick.\n"
" If not specified, defaults to 0.\n"
"Raises:\n"
" SequenceError: if ALSA can't connect the ports"
);
/** alsaseq.Sequencer connect_ports() method */
static PyObject *
Sequencer_connect_ports(SequencerObject *self,
PyObject *args) {
snd_seq_addr_t sender, dest;
snd_seq_port_subscribe_t *sinfo;
int ret;
int queue = 0;
int exclusive = 0;
int time_update = 0;
int time_real = 0;
if (!PyArg_ParseTuple(args, "(BB)(BB)|iiii", &(sender.client),
&(sender.port), &(dest.client), &(dest.port),
&queue, &exclusive, &time_update, &time_real)) {
return NULL;
}
snd_seq_port_subscribe_alloca(&sinfo);
snd_seq_port_subscribe_set_sender(sinfo, &sender);
snd_seq_port_subscribe_set_dest(sinfo, &dest);
snd_seq_port_subscribe_set_queue(sinfo, queue);
snd_seq_port_subscribe_set_exclusive(sinfo, exclusive);
snd_seq_port_subscribe_set_time_update(sinfo, time_update);
snd_seq_port_subscribe_set_time_real(sinfo, time_real);
ret = snd_seq_subscribe_port(self->handle, sinfo);
if (ret < 0) {
RAISESND(ret, "Failed to connect ports %d:%d -> %d:%d",
sender.client, sender.port, dest.client, dest.port);
return NULL;
}
Py_RETURN_NONE;
}
/** alsaseq.Sequencer disconnect_ports() method: __doc__ */
PyDoc_STRVAR(Sequencer_disconnect_ports__doc__,
"disconnect_ports(srcaddr, destaddr)\n"
"\n"
"Disconnect the ports specified by srcaddr and dstaddr.\n"
"\n"
"Parameters:\n"
" srcaddr -- (tuple) the client_id, port_id tuple for the source\n"
" port (the port sending events)\n"
" dstaddr -- (tuple) the client_id, port_id tuple for the destination\n"
" port (the port receiveng events)\n"
"Raises:\n"
" SequenceError: if ALSA can't disconnect the port"
);
/** alsaseq.Sequencer disconnect_ports() method */
static PyObject *
Sequencer_disconnect_ports(SequencerObject *self,
PyObject *args) {
snd_seq_addr_t sender, dest;
snd_seq_port_subscribe_t *sinfo;
int ret;
if (!PyArg_ParseTuple(args, "(BB)(BB)", &(sender.client),
&(sender.port), &(dest.client), &(dest.port))) {
return NULL;
}
snd_seq_port_subscribe_alloca(&sinfo);
snd_seq_port_subscribe_set_sender(sinfo, &sender);
snd_seq_port_subscribe_set_dest(sinfo, &dest);
ret = snd_seq_unsubscribe_port(self->handle, sinfo);
if (ret < 0) {
RAISESND(ret, "Failed to disconnect ports: %d:%d --> %d:%d",
sender.client, sender.port, dest.client, dest.port);
return NULL;
}
Py_RETURN_NONE;
}
/** alsaseq.Sequencer get_connect_info() method: __doc__ */
PyDoc_STRVAR(Sequencer_get_connect_info__doc__,
"get_connect_info(srcaddr, dstaddr) -> dictionary\n"
"\n"
"Retrieve the subscribe info of the specified connection.\n"
"\n"
"Parameters:\n"
" srcaddr -- (tuple) the client_id, port_id tuple for the source\n"
" port (the port sending events)\n"
" dstaddr -- (tuple) the client_id, port_id tuple for the destination\n"
" port (the port receiveng events)\n"
"Returns:\n"
" (dict) a dictionary with the following values:\n"
" queue -- \n"
" exclusive -- \n"
" time_update -- \n"
" time_real --- \n"
"Raises:\n"
" SequenceError: if ALSA can't retrieve the connection or the\n"
" connection doesn't exists."
);
static PyObject*
Sequencer_get_connect_info(SequencerObject *self,
PyObject *args) {
snd_seq_addr_t sender, dest;
snd_seq_port_subscribe_t *sinfo;
int ret;
if (!PyArg_ParseTuple(args, "(BB)(BB)", &(sender.client),
&(sender.port), &(dest.client), &(dest.port))) {
return NULL;
}
snd_seq_port_subscribe_alloca(&sinfo);
snd_seq_port_subscribe_set_sender(sinfo, &sender);
snd_seq_port_subscribe_set_dest(sinfo, &dest);
ret = snd_seq_get_port_subscription(self->handle, sinfo);
if (ret < 0) {
RAISESND(ret, "Failed to get port subscript: %d:%d --> %d:%d",
sender.client, sender.port, dest.client, dest.port);
return NULL;
}
return Py_BuildValue(
"{sisisisi}",
"queue", (int)snd_seq_port_subscribe_get_queue(sinfo),
"exclusive", (int)snd_seq_port_subscribe_get_exclusive(sinfo),
"time_update", (int)snd_seq_port_subscribe_get_time_update(sinfo),
"time_real", (int)snd_seq_port_subscribe_get_time_real(sinfo));
}
/** alsaseq.Sequencer receive_events() method: __doc__ */
PyDoc_STRVAR(Sequencer_receive_events__doc__,
"receive_events(timeout = 0, maxevents = self.receive_maxevents) -> list\n"
"\n"
"Receive events.\n"
"\n"
"Parameters:\n"
" timeout -- (int) time for wating for events in milliseconds\n"
" maxevents -- (int) max events to be returned\n"
"Returns:\n"
" (list) a list of alsaseq.SeqEvent objects\n"
"Raises:\n"
" TypeError: if an invalid type was used in a parameter\n"
" SequencerError: if ALSA error occurs."
);
/** alsaseq.Sequencer receive_events() method */
static PyObject *
Sequencer_receive_events(SequencerObject *self,
PyObject *args,
PyObject *kwds) {
int maxevents = self->receive_max_events;
snd_seq_event_t *event = NULL;
int timeout = 0;
int ret;
char *kwlist[] = {"timeout", "maxevents", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|ii", kwlist, &timeout,
&maxevents)) {
return NULL;
}
if (self->receive_fds == NULL) {
self->receive_max = snd_seq_poll_descriptors_count(self->handle, POLLOUT);
self->receive_fds = malloc(sizeof(struct pollfd) * self->receive_max);
}
PyObject *list = PyList_New(0);
if (list == NULL) {
return NULL;
}
if (self->receive_bytes <= 0 && timeout != 0) {
snd_seq_poll_descriptors(self->handle, self->receive_fds,
self->receive_max, POLLIN);
Py_BEGIN_ALLOW_THREADS;
ret = poll(self->receive_fds, self->receive_max, timeout);
Py_END_ALLOW_THREADS;
if (ret == 0) {
return list;
} else if (ret < 0) {
RAISESTR("Failed to poll from receive: %s", strerror(-ret));
return NULL;
}
}
do {
ret = snd_seq_event_input(self->handle, &event);
self->receive_bytes = ret;
if (ret < 0) {
if (ret != -EAGAIN) {
}
break;
}
PyObject *SeqEventObject = SeqEvent_create(event);
if (SeqEventObject == NULL) {
RAISESTR("Error creating event!");
return NULL;
}
PyList_Append(list, SeqEventObject);
Py_DECREF(SeqEventObject);
maxevents --;
} while (maxevents > 0 && ret > 0);
return list;
}
/** alsaseq.Sequencer output_event() method: __doc__ */
PyDoc_STRVAR(Sequencer_output_event__doc__,
"output_event(event)\n"
"\n"
"Put the the given event in the outputbuffer. This actually will enqueue\n"
"the event, to make sure it's sent, use the drain_output() method.\n"
"\n"
"Parameters:\n"
" event -- a SeqEvent object\n"
"Raises:\n"
" SequencerError: if ALSA can't send the event"
);
/** alsaseq.Sequencer output_event() method */
static PyObject *
Sequencer_output_event(SequencerObject *self,
PyObject *args,
PyObject *kwds) {
SeqEventObject *seqevent;
char *kwlist[] = {"event", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", kwlist,
&seqevent)) {
return NULL;
}
if (!PyObject_TypeCheck(seqevent, &SeqEventType)) {
PyErr_SetString(PyExc_TypeError, "alsaseq.SeqEvent expected");
return NULL;
}
snd_seq_event_output(self->handle, seqevent->event);
Py_RETURN_NONE;
}
/** alsaseq.Sequencer drain_output() method: __doc__ */
PyDoc_STRVAR(Sequencer_drain_output__doc__,
"drain_output()\n"
"\n"
"Drain the output, making sure all events int the buffer are sent.\n"
"The events sent may remain unprocessed, to make sure they are\n"
"processed, call the sync_output_queue() method.\n"
"\n"
"Raises:\n"
" SequencerError: if ALSA can't drain the output"
);
/** alsaseq.Sequencer drain_output() method */
static PyObject *Sequencer_drain_output(SequencerObject *self,
PyObject *args) {
int ret;
ret = snd_seq_drain_output(self->handle);
if (ret < 0) {
RAISESND(ret, "Failed to drain output");
return NULL;
}
Py_RETURN_NONE;
}
/** alsaseq.Sequencer sync_output_queue() method: __doc__ */
PyDoc_STRVAR(Sequencer_sync_output_queue__doc__,
"sync_output_queue()\n"
"\n"
"Waits until all events of this clients are processed.\n"
"\n"
"Raises:\n"
" SequencerError: if an ALSA error occurs."
);
/** alsaseq.Sequencer sync_output_queue() method */
static PyObject *
Sequencer_sync_output_queue(SequencerObject *self,
PyObject *args) {
int ret;
ret = snd_seq_sync_output_queue(self->handle);
if (ret < 0) {
RAISESND(ret, "Failed to sync output queue");
return NULL;
}
Py_RETURN_NONE;
}
/** alsaseq.Sequencer parse_address() method: __doc__ */
PyDoc_STRVAR(Sequencer_parse_address__doc__,
"parse_address(string) -> tuple\n"
"\n"
"Parses the given string as an ALSA client:port. You can use client,\n"
"port id's or names.\n"
"\n"
"Parameters:\n"
" string -- the address in the format client:port.\n"
"Returns:\n"
" the tuple (client_id, port_id).\n"
"Raises:\n"
" SequencerError: if ALSA can't parse the given address"
);
/** alsaseq.Sequencer parse_address() method */
static PyObject *
Sequencer_parse_address(SequencerObject *self,
PyObject *args) {
snd_seq_addr_t addr;
char *str = NULL;
int ret;
if (!PyArg_ParseTuple(args, "s", &(str))) {
return NULL;
}
ret = snd_seq_parse_address(self->handle, &addr, str);
if (ret < 0) {
RAISESND(ret, "Invalid client:port specification '%s'", str);
return NULL;
}
PyObject *tuple = PyTuple_New(2);
PyTuple_SetItem(tuple, 0, PyInt_FromLong(addr.client));
PyTuple_SetItem(tuple, 1, PyInt_FromLong(addr.port));
return tuple;
}
/** alsaseq.Sequencer create_queue() method: __doc__ */
PyDoc_STRVAR(Sequencer_create_queue__doc__,
"create_queue(name=None)-> int\n"
"\n"
"Creates a queue with the optional given name.\n"
"\n"
"Parameters:\n"
" name -- the name of the queue.\n"
"Returns:\n"
" the queue id.\n"
"Raises:\n"
" SequencerError: if ALSA can't create the queue"
);
/** alsaseq.Sequencer create_queue() method */
static PyObject *
Sequencer_create_queue(SequencerObject *self,
PyObject *args,
PyObject *kwds) {
char *kwlist[] = {"name", NULL};
char *queue_name = NULL;
int ret;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|s", kwlist,
&queue_name)) {
return NULL;
}
if (queue_name != NULL) {
ret = snd_seq_alloc_named_queue(self->handle, queue_name);
} else {
ret = snd_seq_alloc_queue(self->handle);
}
if (ret < 0) {
RAISESND(ret, "Failed to create queue");
return NULL;
}
return PyInt_FromLong(ret);
}
/** alsaseq.Sequencer delete_queue() method: __doc__ */
PyDoc_STRVAR(Sequencer_delete_queue__doc__,
"delete_queue(queue)\n"
"\n"
"Deletes (frees) a queue.\n"
"\n"
"Parameters:\n"
" queue -- the queue id.\n"
"Raises:\n"
" SequencerError: if ALSA can't delete the queue."
);
/** alsaseq.Sequencer delete_queue() method */
static PyObject *
Sequencer_delete_queue(SequencerObject *self,
PyObject *args,
PyObject *kwds) {
char *kwlist[] = {"queue", NULL};
int queue_id;
int ret;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist,
&queue_id)) {
return NULL;
}
ret = snd_seq_free_queue(self->handle, queue_id);
if (ret < 0) {
RAISESND(ret, "Failed to create queue");
return NULL;
}
Py_RETURN_NONE;
}
/** alsaseq.Sequencer queue_tempo() method: __doc__ */
PyDoc_STRVAR(Sequencer_queue_tempo__doc__,
"queue_tempo(queue, tempo=None, ppq=None) -> tuple"
"\n"
"Query and changes the queue tempo. For querying (not changing) the queue\n"
"tempo, pass only the queue id.\n"
"\n"
"Parameters:\n"
" queue -- the queue id.\n"
" tempo -- the new queue tempo or None for keeping the current tempo.\n"
" ppq -- the new queue ppq or None for keeping the current tempo.\n"
"Returns:\n"
" a tuple (tempo, ppq) with the current or changed tempo.\n"
"Raises:\n"
" SequencerError: if ALSA can't change the queue tempo or an invalid\n"
" queue was specified."
);
/** alsaseq.Sequencer queue_tempo() method */
static PyObject *
Sequencer_queue_tempo(SequencerObject *self,
PyObject *args,
PyObject *kwds) {
char *kwlist[] = {"queue", "tempo", "ppq", NULL};
int queueid, tempo=-1, ppq=-1;
int ret;
snd_seq_queue_tempo_t *queue_tempo;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "i|ii", kwlist,
&queueid, &tempo, &ppq)) {
return NULL;
}
snd_seq_queue_tempo_alloca(&queue_tempo);
ret = snd_seq_get_queue_tempo(self->handle, queueid, queue_tempo);
if (ret < 0) {
RAISESND(ret, "Failed to retrieve current queue tempo");
return NULL;
}
if (!PyArg_ParseTupleAndKeywords(args, kwds, "i|ii", kwlist,
&queueid, &tempo, &ppq)) {
return NULL;
}
if (tempo != -1) {
snd_seq_queue_tempo_set_tempo(queue_tempo, tempo);
}
if (ppq != -1) {
snd_seq_queue_tempo_set_ppq(queue_tempo, ppq);
}
if (tempo != -1 && ppq != -1) {
ret = snd_seq_set_queue_tempo(self->handle, queueid, queue_tempo);
if (ret < 0) {
RAISESND(ret, "Failed to set queue tempo");
return NULL;
}
}
tempo = snd_seq_queue_tempo_get_tempo(queue_tempo);
ppq = snd_seq_queue_tempo_get_ppq(queue_tempo);
PyObject *tuple = PyTuple_New(2);
PyTuple_SetItem(tuple, 0, PyInt_FromLong(tempo));
PyTuple_SetItem(tuple, 1, PyInt_FromLong(ppq));
return tuple;
}
/** alsaseq.Sequencer start_queue() method: __doc__ */
PyDoc_STRVAR(Sequencer_start_queue__doc__,
"start_queue(queue)\n"
"\n"
"Starts the specified queue.\n"
"\n"
"Parameters:\n"
" queue -- the queue id.\n"
"Raises:\n"
" SequencerError: if ALSA can't start the queue."
);
/** alsaseq.Sequencer start_queue() method */
static PyObject *
Sequencer_start_queue(SequencerObject *self,
PyObject *args,
PyObject *kwds) {
char *kwlist[] = {"queue", NULL};
int queueid;
int ret;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist,
&queueid)) {
return NULL;
}
ret = snd_seq_start_queue(self->handle, queueid, NULL);
if (ret < 0) {
RAISESND(ret, "Failed to start queue");
return NULL;
}
Py_RETURN_NONE;
}
/** alsaseq.Sequencer stop_queue() method: __doc__ */
PyDoc_STRVAR(Sequencer_stop_queue__doc__,
"stop_queue(queue)\n"
"\n"
"Stops the specified queue.\n"
"\n"
"Parameters:\n"
" queue -- the queue id.\n"
"Raises:\n"
" SequencerError: if ALSA can't stop the queue."
);
/** alsaseq.Sequencer stop_queue() method */
static PyObject *
Sequencer_stop_queue(SequencerObject *self,
PyObject *args,
PyObject *kwds) {
char *kwlist[] = {"queue", NULL};
int queueid;
int ret;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist,
&queueid)) {
return NULL;
}
ret = snd_seq_stop_queue(self->handle, queueid, NULL);
if (ret < 0) {
RAISESND(ret, "Failed to stop queue");
return NULL;
}
Py_RETURN_NONE;
}
PyDoc_STRVAR(Sequencer_registerpoll__doc__,
"register_poll(pollObj, input=False, output=False) -- Register poll file descriptors.");
static PyObject *
Sequencer_registerpoll(SequencerObject *self, PyObject *args, PyObject *kwds)
{
PyObject *pollObj, *reg, *t;
struct pollfd *pfd;
int i, count;
int input = 0;
int output = 0;
int mode = POLLIN|POLLOUT;
static char * kwlist[] = { "pollObj", "input", "output", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|ii", kwlist, &pollObj, &input, &output))
return NULL;
if (input && !output)
mode = POLLIN;
else if (!input && output)
mode = POLLOUT;
count = snd_seq_poll_descriptors_count(self->handle, mode);
if (count <= 0)
Py_RETURN_NONE;
pfd = alloca(sizeof(struct pollfd) * count);
count = snd_seq_poll_descriptors(self->handle, pfd, count, mode);
if (count <= 0)
Py_RETURN_NONE;
reg = PyObject_GetAttrString(pollObj, "register");
if (!reg)
return NULL;
for (i = 0; i < count; i++) {
t = PyTuple_New(2);
if (!t) {
Py_DECREF(reg);
return NULL;
}
PyTuple_SET_ITEM(t, 0, PyInt_FromLong(pfd[i].fd));
PyTuple_SET_ITEM(t, 1, PyInt_FromLong(pfd[i].events));
Py_XDECREF(PyObject_CallObject(reg, t));
Py_DECREF(t);
}
Py_DECREF(reg);
Py_RETURN_NONE;
}
/** alsaseq.Sequencer tp_methods */
static PyMethodDef Sequencer_methods[] = {
{"create_simple_port",
(PyCFunction) Sequencer_create_simple_port,
METH_VARARGS | METH_KEYWORDS,
Sequencer_create_simple_port__doc__ },
{"connection_list",
(PyCFunction) Sequencer_connection_list,
METH_VARARGS,
Sequencer_connection_list__doc__ },
{"get_client_info",
(PyCFunction) Sequencer_get_client_info,
METH_VARARGS | METH_KEYWORDS,
Sequencer_get_client_info__doc__ },
{"get_port_info",
(PyCFunction) Sequencer_get_port_info,
METH_VARARGS | METH_KEYWORDS,
Sequencer_get_port_info__doc__ },
{"connect_ports",
(PyCFunction) Sequencer_connect_ports,
METH_VARARGS,
Sequencer_connect_ports__doc__ },
{"disconnect_ports",
(PyCFunction) Sequencer_disconnect_ports,
METH_VARARGS,
Sequencer_disconnect_ports__doc__ },
{"get_connect_info",
(PyCFunction) Sequencer_get_connect_info,
METH_VARARGS,
Sequencer_get_connect_info__doc__},
{"receive_events",
(PyCFunction) Sequencer_receive_events,
METH_VARARGS | METH_KEYWORDS,
Sequencer_receive_events__doc__},
{"output_event",
(PyCFunction) Sequencer_output_event,
METH_VARARGS | METH_KEYWORDS,
Sequencer_output_event__doc__},
{"drain_output",
(PyCFunction) Sequencer_drain_output,
METH_VARARGS,
Sequencer_drain_output__doc__},
{"sync_output_queue",
(PyCFunction) Sequencer_sync_output_queue,
METH_VARARGS,
Sequencer_sync_output_queue__doc__},
{"parse_address",
(PyCFunction) Sequencer_parse_address,
METH_VARARGS,
Sequencer_parse_address__doc__},
{"create_queue",
(PyCFunction) Sequencer_create_queue,
METH_VARARGS | METH_KEYWORDS,
Sequencer_create_queue__doc__},
{"delete_queue",
(PyCFunction) Sequencer_delete_queue,
METH_VARARGS | METH_KEYWORDS,
Sequencer_delete_queue__doc__},
{"queue_tempo",
(PyCFunction) Sequencer_queue_tempo,
METH_VARARGS | METH_KEYWORDS,
Sequencer_queue_tempo__doc__},
{"start_queue",
(PyCFunction) Sequencer_start_queue,
METH_VARARGS | METH_KEYWORDS,
Sequencer_start_queue__doc__},
{"stop_queue",
(PyCFunction) Sequencer_stop_queue,
METH_VARARGS | METH_KEYWORDS,
Sequencer_stop_queue__doc__},
{"register_poll",
(PyCFunction) Sequencer_registerpoll,
METH_VARARGS | METH_KEYWORDS,
Sequencer_registerpoll__doc__},
{NULL}
};
/** alsaseq.Sequencer type */
static PyTypeObject SequencerType = {
PyVarObject_HEAD_INIT(NULL, 0)
tp_name: "alsaseq.Sequencer",
tp_basicsize: sizeof(SequencerObject),
tp_dealloc: (destructor) Sequencer_dealloc,
tp_flags: Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
tp_doc: Sequencer__doc__,
tp_init: (initproc) Sequencer_init,
tp_new: PyType_GenericNew,
tp_alloc: PyType_GenericAlloc,
tp_free: PyObject_Del,
tp_repr: (reprfunc) Sequencer_repr,
tp_methods: Sequencer_methods,
tp_getset: Sequencer_getset
};
//////////////////////////////////////////////////////////////////////////////
// alsaseq module implementation
//////////////////////////////////////////////////////////////////////////////
/** alsaseq module: __doc__ */
char alsaseq__doc__ [] =
"libasound alsaseq wrapper"
;
/** alsaseq module methods */
static PyMethodDef alsaseq_methods[] = {
{ NULL },
};
MOD_INIT(alsaseq)
{
PyObject *module;
if (PyType_Ready(&ConstantType) < 0)
return MOD_ERROR_VAL;
if (PyType_Ready(&SeqEventType) < 0)
return MOD_ERROR_VAL;
if (PyType_Ready(&SequencerType) < 0)
return MOD_ERROR_VAL;
MOD_DEF(module, "alsaseq", alsaseq__doc__, alsaseq_methods);
if (module == NULL)
return MOD_ERROR_VAL;
SequencerError = PyErr_NewException("alsaseq.SequencerError", NULL, NULL);
if (SequencerError == NULL)
return MOD_ERROR_VAL;
Py_INCREF(SequencerError);
PyModule_AddObject(module, "SequencerError", SequencerError);
Py_INCREF(&SeqEventType);
PyModule_AddObject(module, "SeqEvent", (PyObject *) &SeqEventType);
Py_INCREF(&SequencerType);
PyModule_AddObject(module, "Sequencer", (PyObject *) &SequencerType);
Py_INCREF(&ConstantType);
PyModule_AddObject(module, "Constant", (PyObject *) &ConstantType);
/* misc constants */
PyModule_AddStringConstant(module,
"SEQ_LIB_VERSION_STR",
SND_LIB_VERSION_STR);
/* add Constant dictionaries to module */
TCONSTDICTADD(module, STREAMS, "_dstreams");
TCONSTDICTADD(module, MODE, "_dmode");
TCONSTDICTADD(module, QUEUE, "_dqueue");
TCONSTDICTADD(module, CLIENT_TYPE, "_dclienttype");
TCONSTDICTADD(module, PORT_CAP, "_dportcap");
TCONSTDICTADD(module, PORT_TYPE, "_dporttype");
TCONSTDICTADD(module, EVENT_TYPE, "_deventtype");
TCONSTDICTADD(module, EVENT_TIMESTAMP, "_deventtimestamp");
TCONSTDICTADD(module, EVENT_TIMEMODE, "_deventtimemode");
TCONSTDICTADD(module, ADDR_CLIENT, "_dclient");
TCONSTDICTADD(module, ADDR_PORT, "_dport");
/* Sequencer streams */
TCONSTADD(module, STREAMS, SEQ_OPEN_OUTPUT);
TCONSTADD(module, STREAMS, SEQ_OPEN_INPUT);
TCONSTADD(module, STREAMS, SEQ_OPEN_DUPLEX);
/* Sequencer blocking mode */
# define SND_SEQ_BLOCK 0
TCONSTADD(module, MODE, SEQ_BLOCK);
TCONSTADD(module, MODE, SEQ_NONBLOCK);
/* Known queue id */
TCONSTADD(module, QUEUE, SEQ_QUEUE_DIRECT);
/* client types */
TCONSTADD(module, CLIENT_TYPE, SEQ_USER_CLIENT);
TCONSTADD(module, CLIENT_TYPE, SEQ_KERNEL_CLIENT);
/* Sequencer port cap */
# define SND_SEQ_PORT_CAP_NONE 0
TCONSTADD(module, PORT_CAP, SEQ_PORT_CAP_NONE);
TCONSTADD(module, PORT_CAP, SEQ_PORT_CAP_WRITE);
TCONSTADD(module, PORT_CAP, SEQ_PORT_CAP_SYNC_WRITE);
TCONSTADD(module, PORT_CAP, SEQ_PORT_CAP_SYNC_READ);
TCONSTADD(module, PORT_CAP, SEQ_PORT_CAP_SUBS_WRITE);
TCONSTADD(module, PORT_CAP, SEQ_PORT_CAP_SUBS_READ);
TCONSTADD(module, PORT_CAP, SEQ_PORT_CAP_READ);
TCONSTADD(module, PORT_CAP, SEQ_PORT_CAP_NO_EXPORT);
TCONSTADD(module, PORT_CAP, SEQ_PORT_CAP_DUPLEX);
/* Sequencer port type */
TCONSTADD(module, PORT_TYPE, SEQ_PORT_TYPE_SYNTHESIZER);
TCONSTADD(module, PORT_TYPE, SEQ_PORT_TYPE_SYNTH);
TCONSTADD(module, PORT_TYPE, SEQ_PORT_TYPE_SPECIFIC);
TCONSTADD(module, PORT_TYPE, SEQ_PORT_TYPE_SOFTWARE);
TCONSTADD(module, PORT_TYPE, SEQ_PORT_TYPE_SAMPLE);
TCONSTADD(module, PORT_TYPE, SEQ_PORT_TYPE_PORT);
TCONSTADD(module, PORT_TYPE, SEQ_PORT_TYPE_MIDI_XG);
TCONSTADD(module, PORT_TYPE, SEQ_PORT_TYPE_MIDI_MT32);
TCONSTADD(module, PORT_TYPE, SEQ_PORT_TYPE_MIDI_GS);
TCONSTADD(module, PORT_TYPE, SEQ_PORT_TYPE_MIDI_GM2);
TCONSTADD(module, PORT_TYPE, SEQ_PORT_TYPE_MIDI_GM);
TCONSTADD(module, PORT_TYPE, SEQ_PORT_TYPE_MIDI_GENERIC);
TCONSTADD(module, PORT_TYPE, SEQ_PORT_TYPE_HARDWARE);
TCONSTADD(module, PORT_TYPE, SEQ_PORT_TYPE_DIRECT_SAMPLE);
TCONSTADD(module, PORT_TYPE, SEQ_PORT_TYPE_APPLICATION);
/* SeqEvent event type */
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_SYSTEM);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_RESULT);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_NOTE);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_NOTEON);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_NOTEOFF);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_KEYPRESS);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_CONTROLLER);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_PGMCHANGE);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_CHANPRESS);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_PITCHBEND);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_CONTROL14);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_NONREGPARAM);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_REGPARAM);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_SONGPOS);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_SONGSEL);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_QFRAME);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_TIMESIGN);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_KEYSIGN);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_START);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_CONTINUE);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_STOP);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_SETPOS_TICK);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_SETPOS_TIME);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_TEMPO);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_CLOCK);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_TICK);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_QUEUE_SKEW);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_SYNC_POS);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_TUNE_REQUEST);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_RESET);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_SENSING);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_ECHO);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_OSS);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_CLIENT_START);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_CLIENT_EXIT);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_CLIENT_CHANGE);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_PORT_START);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_PORT_EXIT);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_PORT_CHANGE);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_PORT_SUBSCRIBED);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_PORT_UNSUBSCRIBED);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_USR1);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_USR2);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_USR3);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_USR4);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_USR5);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_USR6);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_USR7);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_USR8);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_USR9);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_SYSEX);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_BOUNCE);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_USR_VAR0);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_USR_VAR1);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_USR_VAR2);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_USR_VAR3);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_USR_VAR4);
TCONSTADD(module, EVENT_TYPE, SEQ_EVENT_NONE);
/* SeqEvent event timestamp flags */
TCONSTADD(module, EVENT_TIMESTAMP, SEQ_TIME_STAMP_TICK);
TCONSTADD(module, EVENT_TIMESTAMP, SEQ_TIME_STAMP_REAL);
/* SeqEvent event timemode flags */
TCONSTADD(module, EVENT_TIMEMODE, SEQ_TIME_MODE_ABS);
TCONSTADD(module, EVENT_TIMEMODE, SEQ_TIME_MODE_REL);
/* SeqEvent event addresses */
TCONSTADD(module, ADDR_CLIENT, SEQ_CLIENT_SYSTEM);
TCONSTADD(module, ADDR_CLIENT, SEQ_ADDRESS_BROADCAST);
TCONSTADD(module, ADDR_CLIENT, SEQ_ADDRESS_SUBSCRIBERS);
TCONSTADD(module, ADDR_CLIENT, SEQ_ADDRESS_UNKNOWN);
TCONSTADD(module, ADDR_PORT, SEQ_PORT_SYSTEM_TIMER);
TCONSTADD(module, ADDR_PORT, SEQ_PORT_SYSTEM_ANNOUNCE);
TCONSTADD(module, ADDR_PORT, SEQ_ADDRESS_BROADCAST);
TCONSTADD(module, ADDR_PORT, SEQ_ADDRESS_SUBSCRIBERS);
TCONSTADD(module, ADDR_PORT, SEQ_ADDRESS_UNKNOWN);
return MOD_SUCCESS_VAL(module);
}
|