/usr/lib/python2.7/dist-packages/pyolib/tables.py is in python-pyo 0.8.8-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
"""
Copyright 2009-2015 Olivier Belanger
This file is part of pyo, a python module to help digital signal
processing script creation.
pyo 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 3 of the
License, or (at your option) any later version.
pyo 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 pyo. If not, see <http://www.gnu.org/licenses/>.
"""
from ._core import *
from ._maps import *
from ._widgets import createGraphWindow, createDataGraphWindow, createSndViewTableWindow
from math import pi
import copy
######################################################################
### Tables
######################################################################
class HarmTable(PyoTableObject):
"""
Harmonic waveform generator.
Generates composite waveforms made up of weighted sums
of simple sinusoids.
:Parent: :py:class:`PyoTableObject`
:Args:
list: list, optional
Relative strengths of the fixed harmonic partial numbers 1,2,3, etc.
Defaults to [1].
size: int, optional
Table size in samples. Defaults to 8192.
>>> s = Server().boot()
>>> s.start()
>>> # Square wave up to 9th harmonic
>>> t = HarmTable([1,0,.33,0,.2,0,.143,0,.111])
>>> a = Osc(table=t, freq=[199,200], mul=.2).out()
"""
def __init__(self, list=[1., 0.], size=8192):
pyoArgsAssert(self, "lI", list, size)
PyoTableObject.__init__(self, size)
self._auto_normalize = False
self._list = copy.deepcopy(list)
self._base_objs = [HarmTable_base(self._list, size)]
def autoNormalize(self, x):
"""
Activate/deactivate automatic normalization when harmonics changed.
:Args:
x: boolean
True for activating automatic normalization, False for
deactivating it.
"""
self._auto_normalize = x
if self._auto_normalize:
self.normalize()
def replace(self, list):
"""
Redraw the waveform according to a new set of harmonics
relative strengths.
:Args:
list: list
Relative strengths of the fixed harmonic partial
numbers 1,2,3, etc.
"""
pyoArgsAssert(self, "l", list)
self._list = list
[obj.replace(list) for obj in self._base_objs]
if self._auto_normalize:
self.normalize()
self.refreshView()
def _get_current_data(self):
# internal that returns the data to draw in a DataTableGrapher.
return self._list
def graph(self, yrange=(-1.0, 1.0), title=None, wxnoserver=False):
"""
Opens a multislider window to control the data values.
When editing the grapher with the mouse, the new values are
sent to the object to replace the table content.
:Args:
yrange: tuple, optional
Set the min and max values of the Y axis of the multislider.
Defaults to (0.0, 1.0).
title: string, optional
Title of the window. If none is provided, the name of the
class is used.
wxnoserver: boolean, optional
With wxPython graphical toolkit, if True, tells the
interpreter that there will be no server window.
If `wxnoserver` is set to True, the interpreter will not wait for
the server GUI before showing the controller window.
.. note::
The number of bars in the graph is initialized to the length
of the list of relative strentghs at the time the graph is
created.
"""
createDataGraphWindow(self, yrange, title, wxnoserver)
@property
def list(self):
"""list. Relative strengths of the fixed harmonic partial numbers."""
return self._list
@list.setter
def list(self, x): self.replace(x)
class SawTable(PyoTableObject):
"""
Sawtooth waveform generator.
Generates sawtooth waveforms made up of fixed number of harmonics.
:Parent: :py:class:`PyoTableObject`
:Args:
order: int, optional
Number of harmonics sawtooth is made of.
Defaults to 10.
size: int, optional
Table size in samples. Defaults to 8192.
>>> s = Server().boot()
>>> s.start()
>>> t = SawTable(order=12).normalize()
>>> a = Osc(table=t, freq=[199,200], mul=.2).out()
"""
def __init__(self, order=10, size=8192):
pyoArgsAssert(self, "II", order, size)
PyoTableObject.__init__(self, size)
self._order = order
list = [1. / i for i in range(1,(order+1))]
self._base_objs = [HarmTable_base(list, size)]
def setOrder(self, x):
"""
Change the `order` attribute and redraw the waveform.
:Args:
x: int
New number of harmonics
"""
pyoArgsAssert(self, "I", x)
self._order = x
list = [1. / i for i in range(1,(self._order+1))]
[obj.replace(list) for obj in self._base_objs]
self.refreshView()
@property
def order(self):
"""int. Number of harmonics sawtooth is made of."""
return self._order
@order.setter
def order(self, x): self.setOrder(x)
class SquareTable(PyoTableObject):
"""
Square waveform generator.
Generates square waveforms made up of fixed number of harmonics.
:Parent: :py:class:`PyoTableObject`
:Args:
order: int, optional
Number of harmonics square waveform is made of. The waveform will
contains `order` odd harmonics. Defaults to 10.
size: int, optional
Table size in samples. Defaults to 8192.
>>> s = Server().boot()
>>> s.start()
>>> t = SquareTable(order=15).normalize()
>>> a = Osc(table=t, freq=[199,200], mul=.2).out()
"""
def __init__(self, order=10, size=8192):
pyoArgsAssert(self, "II", order, size)
PyoTableObject.__init__(self, size)
self._order = order
list = []
for i in range(1,(order*2)):
if i%2 == 1:
list.append(1. / i)
else:
list.append(0.)
self._base_objs = [HarmTable_base(list, size)]
def setOrder(self, x):
"""
Change the `order` attribute and redraw the waveform.
:Args:
x: int
New number of harmonics
"""
pyoArgsAssert(self, "I", x)
self._order = x
list = []
for i in range(1,(self._order*2)):
if i%2 == 1:
list.append(1. / i)
else:
list.append(0.)
[obj.replace(list) for obj in self._base_objs]
self.refreshView()
@property
def order(self):
"""int. Number of harmonics square waveform is made of."""
return self._order
@order.setter
def order(self, x): self.setOrder(x)
class ChebyTable(PyoTableObject):
"""
Chebyshev polynomials of the first kind.
Uses Chebyshev coefficients to generate stored polynomial functions
which, under waveshaping, can be used to split a sinusoid into
harmonic partials having a pre-definable spectrum.
:Parent: :py:class:`PyoTableObject`
:Args:
list: list, optional
Relative strengths of partials numbers 1,2,3, ..., 12 that will
result when a sinusoid of amplitude 1 is waveshaped using this
function table. Up to 12 partials can be specified. Defaults to [1].
size: int, optional
Table size in samples. Defaults to 8192.
>>> s = Server().boot()
>>> s.start()
>>> t = ChebyTable([1,0,.33,0,.2,0,.143,0,.111])
>>> lfo = Sine(freq=.25, mul=0.45, add=0.5)
>>> a = Sine(freq=[200,201], mul=lfo)
>>> b = Lookup(table=t, index=a, mul=1-lfo).out()
"""
def __init__(self, list=[1., 0.], size=8192):
pyoArgsAssert(self, "lI", list, size)
PyoTableObject.__init__(self, size)
self._auto_normalize = False
self._list = copy.deepcopy(list)
self._base_objs = [ChebyTable_base(self._list, size)]
def autoNormalize(self, x):
"""
Activate/deactivate automatic normalization when harmonics changed.
:Args:
x: boolean
True for activating automatic normalization, False for
deactivating it.
"""
self._auto_normalize = x
if self._auto_normalize:
self.normalize()
def replace(self, list):
"""
Redraw the waveform according to a new set of harmonics
relative strengths that will result when a sinusoid of
amplitude 1 is waveshaped using this function table.
:Args:
list: list
Relative strengths of the fixed harmonic partial
numbers 1,2,3, ..., 12. Up to 12 partials can be specified.
"""
pyoArgsAssert(self, "l", list)
self._list = list
[obj.replace(list) for obj in self._base_objs]
if self._auto_normalize:
self.normalize()
self.refreshView()
def getNormTable(self):
"""
Return a DataTable filled with the normalization function
corresponding to the current polynomial.
"""
if sum(self._list[1::2]) == 0:
data = self._base_objs[0].getNormTable(0)
else:
data = self._base_objs[0].getNormTable(1)
return DataTable(size=len(data), init=data).normalize()
def _get_current_data(self):
# internal that returns the data to draw in a DataTableGrapher.
return self._list
def graph(self, yrange=(-1.0, 1.0), title=None, wxnoserver=False):
"""
Opens a multislider window to control the data values.
When editing the grapher with the mouse, the new values are
sent to the object to replace the table content.
:Args:
yrange: tuple, optional
Set the min and max values of the Y axis of the multislider.
Defaults to (0.0, 1.0).
title: string, optional
Title of the window. If none is provided, the name of the
class is used.
wxnoserver: boolean, optional
With wxPython graphical toolkit, if True, tells the
interpreter that there will be no server window.
If `wxnoserver` is set to True, the interpreter will not wait for
the server GUI before showing the controller window.
.. note::
The number of bars in the graph is initialized to the length
of the list of relative strentghs at the time the graph is
created.
"""
createDataGraphWindow(self, yrange, title, wxnoserver)
@property
def list(self):
"""list. Relative strengths of the fixed harmonic partial numbers."""
return self._list
@list.setter
def list(self, x): self.replace(x)
class HannTable(PyoTableObject):
"""
Generates Hanning window function.
:Parent: :py:class:`PyoTableObject`
:Args:
size: int, optional
Table size in samples. Defaults to 8192.
>>> s = Server().boot()
>>> s.start()
>>> # Hanning envelope
>>> t = HannTable()
>>> a = Osc(table=t, freq=2, mul=.2)
>>> b = Sine(freq=[299,300], mul=a).out()
"""
def __init__(self, size=8192):
pyoArgsAssert(self, "I", size)
PyoTableObject.__init__(self, size)
self._base_objs = [HannTable_base(size)]
class SincTable(PyoTableObject):
"""
Generates sinc window function.
:Parent: :py:class:`PyoTableObject`
:Args:
freq: float, optional
Frequency, in radians, of the sinc function. Defaults to pi*2.
windowed: boolean, optional
If True, an hanning window is applied on the sinc function. Defaults to False.
size: int, optional
Table size in samples. Defaults to 8192.
>>> import math
>>> s = Server().boot()
>>> s.start()
>>> t = SincTable(freq=math.pi*6, windowed=True)
>>> a = Osc(t, freq=[199,200], mul=.2).out()
"""
def __init__(self, freq=pi*2, windowed=False, size=8192):
pyoArgsAssert(self, "NBI", freq, windowed, size)
PyoTableObject.__init__(self, size)
self._freq = freq
self._windowed = windowed
self._base_objs = [SincTable_base(freq, windowed, size)]
def setFreq(self, x):
"""
Change the frequency of the sinc function. This will redraw the envelope.
:Args:
x: float
New frequency in radians.
"""
pyoArgsAssert(self, "N", x)
self._freq = x
[obj.setFreq(x) for obj in self._base_objs]
self.refreshView()
def setWindowed(self, x):
"""
Change the windowed flag. This will redraw the envelope.
:Args:
x: boolean
New windowed flag.
"""
pyoArgsAssert(self, "B", x)
self._windowed = x
[obj.setWindowed(x) for obj in self._base_objs]
self.refreshView()
@property
def freq(self):
"""float. Frequency of the sinc function."""
return self._freq
@freq.setter
def freq(self, x): self.setFreq(x)
@property
def windowed(self):
"""boolean. Windowed flag."""
return self._windowed
@windowed.setter
def windowed(self, x): self.setWindowed(x)
class WinTable(PyoTableObject):
"""
Generates different kind of windowing functions.
:Parent: :py:class:`PyoTableObject`
:Args:
type: int, optional
Windowing function. Possible choices are:
0. Rectangular (no window)
1. Hamming
2. Hanning (default)
3. Bartlett (triangular)
4. Blackman 3-term
5. Blackman-Harris 4-term
6. Blackman-Harris 7-term
7. Tuckey (alpha = 0.66)
8. Sine (half-sine window)
size: int, optional
Table size in samples. Defaults to 8192.
>>> s = Server().boot()
>>> s.start()
>>> # Triangular envelope
>>> t = WinTable(type=3)
>>> a = Osc(table=t, freq=2, mul=.2)
>>> b = SineLoop(freq=[199,200], feedback=0.05, mul=a).out()
"""
def __init__(self, type=2, size=8192):
pyoArgsAssert(self, "II", type, size)
PyoTableObject.__init__(self, size)
self._type = type
self._base_objs = [WinTable_base(type, size)]
def setType(self, type):
"""
Sets the windowing function.
:Args:
type: int {0 -> 8}
Windowing function.
"""
pyoArgsAssert(self, "I", type)
self._type = type
[obj.setType(type) for obj in self._base_objs]
self.refreshView()
@property
def type(self):
"""int. Windowing function."""
return self._type
@type.setter
def type(self, x): self.setType(x)
class ParaTable(PyoTableObject):
"""
Generates parabola window function.
The parabola is a conic section, the intersection of a right circular conical
surface and a plane parallel to a generating straight line of that surface.
:Parent: :py:class:`PyoTableObject`
:Args:
size: int, optional
Table size in samples. Defaults to 8192.
>>> s = Server().boot()
>>> s.start()
>>> # Parabola envelope
>>> t = ParaTable()
>>> a = Osc(table=t, freq=2, mul=.2)
>>> b = SineLoop(freq=[299,300], feedback=0.05, mul=a).out()
"""
def __init__(self, size=8192):
pyoArgsAssert(self, "I", size)
PyoTableObject.__init__(self, size)
self._base_objs = [ParaTable_base(size)]
class LinTable(PyoTableObject):
"""
Construct a table from segments of straight lines in breakpoint fashion.
:Parent: :py:class:`PyoTableObject`
:Args:
list: list, optional
List of tuples indicating location and value of each points
in the table. The default, [(0,0.), (8191, 1.)], creates a
straight line from 0.0 at location 0 to 1.0 at the end of the
table (size - 1). Location must be an integer.
size: int, optional
Table size in samples. Defaults to 8192.
.. note::
Locations in the list must be in increasing order. If the last value
is less than size, the rest of the table will be filled with zeros.
>>> s = Server().boot()
>>> s.start()
>>> # Sharp attack envelope
>>> t = LinTable([(0,0), (100,1), (1000,.25), (8191,0)])
>>> a = Osc(table=t, freq=2, mul=.25)
>>> b = SineLoop(freq=[299,300], feedback=0.05, mul=a).out()
"""
def __init__(self, list=[(0, 0.), (8191, 1.)], size=8192):
pyoArgsAssert(self, "lI", list, size)
PyoTableObject.__init__(self, size)
if size < list[-1][0]:
print("LinTable warning: size smaller than last point position.")
print(" Increased size to last point position + 1")
size = list[-1][0] + 1
self._size = size
self._base_objs = [LinTable_base(copy.deepcopy(list), size)]
def replace(self, list):
"""
Draw a new envelope according to the new `list` parameter.
:Args:
list: list
List of tuples indicating location and value of each points
in the table. Location must be integer.
"""
pyoArgsAssert(self, "l", list)
self._list = list
[obj.replace(list) for obj in self._base_objs]
self.refreshView()
def loadRecFile(self, filename, tolerance=0.02):
"""
Import an automation recording file in the table.
loadRecFile takes a recording file, usually from a ControlRec object,
as `filename` parameter, applies a filtering pre-processing to eliminate
redundancies and loads the result in the table as a list of points.
Filtering process can be controled with the `tolerance` parameter.
:Args:
filename: string
Full path of an automation recording file.
tolerance: float, optional
Tolerance of the filter. A higher value will eliminate more points.
Defaults to 0.02.
"""
pyoArgsAssert(self, "SN", filename, tolerance)
_path, _name = os.path.split(filename)
# files = sorted([f for f in os.listdir(_path) if _name+"_" in f])
# if _name not in files: files.append(_name)
files = [filename]
for i, obj in enumerate(self._base_objs):
p = os.path.join(_path, wrap(files,i))
f = open(p, "r")
values = [(float(l.split()[0]), float(l.split()[1])) for l in f.readlines()]
scl = self._size / values[-1][0]
values = [(int(v[0]*scl), v[1]) for v in values]
f.close()
values = reducePoints(values, tolerance=tolerance)
self._list = values
obj.replace(values)
self.refreshView()
def getPoints(self):
"""
Returns list of points of the current table.
"""
return self._base_objs[0].getPoints()
def graph(self, yrange=(0.0, 1.0), title=None, wxnoserver=False):
"""
Opens a grapher window to control the shape of the envelope.
When editing the grapher with the mouse, the new set of points
will be send to the object on mouse up.
Ctrl+C with focus on the grapher will copy the list of points to the
clipboard, giving an easy way to insert the new shape in a script.
:Args:
yrange: tuple, optional
Set the min and max values of the Y axis of the graph.
Defaults to (0.0, 1.0).
title: string, optional
Title of the window. If none is provided, the name of the
class is used.
wxnoserver: boolean, optional
With wxPython graphical toolkit, if True, tells the
interpreter that there will be no server window.
If `wxnoserver` is set to True, the interpreter will not wait for
the server GUI before showing the controller window.
"""
createGraphWindow(self, 0, self._size, yrange, title, wxnoserver)
@property
def list(self):
"""list. List of tuples indicating location and value of each points in the table."""
return self.getPoints()
@list.setter
def list(self, x): self.replace(x)
class LogTable(PyoTableObject):
"""
Construct a table from logarithmic segments in breakpoint fashion.
:Parent: :py:class:`PyoTableObject`
:Args:
list: list, optional
List of tuples indicating location and value of each points
in the table. The default, [(0,0.), (8191, 1.)], creates a
logarithmic line from 0.0 at location 0 to 1.0 at the end of
the table (size - 1). Location must be an integer.
size: int, optional
Table size in samples. Defaults to 8192.
.. note::
Locations in the list must be in increasing order. If the last value
is less than size, the rest of the table will be filled with zeros.
Values must be greater than 0.0.
>>> s = Server().boot()
>>> s.start()
>>> t = LogTable([(0,0), (4095,1), (8192,0)])
>>> a = Osc(table=t, freq=2, mul=.25)
>>> b = SineLoop(freq=[599,600], feedback=0.05, mul=a).out()
"""
def __init__(self, list=[(0, 0.), (8191, 1.)], size=8192):
pyoArgsAssert(self, "lI", list, size)
PyoTableObject.__init__(self, size)
if size < list[-1][0]:
print("LogTable warning: size smaller than last point position.")
print(" Increased size to last point position + 1")
size = list[-1][0] + 1
self._size = size
self._base_objs = [LogTable_base(copy.deepcopy(list), size)]
def replace(self, list):
"""
Draw a new envelope according to the new `list` parameter.
:Args:
list: list
List of tuples indicating location and value of each points
in the table. Location must be integer.
"""
pyoArgsAssert(self, "l", list)
self._list = list
[obj.replace(list) for obj in self._base_objs]
self.refreshView()
def loadRecFile(self, filename, tolerance=0.02):
"""
Import an automation recording file in the table.
loadRecFile takes a recording file, usually from a ControlRec object,
as `filename` parameter, applies a filtering pre-processing to eliminate
redundancies and loads the result in the table as a list of points.
Filtering process can be controled with the `tolerance` parameter.
:Args:
filename: string
Full path of an automation recording file.
tolerance: float, optional
Tolerance of the filter. A higher value will eliminate more points.
Defaults to 0.02.
"""
pyoArgsAssert(self, "SN", filename, tolerance)
_path, _name = os.path.split(filename)
# files = sorted([f for f in os.listdir(_path) if _name+"_" in f])
# if _name not in files: files.append(_name)
files = [filename]
for i, obj in enumerate(self._base_objs):
p = os.path.join(_path, wrap(files,i))
f = open(p, "r")
values = [(float(l.split()[0]), float(l.split()[1])) for l in f.readlines()]
scl = self._size / values[-1][0]
values = [(int(v[0]*scl), v[1]) for v in values]
f.close()
values = reducePoints(values, tolerance=tolerance)
self._list = values
obj.replace(values)
self.refreshView()
def getPoints(self):
"""
Returns list of points of the current table.
"""
return self._base_objs[0].getPoints()
def graph(self, yrange=(0.0, 1.0), title=None, wxnoserver=False):
"""
Opens a grapher window to control the shape of the envelope.
When editing the grapher with the mouse, the new set of points
will be send to the object on mouse up.
Ctrl+C with focus on the grapher will copy the list of points to the
clipboard, giving an easy way to insert the new shape in a script.
:Args:
yrange: tuple, optional
Set the min and max values of the Y axis of the graph.
Defaults to (0.0, 1.0).
title: string, optional
Title of the window. If none is provided, the name of the
class is used.
wxnoserver: boolean, optional
With wxPython graphical toolkit, if True, tells the
interpreter that there will be no server window.
If `wxnoserver` is set to True, the interpreter will not wait for
the server GUI before showing the controller window.
"""
createGraphWindow(self, 4, self._size, yrange, title, wxnoserver)
@property
def list(self):
"""list. List of tuples indicating location and value of each points in the table."""
return self.getPoints()
@list.setter
def list(self, x): self.replace(x)
class CosLogTable(PyoTableObject):
"""
Construct a table from logarithmic-cosine segments in breakpoint fashion.
:Parent: :py:class:`PyoTableObject`
:Args:
list: list, optional
List of tuples indicating location and value of each points
in the table. The default, [(0,0.), (8191, 1.)], creates a
logarithmic line from 0.0 at location 0 to 1.0 at the end of
the table (size - 1). Location must be an integer.
size: int, optional
Table size in samples. Defaults to 8192.
.. note::
Locations in the list must be in increasing order. If the last value
is less than size, the rest of the table will be filled with zeros.
Values must be greater than 0.0.
>>> s = Server().boot()
>>> s.start()
>>> t = CosLogTable([(0,0), (4095,1), (8192,0)])
>>> a = Osc(table=t, freq=2, mul=.25)
>>> b = SineLoop(freq=[599,600], feedback=0.05, mul=a).out()
"""
def __init__(self, list=[(0, 0.), (8191, 1.)], size=8192):
pyoArgsAssert(self, "lI", list, size)
PyoTableObject.__init__(self, size)
if size < list[-1][0]:
print("CosLogTable warning: size smaller than last point position.")
print(" Increased size to last point position + 1")
size = list[-1][0] + 1
self._size = size
self._base_objs = [CosLogTable_base(copy.deepcopy(list), size)]
def replace(self, list):
"""
Draw a new envelope according to the new `list` parameter.
:Args:
list: list
List of tuples indicating location and value of each points
in the table. Location must be integer.
"""
pyoArgsAssert(self, "l", list)
self._list = list
[obj.replace(list) for obj in self._base_objs]
self.refreshView()
def loadRecFile(self, filename, tolerance=0.02):
"""
Import an automation recording file in the table.
loadRecFile takes a recording file, usually from a ControlRec object,
as `filename` parameter, applies a filtering pre-processing to eliminate
redundancies and loads the result in the table as a list of points.
Filtering process can be controled with the `tolerance` parameter.
:Args:
filename: string
Full path of an automation recording file.
tolerance: float, optional
Tolerance of the filter. A higher value will eliminate more points.
Defaults to 0.02.
"""
pyoArgsAssert(self, "SN", filename, tolerance)
_path, _name = os.path.split(filename)
# files = sorted([f for f in os.listdir(_path) if _name+"_" in f])
# if _name not in files: files.append(_name)
files = [filename]
for i, obj in enumerate(self._base_objs):
p = os.path.join(_path, wrap(files,i))
f = open(p, "r")
values = [(float(l.split()[0]), float(l.split()[1])) for l in f.readlines()]
scl = self._size / values[-1][0]
values = [(int(v[0]*scl), v[1]) for v in values]
f.close()
values = reducePoints(values, tolerance=tolerance)
self._list = values
obj.replace(values)
self.refreshView()
def getPoints(self):
"""
Returns list of points of the current table.
"""
return self._base_objs[0].getPoints()
def graph(self, yrange=(0.0, 1.0), title=None, wxnoserver=False):
"""
Opens a grapher window to control the shape of the envelope.
When editing the grapher with the mouse, the new set of points
will be send to the object on mouse up.
Ctrl+C with focus on the grapher will copy the list of points to the
clipboard, giving an easy way to insert the new shape in a script.
:Args:
yrange: tuple, optional
Set the min and max values of the Y axis of the graph.
Defaults to (0.0, 1.0).
title: string, optional
Title of the window. If none is provided, the name of the
class is used.
wxnoserver: boolean, optional
With wxPython graphical toolkit, if True, tells the
interpreter that there will be no server window.
If `wxnoserver` is set to True, the interpreter will not wait for
the server GUI before showing the controller window.
"""
createGraphWindow(self, 5, self._size, yrange, title, wxnoserver)
@property
def list(self):
"""list. List of tuples indicating location and value of each points in the table."""
return self.getPoints()
@list.setter
def list(self, x): self.replace(x)
class CosTable(PyoTableObject):
"""
Construct a table from cosine interpolated segments.
:Parent: :py:class:`PyoTableObject`
:Args:
list: list, optional
List of tuples indicating location and value of each points
in the table. The default, [(0,0.), (8191, 1.)], creates a
cosine line from 0.0 at location 0 to 1.0 at the end of the
table (size - 1). Location must be an integer.
size: int, optional
Table size in samples. Defaults to 8192.
.. note::
Locations in the list must be in increasing order. If the last value
is less than size, the rest of the table will be filled with zeros.
>>> s = Server().boot()
>>> s.start()
>>> # Sharp attack envelope
>>> t = CosTable([(0,0), (100,1), (1000,.25), (8191,0)])
>>> a = Osc(table=t, freq=2, mul=.25)
>>> b = SineLoop(freq=[299,300], feedback=0.05, mul=a).out()
"""
def __init__(self, list=[(0, 0.), (8191, 1.)], size=8192):
pyoArgsAssert(self, "lI", list, size)
PyoTableObject.__init__(self, size)
if size < list[-1][0]:
print("CosTable warning: size smaller than last point position.")
print(" Increased size to last point position + 1")
size = list[-1][0] + 1
self._size = size
self._base_objs = [CosTable_base(copy.deepcopy(list), size)]
def replace(self, list):
"""
Draw a new envelope according to the new `list` parameter.
:Args:
list: list
List of tuples indicating location and value of each points
in the table. Location must be integer.
"""
pyoArgsAssert(self, "l", list)
self._list = list
[obj.replace(list) for obj in self._base_objs]
self.refreshView()
def loadRecFile(self, filename, tolerance=0.02):
"""
Import an automation recording file in the table.
loadRecFile takes a recording file, usually from a ControlRec object,
as `filename` parameter, applies a filtering pre-processing to eliminate
redundancies and loads the result in the table as a list of points.
Filtering process can be controled with the `tolerance` parameter.
:Args:
filename: string
Full path of an automation recording file.
tolerance: float, optional
Tolerance of the filter. A higher value will eliminate more points.
Defaults to 0.02.
"""
pyoArgsAssert(self, "SN", filename, tolerance)
_path, _name = os.path.split(filename)
# files = sorted([f for f in os.listdir(_path) if _name+"_" in f])
# if _name not in files: files.append(_name)
files = [filename]
for i, obj in enumerate(self._base_objs):
p = os.path.join(_path, wrap(files,i))
f = open(p, "r")
values = [(float(l.split()[0]), float(l.split()[1])) for l in f.readlines()]
scl = self._size / values[-1][0]
values = [(int(v[0]*scl), v[1]) for v in values]
f.close()
values = reducePoints(values, tolerance=tolerance)
self._list = values
obj.replace(values)
self.refreshView()
def getPoints(self):
"""
Returns list of points of the current table.
"""
return self._base_objs[0].getPoints()
def graph(self, yrange=(0.0, 1.0), title=None, wxnoserver=False):
"""
Opens a grapher window to control the shape of the envelope.
When editing the grapher with the mouse, the new set of points
will be send to the object on mouse up.
Ctrl+C with focus on the grapher will copy the list of points to the
clipboard, giving an easy way to insert the new shape in a script.
:Args:
yrange: tuple, optional
Set the min and max values of the Y axis of the graph.
Defaults to (0.0, 1.0).
title: string, optional
Title of the window. If none is provided, the name of the
class is used.
wxnoserver: boolean, optional
With wxPython graphical toolkit, if True, tells the
interpreter that there will be no server window.
If `wxnoserver` is set to True, the interpreter will not wait for
the server GUI before showing the controller window.
"""
createGraphWindow(self, 1, self._size, yrange, title, wxnoserver)
@property
def list(self):
"""list. List of tuples indicating location and value of each points in the table."""
return self.getPoints()
@list.setter
def list(self, x): self.replace(x)
class CurveTable(PyoTableObject):
"""
Construct a table from curve interpolated segments.
CurveTable uses Hermite interpolation (sort of cubic interpolation)
to calculate each points of the curve. This algorithm allows tension
and biasing controls. Tension can be used to tighten up the curvature
at the known points. The bias is used to twist the curve about the
known points.
:Parent: :py:class:`PyoTableObject`
:Args:
list: list, optional
List of tuples indicating location and value of each points
in the table. The default, [(0,0.), (8191, 1.)], creates a
curved line from 0.0 at location 0 to 1.0 at the end of the
table (size - 1). Location must be an integer.
tension: float, optional
Curvature at the known points. 1 is high, 0 normal, -1 is low.
Defaults to 0.
bias: float, optional
Curve attraction (for each segments) toward bundary points.
0 is even, positive is towards first point, negative is towards
the second point. Defaults to 0.
size: int, optional
Table size in samples. Defaults to 8192.
.. note::
Locations in the list must be in increasing order. If the last value
is less than size, the rest of the table will be filled with zeros.
High tension or bias values can create unstable or very loud table,
use normalize method to keep the curve between -1 and 1.
>>> s = Server().boot()
>>> s.start()
>>> t = CurveTable([(0,0),(2048,.5),(4096,.2),(6144,.5),(8192,0)], 0, 20)
>>> t.normalize()
>>> a = Osc(table=t, freq=2, mul=.25)
>>> b = SineLoop(freq=[299,300], feedback=0.05, mul=a).out()
"""
def __init__(self, list=[(0, 0.), (8191, 1.)], tension=0, bias=0, size=8192):
pyoArgsAssert(self, "lNNI", list, tension, bias, size)
PyoTableObject.__init__(self, size)
if size < list[-1][0]:
print("CurveTable warning: size smaller than last point position.")
print(" Increased size to last point position + 1")
size = list[-1][0] + 1
self._size = size
self._tension = tension
self._bias = bias
self._base_objs = [CurveTable_base(copy.deepcopy(list), tension, bias, size)]
def setTension(self, x):
"""
Replace the `tension` attribute.
1 is high, 0 normal, -1 is low.
:Args:
x: float
New `tension` attribute.
"""
pyoArgsAssert(self, "N", x)
self._tension = x
[obj.setTension(x) for obj in self._base_objs]
self.refreshView()
def setBias(self, x):
"""
Replace the `bias` attribute.
0 is even, positive is towards first point, negative is towards
the second point.
:Args:
x: float
New `bias` attribute.
"""
pyoArgsAssert(self, "N", x)
self._bias = x
[obj.setBias(x) for obj in self._base_objs]
self.refreshView()
def replace(self, list):
"""
Draw a new envelope according to the new `list` parameter.
:Args:
list: list
List of tuples indicating location and value of each points
in the table. Location must be integer.
"""
pyoArgsAssert(self, "l", list)
self._list = list
[obj.replace(list) for obj in self._base_objs]
self.refreshView()
def loadRecFile(self, filename, tolerance=0.02):
"""
Import an automation recording file in the table.
loadRecFile takes a recording file, usually from a ControlRec object,
as `filename` parameter, applies a filtering pre-processing to eliminate
redundancies and loads the result in the table as a list of points.
Filtering process can be controled with the `tolerance` parameter.
:Args:
filename: string
Full path of an automation recording file.
tolerance: float, optional
Tolerance of the filter. A higher value will eliminate more points.
Defaults to 0.02.
"""
pyoArgsAssert(self, "SN", filename, tolerance)
_path, _name = os.path.split(filename)
# files = sorted([f for f in os.listdir(_path) if _name+"_" in f])
# if _name not in files: files.append(_name)
files = [filename]
for i, obj in enumerate(self._base_objs):
p = os.path.join(_path, wrap(files,i))
f = open(p, "r")
values = [(float(l.split()[0]), float(l.split()[1])) for l in f.readlines()]
scl = self._size / values[-1][0]
values = [(int(v[0]*scl), v[1]) for v in values]
f.close()
values = reducePoints(values, tolerance=tolerance)
self._list = values
obj.replace(values)
self.refreshView()
def getPoints(self):
"""
Returns list of points of the current table.
"""
return self._base_objs[0].getPoints()
def graph(self, yrange=(0.0, 1.0), title=None, wxnoserver=False):
"""
Opens a grapher window to control the shape of the envelope.
When editing the grapher with the mouse, the new set of points
will be send to the object on mouse up.
Ctrl+C with focus on the grapher will copy the list of points to the
clipboard, giving an easy way to insert the new shape in a script.
:Args:
yrange: tuple, optional
Set the min and max values of the Y axis of the graph.
Defaults to (0.0, 1.0).
title: string, optional
Title of the window. If none is provided, the name of the
class is used.
wxnoserver: boolean, optional
With wxPython graphical toolkit, if True, tells the
interpreter that there will be no server window.
If `wxnoserver` is set to True, the interpreter will not wait for
the server GUI before showing the controller window.
"""
createGraphWindow(self, 3, self._size, yrange, title, wxnoserver)
@property
def tension(self):
"""float. Curvature tension."""
return self._tension
@tension.setter
def tension(self, x): self.setTension(x)
@property
def bias(self):
"""float. Curve Attraction."""
return self._bias
@bias.setter
def bias(self, x): self.setBias(x)
@property
def list(self):
"""list. List of tuples indicating location and value of each points in the table."""
return self.getPoints()
@list.setter
def list(self, x): self.replace(x)
class ExpTable(PyoTableObject):
"""
Construct a table from exponential interpolated segments.
:Parent: :py:class:`PyoTableObject`
:Args:
list: list, optional
List of tuples indicating location and value of each points
in the table. The default, [(0,0.), (8192, 1.)], creates a
exponential line from 0.0 at location 0 to 1.0 at the end of
the table. Location must be an integer.
exp: float, optional
Exponent factor. Used to control the slope of the curve.
Defaults to 10.
inverse: boolean, optional
If True, downward slope will be inversed. Useful to create
biexponential curves. Defaults to True.
size: int, optional
Table size in samples. Defaults to 8192.
.. note::
Locations in the list must be in increasing order. If the last value
is less than size, the rest of the table will be filled with zeros.
>>> s = Server().boot()
>>> s.start()
>>> t = ExpTable([(0,0),(4096,1),(8192,0)], exp=5, inverse=True)
>>> a = Osc(table=t, freq=2, mul=.3)
>>> b = Sine(freq=[299,300], mul=a).out()
"""
def __init__(self, list=[(0, 0.), (8192, 1.)], exp=10, inverse=True, size=8192):
pyoArgsAssert(self, "lNBI", list, exp, inverse, size)
PyoTableObject.__init__(self, size)
if size < list[-1][0]:
print("ExpTable warning: size smaller than last point position.")
print(" Increased size to last point position + 1")
size = list[-1][0] + 1
self._size = size
self._exp = exp
self._inverse = inverse
self._base_objs = [ExpTable_base(copy.deepcopy(list), exp, inverse, size)]
def setExp(self, x):
"""
Replace the `exp` attribute.
:Args:
x: float
New `exp` attribute.
"""
pyoArgsAssert(self, "N", x)
self._exp = x
[obj.setExp(x) for obj in self._base_objs]
self.refreshView()
def setInverse(self, x):
"""
Replace the `inverse` attribute.
:Args:
x: boolean
New `inverse` attribute.
"""
pyoArgsAssert(self, "B", x)
self._inverse = x
[obj.setInverse(x) for obj in self._base_objs]
self.refreshView()
def replace(self, list):
"""
Draw a new envelope according to the new `list` parameter.
:Args:
list: list
List of tuples indicating location and value of each points
in the table. Location must be integer.
"""
pyoArgsAssert(self, "l", list)
self._list = list
[obj.replace(list) for obj in self._base_objs]
self.refreshView()
def loadRecFile(self, filename, tolerance=0.02):
"""
Import an automation recording file in the table.
loadRecFile takes a recording file, usually from a ControlRec object,
as `filename` parameter, applies a filtering pre-processing to eliminate
redundancies and loads the result in the table as a list of points.
Filtering process can be controled with the `tolerance` parameter.
:Args:
filename: string
Full path of an automation recording file.
tolerance: float, optional
Tolerance of the filter. A higher value will eliminate more points.
Defaults to 0.02.
"""
pyoArgsAssert(self, "SN", filename, tolerance)
_path, _name = os.path.split(filename)
# files = sorted([f for f in os.listdir(_path) if _name+"_" in f])
# if _name not in files: files.append(_name)
files = [filename]
for i, obj in enumerate(self._base_objs):
p = os.path.join(_path, wrap(files,i))
f = open(p, "r")
values = [(float(l.split()[0]), float(l.split()[1])) for l in f.readlines()]
scl = self._size / values[-1][0]
values = [(int(v[0]*scl), v[1]) for v in values]
f.close()
values = reducePoints(values, tolerance=tolerance)
self._list = values
obj.replace(values)
self.refreshView()
def getPoints(self):
"""
Returns list of points of the current table.
"""
return self._base_objs[0].getPoints()
def graph(self, yrange=(0.0, 1.0), title=None, wxnoserver=False):
"""
Opens a grapher window to control the shape of the envelope.
When editing the grapher with the mouse, the new set of points
will be send to the object on mouse up.
Ctrl+C with focus on the grapher will copy the list of points to the
clipboard, giving an easy way to insert the new shape in a script.
:Args:
yrange: tuple, optional
Set the min and max values of the Y axis of the graph.
Defaults to (0.0, 1.0).
title: string, optional
Title of the window. If none is provided, the name of the
class is used.
wxnoserver: boolean, optional
With wxPython graphical toolkit, if True, tells the
interpreter that there will be no server window.
If `wxnoserver` is set to True, the interpreter will not wait for
the server GUI before showing the controller window.
"""
createGraphWindow(self, 2, self._size, yrange, title, wxnoserver)
@property
def exp(self):
"""float. Exponent factor."""
return self._exp
@exp.setter
def exp(self, x): self.setExp(x)
@property
def inverse(self):
"""boolean. Inverse factor."""
return self._inverse
@inverse.setter
def inverse(self, x): self.setInverse(x)
@property
def list(self):
"""list. List of tuples indicating location and value of each points in the table."""
return self.getPoints()
@list.setter
def list(self, x): self.replace(x)
class SndTable(PyoTableObject):
"""
Transfers data from a soundfile into a function table.
If `chnl` is None, the table will contain as many table streams as
necessary to read all channels of the loaded sound.
:Parent: :py:class:`PyoTableObject`
:Args:
path: string, optional
Full path name of the sound. The defaults, None, creates an empty
table.
chnl: int, optional
Channel number to read in. The count starts at 0 (first channel is
is 0, second is 1 and so on). Available at initialization time only.
The default (None) reads all channels.
start: float, optional
Begins reading at `start` seconds into the file. Available at
initialization time only. Defaults to 0.
stop: float, optional
Stops reading at `stop` seconds into the file. Available at
initialization time only. The default (None) means the end of
the file.
>>> s = Server().boot()
>>> s.start()
>>> snd_path = SNDS_PATH + '/transparent.aif'
>>> t = SndTable(snd_path)
>>> freq = t.getRate()
>>> a = Osc(table=t, freq=[freq, freq*.995], mul=.3).out()
"""
def __init__(self, path=None, chnl=None, start=0, stop=None, initchnls=1):
PyoTableObject.__init__(self)
self._path = path
self._chnl = chnl
self._start = start
self._stop = stop
self._size = []
self._dur = []
self._base_objs = []
path, lmax = convertArgsToLists(path)
if self._path is None:
self._base_objs = [SndTable_base("", 0, 0) for i in range(initchnls)]
else:
for p in path:
_size, _dur, _snd_sr, _snd_chnls, _format, _type = sndinfo(p)
if chnl is None:
if stop is None:
self._base_objs.extend([SndTable_base(stringencode(p), i, start) for i in range(_snd_chnls)])
else:
self._base_objs.extend([SndTable_base(stringencode(p), i, start, stop) for i in range(_snd_chnls)])
else:
if stop is None:
self._base_objs.append(SndTable_base(stringencode(p), chnl, start))
else:
self._base_objs.append(SndTable_base(stringencode(p), chnl, start, stop))
self._size.append(self._base_objs[-1].getSize())
self._dur.append(self._size[-1] / float(_snd_sr))
if lmax == 1:
self._size = self._base_objs[-1].getSize()
self._dur = self._size / float(_snd_sr)
def setSound(self, path, start=0, stop=None):
"""
Load a new sound in the table.
Keeps the number of channels of the sound loaded at initialization.
If the new sound has less channels, it will wrap around and load
the same channels many times. If the new sound has more channels,
the extra channels will be skipped.
:Args:
path: string
Full path of the new sound.
start: float, optional
Begins reading at `start` seconds into the file. Defaults to 0.
stop: float, optional
Stops reading at `stop` seconds into the file. The default (None)
means the end of the file.
"""
self._path = path
if type(path) == list:
self._size = []
self._dur = []
path, lmax = convertArgsToLists(path)
for i, obj in enumerate(self._base_objs):
p = path[i%lmax]
_size, _dur, _snd_sr, _snd_chnls, _format, _type = sndinfo(p)
self._size.append(_size)
self._dur.append(_dur)
if stop is None:
obj.setSound(stringencode(p), 0, start)
else:
obj.setSound(stringencode(p), 0, start, stop)
else:
_size, _dur, _snd_sr, _snd_chnls, _format, _type = sndinfo(path)
self._size = _size
self._dur = _dur
if stop is None:
[obj.setSound(stringencode(path), (i%_snd_chnls), start) for i, obj in enumerate(self._base_objs)]
else:
[obj.setSound(stringencode(path), (i%_snd_chnls), start, stop) for i, obj in enumerate(self._base_objs)]
self.refreshView()
self._resetView()
def append(self, path, crossfade=0, start=0, stop=None):
"""
Append a sound to the one already in the table with crossfade.
Keeps the number of channels of the sound loaded at initialization.
If the new sound has less channels, it will wrap around and load
the same channels many times. If the new sound has more channels,
the extra channels will be skipped.
:Args:
path: string
Full path of the new sound.
crossfade: float, optional
Crossfade time, in seconds, between the sound already in the table
and the new one. Defaults to 0.
start: float, optional
Begins reading at `start` seconds into the file. Defaults to 0.
stop: float, optional
Stops reading at `stop` seconds into the file. The default, None,
means the end of the file.
"""
if type(path) == list:
self._size = []
self._dur = []
path, lmax = convertArgsToLists(path)
for i, obj in enumerate(self._base_objs):
p = path[i%lmax]
_size, _dur, _snd_sr, _snd_chnls, _format, _type = sndinfo(p)
self._size.append(_size)
self._dur.append(_dur)
if stop is None:
obj.append(stringencode(p), crossfade, 0, start)
else:
obj.append(stringencode(p), crossfade, 0, start, stop)
else:
_size, _dur, _snd_sr, _snd_chnls, _format, _type = sndinfo(path)
self._size = _size
self._dur = _dur
if stop is None:
[obj.append(stringencode(path), crossfade, (i%_snd_chnls), start) for i, obj in enumerate(self._base_objs)]
else:
[obj.append(stringencode(path), crossfade, (i%_snd_chnls), start, stop) for i, obj in enumerate(self._base_objs)]
self.refreshView()
def insert(self, path, pos=0, crossfade=0, start=0, stop=None):
"""
Insert a sound into the one already in the table with crossfade.
Insert a sound at position `pos`, specified in seconds,
with crossfading at the beginning and the end of the insertion.
Keeps the number of channels of the sound loaded at initialization.
If the new sound has less channels, it will wrap around and load
the same channels many times. If the new sound has more channels,
the extra channels will be skipped.
:Args:
path: string
Full path of the new sound.
pos: float, optional
Position in the table, in seconds, where to insert the new sound.
Defaults to 0.
crossfade: float, optional
Crossfade time, in seconds, between the sound already in the table
and the new one. Defaults to 0.
start: float, optional
Begins reading at `start` seconds into the file. Defaults to 0.
stop: float, optional
Stops reading at `stop` seconds into the file. The default, None,
means the end of the file.
"""
if type(path) == list:
self._size = []
self._dur = []
path, lmax = convertArgsToLists(path)
for i, obj in enumerate(self._base_objs):
p = path[i%lmax]
_size, _dur, _snd_sr, _snd_chnls, _format, _type = sndinfo(p)
self._size.append(_size)
self._dur.append(_dur)
if stop is None:
obj.insert(stringencode(p), pos, crossfade, 0, start)
else:
obj.insert(stringencode(p), pos, crossfade, 0, start, stop)
else:
_size, _dur, _snd_sr, _snd_chnls, _format, _type = sndinfo(path)
self._size = _size
self._dur = _dur
if stop is None:
[obj.insert(stringencode(path), pos, crossfade, (i%_snd_chnls), start) for i, obj in enumerate(self._base_objs)]
else:
[obj.insert(stringencode(path), pos, crossfade, (i%_snd_chnls), start, stop) for i, obj in enumerate(self._base_objs)]
self.refreshView()
def getRate(self, all=True):
"""
Return the frequency in cps at which the sound will be read at its
original pitch.
:Args:
all: boolean
If the table contains more than one sound and `all` is True,
returns a list of all durations. Otherwise, returns only the
first duration as a float.
"""
if type(self._path) == list:
_rate = [obj.getRate() for obj in self._base_objs]
else:
_rate = self._base_objs[0].getRate()
if all:
return _rate
else:
if type(_rate) == list:
return _rate[0]
else:
return _rate
def getDur(self, all=True):
"""
Return the duration of the sound in seconds.
:Args:
all: boolean
If the table contains more than one sound and `all` is True,
returns a list of all durations. Otherwise, returns only the
first duration as a float.
"""
if type(self._path) == list:
_dur = [1./obj.getRate() for obj in self._base_objs]
else:
_dur = 1./self._base_objs[0].getRate()
if all:
return _dur
else:
if type(_dur) == list:
return _dur[0]
else:
return _dur
def setSize(self, x):
print("SndTable has no setSize method!")
def getSize(self, all=True):
"""
Return the size of the table in samples.
:Args:
all: boolean
If the table contains more than one sound and `all` is True,
returns a list of all sizes. Otherwise, returns only the
first size as an int.
"""
if len(self._base_objs) > 1:
_size = [obj.getSize() for obj in self._base_objs]
else:
_size = self._base_objs[0].getSize()
if all:
return _size
else:
if type(_size) == list:
return _size[0]
else:
return _size
def getViewTable(self, size, begin=0, end=0):
"""
Return a list of points (in X, Y pixel values) for each channel in the table.
These lists can be draw on a DC (WxPython) with a DrawLines method.
:Args:
size: tuple
Size, (X, Y) pixel values, of the waveform container window.
begin: float, optional
First position in the the table, in seconds, where to get samples.
Defaults to 0.
end: float, optional
Last position in the table, in seconds, where to get samples.
if this value is set to 0, that means the end of the table. Defaults to 0.
"""
w, h = size
chnls = len(self._base_objs)
img = []
imgHeight = h // chnls
for i in range(chnls):
off = h // chnls * i
img.append(self._base_objs[i].getViewTable((w, imgHeight), begin, end, off))
return img
def getEnvelope(self, points):
"""
Return the amplitude envelope of the table.
Return a list, of length `chnl`, of lists of length `points` filled
with the amplitude envelope of the table.
:Args:
points: int
Number of points of the amplitude analysis.
"""
return [obj.getEnvelope(points) for obj in self._base_objs]
def view(self, title="Sound waveform", wxnoserver=False, mouse_callback=None):
"""
Opens a window showing the contents of the table.
:Args:
title: string, optional
Window title. Defaults to "Table waveform".
wxnoserver: boolean, optional
With wxPython graphical toolkit, if True, tells the
interpreter that there will be no server window.
mouse_callback: callable
If provided, this function will be called with the mouse
position, inside the frame, as argument. Defaults to None.
If `wxnoserver` is set to True, the interpreter will not wait for
the server GUI before showing the controller window.
"""
createSndViewTableWindow(self, title, wxnoserver, self.__class__.__name__, mouse_callback)
def refreshView(self):
if self.viewFrame is not None:
self.viewFrame.update()
def _resetView(self):
if self.viewFrame is not None:
if hasattr(self.viewFrame, "_setZoom"):
self.viewFrame._setZoom()
@property
def sound(self):
"""string. Full path of the sound."""
return self._path
@sound.setter
def sound(self, x): self.setSound(x)
@property
def path(self):
"""string. Full path of the sound."""
return self._path
@path.setter
def path(self, x): self.setSound(x)
@property
def chnl(self):
"""int. Channel to read in."""
return self._chnl
@chnl.setter
def chnl(self, x): print("'chnl' attribute is read-only.")
@property
def start(self):
"""float. Start point, in seconds, to read into the file."""
return self._start
@start.setter
def start(self, x): print("'start' attribute is read-only.")
@property
def stop(self):
"""float. Stop point, in seconds, to read into the file."""
return self._stop
@stop.setter
def stop(self, x): print("SndTable 'stop' attribute is read-only.")
@property
def size(self):
return self._size
@size.setter
def size(self, x): print("SndTable 'size' attribute is read-only.")
class NewTable(PyoTableObject):
"""
Create an empty table ready for recording.
See :py:class:`TableRec` to write samples in the table.
:Parent: :py:class:`PyoTableObject`
:Args:
length: float
Length of the table in seconds.
chnls: int, optional
Number of channels that will be handled by the table.
Defaults to 1.
init: list of floats, optional
Initial table. List of list can match the number of channels,
otherwise, the list will be loaded in all tablestreams.
Defaults to None.
feedback: float, optional
Amount of old data to mix with a new recording. Defaults to 0.0.
.. seealso::
:py:class:`DataTable`, :py:class:`TableRec`
>>> s = Server(duplex=1).boot()
>>> s.start()
>>> t = NewTable(length=2, chnls=1)
>>> a = Input(0)
>>> b = TableRec(a, t, .01)
>>> amp = Iter(b["trig"], [.5])
>>> freq = t.getRate()
>>> c = Osc(table=t, freq=[freq, freq*.99], mul=amp).out()
>>> # to record in the empty table, call:
>>> # b.play()
"""
def __init__(self, length, chnls=1, init=None, feedback=0.0):
pyoArgsAssert(self, "NILN", length, chnls, init, feedback)
PyoTableObject.__init__(self)
self._length = length
self._chnls = chnls
self._init = init
self._feedback = feedback
if init is None:
self._base_objs = [NewTable_base(length, None, feedback) for i in range(chnls)]
else:
if type(init[0]) != list:
init = [init]
self._base_objs = [NewTable_base(length, wrap(init,i), feedback) for i in range(chnls)]
self._size = self._base_objs[0].getSize()
def replace(self, x):
"""
Replaces the actual table.
:Args:
x: list of floats
New table. Must be of the same size as the actual table.
List of list can match the number of channels, otherwise,
the list will be loaded in all tablestreams.
"""
pyoArgsAssert(self, "l", x)
if type(x[0]) != list:
x = [x]
[obj.setTable(wrap(x,i)) for i, obj in enumerate(self._base_objs)]
self.refreshView()
def setFeedback(self, x):
"""
Replaces the`feedback` attribute.
:Args:
x: float
New `feedback` value.
"""
pyoArgsAssert(self, "N", x)
self._feedback = x
[obj.setFeedback(x) for i, obj in enumerate(self._base_objs)]
def getLength(self):
"""
Returns the length of the table in seconds.
"""
return self._base_objs[0].getLength()
def getDur(self, all=True):
"""
Returns the length of the table in seconds.
The `all` argument is there for compatibility with SndTable but
is not used for now.
"""
return self._base_objs[0].getLength()
def getRate(self):
"""
Returns the frequency (cycle per second) to give to an
oscillator to read the sound at its original pitch.
"""
return self._base_objs[0].getRate()
def getViewTable(self, size, begin=0, end=0):
"""
Return a list of points (in X, Y pixel values) for each channel in the table.
These lists can be draw on a DC (WxPython) with a DrawLines method.
:Args:
size: tuple
Size, (X, Y) pixel values, of the waveform container window.
begin: float, optional
First position in the the table, in seconds, where to get samples.
Defaults to 0.
end: float, optional
Last position in the table, in seconds, where to get samples.
if this value is set to 0, that means the end of the table. Defaults to 0.
"""
w, h = size
chnls = len(self._base_objs)
img = []
imgHeight = h // chnls
for i in range(chnls):
off = h // chnls * i
img.append(self._base_objs[i].getViewTable((w, imgHeight), begin, end, off))
return img
def view(self, title="Sound waveform", wxnoserver=False, mouse_callback=None):
"""
Opens a window showing the contents of the table.
:Args:
title: string, optional
Window title. Defaults to "Table waveform".
wxnoserver: boolean, optional
With wxPython graphical toolkit, if True, tells the
interpreter that there will be no server window.
mouse_callback: callable
If provided, this function will be called with the mouse
position, inside the frame, as argument. Defaults to None.
If `wxnoserver` is set to True, the interpreter will not wait for
the server GUI before showing the controller window.
"""
createSndViewTableWindow(self, title, wxnoserver, self.__class__.__name__, mouse_callback)
def refreshView(self):
if self.viewFrame is not None:
self.viewFrame.update()
@property
def length(self):
"""float. Length of the table in seconds."""
return self._length
@length.setter
def length(self, x): print("'length' attribute is read-only.")
@property
def chnls(self):
"""int. Number of channels that will be handled by the table."""
return self._chnls
@chnls.setter
def chnls(self, x): print("'chnls' attribute is read-only.")
@property
def init(self):
"""list of floats. Initial table."""
return self._init
@init.setter
def init(self, x): print("'init' attribute is read-only.")
@property
def feedback(self):
"""float. Amount of old data to mix with a new recording."""
return self._feedback
@feedback.setter
def feedback(self, x): self.setFeedback(x)
@property
def size(self):
return self._size
@size.setter
def size(self, x): print("NewTable 'size' attribute is read-only.")
class DataTable(PyoTableObject):
"""
Create an empty table ready for data recording.
See :py:class:`TableRec` to write samples in the table.
:Parent: :py:class:`PyoTableObject`
:Args:
size: int
Size of the table in samples.
chnls: int, optional
Number of channels that will be handled by the table.
Defaults to 1.
init: list of floats, optional
Initial table. List of list can match the number of channels,
otherwise, the list will be loaded in all tablestreams.
.. seealso::
:py:class:`NewTable`, :py:class:`TableRec`
>>> s = Server().boot()
>>> s.start()
>>> import random
>>> notes = [midiToHz(random.randint(48,72)) for i in range(10)]
>>> tab = DataTable(size=10, init=notes)
>>> ind = RandInt(10, 8)
>>> pit = TableIndex(tab, ind)
>>> a = SineLoop(freq=[pit,pit*0.99], feedback = 0.07, mul=.2).out()
"""
def __init__(self, size, chnls=1, init=None):
pyoArgsAssert(self, "IIL", size, chnls, init)
PyoTableObject.__init__(self, size)
self._chnls = chnls
self._init = init
if init is None:
self._base_objs = [DataTable_base(size) for i in range(chnls)]
else:
if type(init[0]) != list:
init = [init]
self._base_objs = [DataTable_base(size, wrap(init,i)) for i in range(chnls)]
def replace(self, x):
"""
Replaces the actual table.
:Args:
x: list of floats
New table. Must be of the same size as the actual table.
List of list can match the number of channels, otherwise,
the list will be loaded in all tablestreams.
"""
pyoArgsAssert(self, "l", x)
if type(x[0]) != list:
x = [x]
[obj.setTable(wrap(x,i)) for i, obj in enumerate(self._base_objs)]
self.refreshView()
def getRate(self):
"""
Returns the frequency (cycle per second) to give to an
oscillator to read the sound at its original pitch.
"""
return self._base_objs[0].getRate()
def _get_current_data(self):
# internal that returns the data to draw in a DataTableGrapher.
return self.getTable()
def graph(self, yrange=(0.0, 1.0), title=None, wxnoserver=False):
"""
Opens a multislider window to control the data values.
When editing the grapher with the mouse, the new values are
sent to the object to replace the table content.
:Args:
yrange: tuple, optional
Set the min and max values of the Y axis of the multislider.
Defaults to (0.0, 1.0).
title: string, optional
Title of the window. If none is provided, the name of the
class is used.
wxnoserver: boolean, optional
With wxPython graphical toolkit, if True, tells the
interpreter that there will be no server window.
If `wxnoserver` is set to True, the interpreter will not wait for
the server GUI before showing the controller window.
"""
createDataGraphWindow(self, yrange, title, wxnoserver)
@property
def size(self):
"""int. Length of the table in samples."""
return self._size
@size.setter
def size(self, x): print("DataTable 'size' attribute is read-only.")
@property
def chnls(self):
"""int. Number of channels that will be handled by the table."""
return self._chnls
@chnls.setter
def chnls(self, x): print("'chnls' attribute is read-only.")
@property
def init(self):
"""list of floats. Initial table."""
return self._init
@init.setter
def init(self, x): print("'init' attribute is read-only.")
class AtanTable(PyoTableObject):
"""
Generates an arctangent transfert function.
This table allow the creation the classic arctangent transfert functions,
useful in distortion design. See Lookup object for a simple table lookup
process.
:Parent: :py:class:`PyoTableObject`
:Args:
slope: float, optional
Slope of the arctangent function, between 0 and 1. Defaults to 0.5.
size: int, optional
Table size in samples. Defaults to 8192.
>>> import math
>>> s = Server().boot()
>>> s.start()
>>> t = AtanTable(slope=0.8)
>>> a = Sine(freq=[149,150])
>>> l = Lookup(table=t, index=a, mul=0.3).out()
"""
def __init__(self, slope=0.5, size=8192):
pyoArgsAssert(self, "NI", slope, size)
PyoTableObject.__init__(self, size)
self._slope = slope
self._base_objs = [AtanTable_base(slope, size)]
def setSlope(self, x):
"""
Change the slope of the arctangent function. This will redraw the table.
:Args:
x: float
New slope between 0 and 1.
"""
pyoArgsAssert(self, "N", x)
self._slope = x
[obj.setSlope(x) for obj in self._base_objs]
self.refreshView()
@property
def slope(self):
"""float. slope of the arctangent function."""
return self._slope
@slope.setter
def slope(self, x): self.setSlope(x)
class PartialTable(PyoTableObject):
"""
Inharmonic waveform generator.
Generates waveforms made of inharmonic components. Partials are
given as a list of 2-values tuple, where the first one is the
partial number (can be float) and the second one is the strength
of the partial.
The object uses the first two decimal values of each partial to
compute a higher harmonic at a multiple of 100 (so each component
is in reality truly harmonic). If the oscillator has a frequency
divided by 100, the real desired partials will be restituted.
The list:
[(1, 1), (1.1, 0.7), (1.15, 0.5)] will draw a table with:
harmonic 100: amplitude = 1
harmonic 110: amplitude = 0.7
harmonic 115: amplitude = 0.5
To listen to a signal composed of 200, 220 and 230 Hz, one should
declared an oscillator like this (frequency of 200Hz divided by 100):
a = Osc(t, freq=2, mul=0.5).out()
:Parent: :py:class:`PyoTableObject`
:Args:
list: list of tuple, optional
List of 2-values tuples. First value is the partial number (float up
to two decimal values) and second value is its amplitude (relative to
the other harmonics). Defaults to [(1,1), (1.33,0.5),(1.67,0.3)].
size: int, optional
Table size in samples. Because computed harmonics are very high in
frequency, the table size must be bigger than a classic HarmTable.
Defaults to 65536.
>>> s = Server().boot()
>>> s.start()
>>> t = PartialTable([(1,1), (2.37, 0.5), (4.55, 0.3)]).normalize()
>>> # Play with fundamentals 199 and 200 Hz
>>> a = Osc(table=t, freq=[1.99,2], mul=.2).out()
"""
def __init__(self, list=[(1,1), (1.33,0.5),(1.67,0.3)], size=65536):
pyoArgsAssert(self, "lI", list, size)
PyoTableObject.__init__(self, size)
self._list = list
self._par_table = HarmTable(self._create_list(), size)
self._base_objs = self._par_table.getBaseObjects()
self.normalize()
def _create_list(self):
# internal method used to compute the harmonics's weight
hrms = [(int(x*100.), y) for x, y in self._list]
l = []
ind = 0
for i in range(10000):
if i == hrms[ind][0]:
l.append(hrms[ind][1])
ind += 1
if ind == len(hrms):
break
else:
l.append(0)
return l
def replace(self, list):
"""
Redraw the waveform according to a new set of harmonics
relative strengths.
:Args:
list: list of tuples
Each tuple contains the partial number, as a float,
and its strength.
"""
pyoArgsAssert(self, "l", list)
self._list = list
[obj.replace(self._create_list()) for obj in self._base_objs]
self.normalize()
self.refreshView()
@property
def list(self):
"""list. List of partial numbers and strength."""
return self._list
@list.setter
def list(self, x): self.replace(x)
class PadSynthTable(PyoTableObject):
"""
Generates wavetable with the PadSynth algorithm from Nasca Octavian Paul.
This object generates a wavetable with the PadSynth algorithm describe here:
http://zynaddsubfx.sourceforge.net/doc/PADsynth/PADsynth.htm
This algorithm generates some large wavetables that can be played at
different speeds to get the desired sound. This algorithm describes
only how these wavetables are generated. The result is a perfectly
looped wavetable.
To get the desired pitch from the table, the playback speed must be
`sr / table size`. This speed can be transposed to obtain different
pitches from a single wavetable.
:Parent: :py:class:`PyoTableObject`
:Args:
basefreq: float, optional
The base frequency of the algorithm in Hz. If the spreading factor
is near 1.0, this frequency is the fundamental of the spectrum.
Defaults to 440.
spread: float, optional
The spreading factor for the harmonics. Each harmonic real frequency
is computed as `basefreq * pow(n, spread)` where `n` is the harmonic
order. Defaults to 1.
bw: float, optional
The bandwidth of the first harmonic in cents. The bandwidth allows
to control the harmonic profile using a gaussian distribution (bell
shape). Defaults to 50.
bwscl: float, optional
The bandswidth scale specifies how much the bandwidth of the
harmonic increase according to its frequency. Defaults to 1.
nharms: int, optional
The number of harmonics in the generated wavetable. Higher
numbers of harmonics take more time to generate the wavetable.
Defaults to 64.
damp: float, optional
The amplitude damping factor specifies how much the amplitude
of the harmonic decrease according to its order. It uses a
simple power serie, `amp = pow(damp, n)` where `n` is the
harmonic order. Defaults to 0.7.
size: int, optional
Table size in samples. Must be a power-of-two, usually a big one!
Defaults to 262144.
.. note::
Many thanks to Nasca Octavian Paul for making this beautiful algorithm
and releasing it under Public Domain.
>>> s = Server().boot()
>>> s.start()
>>> f = s.getSamplingRate() / 262144
>>> t = PadSynthTable(basefreq=midiToHz(48), spread=1.205, bw=10, bwscl=1.5)
>>> a = Osc(table=t, freq=f, phase=[0, 0.5], mul=0.5).out()
"""
def __init__(self, basefreq=440, spread=1, bw=50, bwscl=1, nharms=64, damp=0.7, size=262144):
pyoArgsAssert(self, "NNNNINI", basefreq, spread, bw, bwscl, nharms, damp, size)
PyoTableObject.__init__(self, size)
self._basefreq = basefreq
self._spread = spread
self._bw = bw
self._bwscl = bwscl
self._nharms = nharms
self._damp = damp
self._base_objs = [PadSynthTable_base(basefreq, spread, bw, bwscl, nharms, damp, size)]
def setBaseFreq(self, x, generate=True):
"""
Change the base frequency of the algorithm.
:Args:
x: float
New base frequency in Hz.
generate: boolean, optional
If True, a new table will be computed with changed value.
"""
pyoArgsAssert(self, "NB", x, generate)
self._basefreq = x
[obj.setBaseFreq(x, generate) for obj in self._base_objs]
if generate:
self.refreshView()
def setSpread(self, x, generate=True):
"""
Change the frequency spreading factor of the algorithm.
:Args:
x: float
New spread factor.
generate: boolean, optional
If True, a new table will be computed with changed value.
"""
pyoArgsAssert(self, "NB", x, generate)
self._spread = x
[obj.setSpread(x, generate) for obj in self._base_objs]
if generate:
self.refreshView()
def setBw(self, x, generate=True):
"""
Change the bandwidth of the first harmonic.
:Args:
x: float
New bandwidth in cents.
generate: boolean, optional
If True, a new table will be computed with changed value.
"""
pyoArgsAssert(self, "NB", x, generate)
self._bw = x
[obj.setBw(x, generate) for obj in self._base_objs]
if generate:
self.refreshView()
def setBwScl(self, x, generate=True):
"""
Change the bandwidth scaling factor.
:Args:
x: float
New bandwidth scaling factor.
generate: boolean, optional
If True, a new table will be computed with changed value.
"""
pyoArgsAssert(self, "NB", x, generate)
self._bwscl = x
[obj.setBwScl(x, generate) for obj in self._base_objs]
if generate:
self.refreshView()
def setNharms(self, x, generate=True):
"""
Change the number of harmonics.
:Args:
x: int
New number of harmonics.
generate: boolean, optional
If True, a new table will be computed with changed value.
"""
pyoArgsAssert(self, "IB", x, generate)
self._nharms = x
[obj.setNharms(x, generate) for obj in self._base_objs]
if generate:
self.refreshView()
def setDamp(self, x, generate=True):
"""
Change the amplitude damping factor.
:Args:
x: float
New amplitude damping factor.
generate: boolean, optional
If True, a new table will be computed with changed value.
"""
pyoArgsAssert(self, "NB", x, generate)
self._damp = x
[obj.setDamp(x, generate) for obj in self._base_objs]
if generate:
self.refreshView()
def setSize(self, size, generate=True):
"""
Change the size of the table.
This will erase the previously drawn waveform.
:Args:
size: int
New table size in samples. Must be a power-of-two.
generate: boolean, optional
If True, a new table will be computed with changed value.
"""
pyoArgsAssert(self, "IB", size, generate)
self._size = size
[obj.setSize(size, generate) for obj in self._base_objs]
if generate:
self.refreshView()
@property
def basefreq(self):
"""float. Base frequency in Hz."""
return self._basefreq
@basefreq.setter
def basefreq(self, x): self.setBaseFreq(x)
@property
def spread(self):
"""float. Frequency spreading factor."""
return self._spread
@spread.setter
def spread(self, x): self.setSpread(x)
@property
def bw(self):
"""float. Bandwitdh of the first harmonic in cents."""
return self._bw
@bw.setter
def bw(self, x): self.setBw(x)
@property
def bwscl(self):
"""float. Bandwitdh scaling factor."""
return self._bwscl
@bwscl.setter
def bwscl(self, x): self.setBwScl(x)
@property
def nharms(self):
"""int. Number of harmonics."""
return self._nharms
@nharms.setter
def nharms(self, x): self.setNharms(x)
@property
def damp(self):
"""float. Amplitude damping factor."""
return self._damp
@damp.setter
def damp(self, x): self.setDamp(x)
class SharedTable(PyoTableObject):
"""
Create an inter-process shared memory table.
This table uses the given name to open an internal shared memory
object, used as the data memory of the table. Two or more tables
from different processes, if they use the same name, can read and
write to the same memory space.
.. note::
SharedTable is not implemented yet for Windows (unix only).
:Parent: :py:class:`PyoTableObject`
:Args:
name: string
Unique name in the system shared memory. Two or more tables created
with the same name will shared the same memory space. The name
must conform to the construction rules for a unix pathname (ie.
it must begin with a slash). Available at initialization time only.
create: loolean
If True, an entry will be create in the system shared memory.
If False, the object will use an already created shared memory.
Can't be a list. Available at initialization time only.
size: int
Size of the table in samples. Can't be a list.
Available at initialization time only.
>>> s = Server().boot()
>>> s.start()
>>> # Creating parent table.
>>> table = SharedTable(["/sharedl", "/sharedr"], True, s.getBufferSize())
>>> # Creating child table.
>>> shared = SharedTable(["/sharedl", "/sharedr"], False, s.getBufferSize())
>>> # Read and output the content of the parent table.
>>> tabread = TableRead(table, table.getRate(), True).out()
>>> # Record some signal signal in the child table.
>>> lfo = Sine(freq=[0.2, 0.25]).range(98, 102)
>>> wave = LFO(freq=lfo, type=4, sharp=0.7, mul=0.3)
>>> pos = Phasor(shared.getRate())
>>> record = TableWrite(wave, pos, shared)
"""
def __init__(self, name, create, size):
if sys.platform == "win32":
raise Exception("SharedTable is not implemented yet for Windows.")
pyoArgsAssert(self, "sBI", name, create, size)
PyoTableObject.__init__(self, size)
self._name = name
self._create = create
name, lmax = convertArgsToLists(name)
self._base_objs = [SharedTable_base(wrap(name,i), create, size) for i in range(lmax)]
def getRate(self):
"""
Returns the frequency (cycle per second) to give to an
oscillator to read the sound at its original pitch.
"""
return self._base_objs[0].getRate()
@property
def size(self):
"""int. Length of the table in samples."""
return self._size
@size.setter
def size(self, x): print("SharedTable 'size' attribute is read-only.")
|