File: pyotableobject1.rst.txt

package info (click to toggle)
python-pyo 1.0.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,332 kB
  • sloc: python: 135,133; ansic: 127,822; javascript: 16,116; sh: 395; makefile: 388; cpp: 242
file content (78 lines) | stat: -rw-r--r-- 2,326 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
Creating a custom PyoTableObject - TriangleTable
=================================================================

.. code-block:: python

    from pyo import *

    class TriTable(PyoTableObject):
        """
        Triangle waveform generator.

        Generates triangle waveforms made up of fixed number of harmonics.

        :Parent: :py:class:`PyoTableObject`

        :Args:

            order : int, optional
                Number of harmonics triangle 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 = TriTable(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
            self._tri_table = HarmTable(self._create_list(order), size)
            self._base_objs = self._tri_table.getBaseObjects()

        def _create_list(self, order):
            # internal method used to compute the harmonics's weight
            l = []
            ph = 1.0
            for i in range(1,order*2):
                if i % 2 == 0:
                    l.append(0)
                else:
                    l.append(ph / (i*i))
                    ph *= -1
            return l
        
        def setOrder(self, x):
            """
            Change the `order` attribute and redraw the waveform.
            
            :Args:
            
                x : int
                    New number of harmonics

            """      
            self._order = x
            self._tri_table.replace(self._create_list(x))
            self.normalize()
            self.refreshView()

        @property
        def order(self): 
            """int. Number of harmonics triangular waveform is made of."""
            return self._order
        @order.setter
        def order(self, x): self.setOrder(x)

    # Run the script to test the TriTable object.
    if __name__ == "__main__":
        s = Server().boot()
        t = TriTable(10, 8192)
        t.normalize()
        t.view()
        a = Osc(t, 500, mul=.3).out()
        s.gui(locals())