This file is indexed.

/usr/share/pyshared/pyolib/tables.py is in python-pyo 0.6.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
"""
Copyright 2010 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 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 General Public License for more details.

You should have received a copy of the GNU 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 types import ListType
from math import pi

######################################################################
### 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):
        PyoTableObject.__init__(self, size)
        self._list = list
        self._base_objs = [HarmTable_base(list, size)]
    
    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.

        """      
        self._list = list
        [obj.replace(list) for obj in self._base_objs]
        self.refreshView()

    @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):
        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

        """      
        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):
        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

        """      
        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):
        PyoTableObject.__init__(self, size)
        self._list = list
        self._base_objs = [ChebyTable_base(list, size)]
    
    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.

        """ 
        self._list = list
        [obj.replace(list) for obj in self._base_objs]
        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()

    @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):
        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):
        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.

        """
        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.

        """
        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):
        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.

        """
        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):
        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):
        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(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.

        """ 
        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.

        """
        _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):
        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(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.

        """ 
        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.

        """
        _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):
        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(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.

        """ 
        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.

        """
        _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):
        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(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.

        """      
        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.

        """
        _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):
        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(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.
        
        """
        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.
        
        """
        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.

        """      
        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.

        """
        _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):
        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(list, exp, inverse, size)]

    def setExp(self, x):
        """
        Replace the `exp` attribute.
        
        :Args:
        
            x : float
                New `exp` attribute.
        
        """
        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.
        
        """
        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.

        """
        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.

        """
        _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. 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 == 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 == None:
                    if stop == None:
                        self._base_objs.extend([SndTable_base(p, i, start) for i in range(_snd_chnls)])
                    else:
                        self._base_objs.extend([SndTable_base(p, i, start, stop) for i in range(_snd_chnls)])
                else:
                    if stop == None:
                        self._base_objs.append(SndTable_base(p, chnl, start))
                    else:
                        self._base_objs.append(SndTable_base(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) == ListType:
            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 == None:
                    obj.setSound(p, 0, start)
                else:
                    obj.setSound(p, 0, start, stop)
        else:
            _size, _dur, _snd_sr, _snd_chnls, _format, _type = sndinfo(path)
            self._size = _size
            self._dur = _dur
            if stop == None:
                [obj.setSound(path, (i%_snd_chnls), start) for i, obj in enumerate(self._base_objs)]
            else:
                [obj.setSound(path, (i%_snd_chnls), start, stop) for i, obj in enumerate(self._base_objs)]
        self.refreshView()

    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) == ListType:
            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 == None:
                    obj.append(p, crossfade, 0, start)
                else:
                    obj.append(p, crossfade, 0, start, stop)
        else:
            _size, _dur, _snd_sr, _snd_chnls, _format, _type = sndinfo(path)
            self._size = _size
            self._dur = _dur
            if stop == None:
                [obj.append(path, crossfade, (i%_snd_chnls), start) for i, obj in enumerate(self._base_objs)]
            else:
                [obj.append(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) == ListType:
            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 == None:
                    obj.insert(p, pos, crossfade, 0, start)
                else:
                    obj.insert(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 == None:
                [obj.insert(path, pos, crossfade, (i%_snd_chnls), start) for i, obj in enumerate(self._base_objs)]
            else:
                [obj.insert(path, pos, crossfade, (i%_snd_chnls), start, stop) for i, obj in enumerate(self._base_objs)]
        self.refreshView()

    def getRate(self):
        """
        Return the frequency in cps at which the sound will be read at its 
        original pitch.
        
        """
        if type(self._path) == ListType:
            return [obj.getRate() for obj in self._base_objs]
        else:
            return self._base_objs[0].getRate()

    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) == ListType:
            _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) == ListType:
                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) == ListType:
                return _size[0]
            else:
                return _size

    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 != None:
            self.viewFrame.update()

    @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):
        PyoTableObject.__init__(self)
        self._length = length
        self._chnls = chnls
        self._init = init
        self._feedback = feedback
        if init == None:
            self._base_objs = [NewTable_base(length, None, feedback) for i in range(chnls)]
        else:
            if type(init[0]) != ListType: 
                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.

        """
        if type(x[0]) != ListType: 
            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.

        """
        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):
        """
        Returns the length of the table in seconds.
        
        """
        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 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 != 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):
        PyoTableObject.__init__(self, size)
        self._chnls = chnls
        self._init = init
        if init == None:
            self._base_objs = [DataTable_base(size) for i in range(chnls)]
        else:
            if type(init[0]) != ListType:
                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.

        """
        if type(x[0]) != ListType: 
            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 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."