File: external-template.py

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 (116 lines) | stat: -rw-r--r-- 3,865 bytes parent folder | download | duplicates (3)
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
# minimal imports.
# _core contains PyoObject, Mix, Dummy and some utility functions.
# _maps contains all SLMap objects used to set up slider controls.
from pyo.lib._core import *
from pyo.lib._maps import *

# Objects generating vectors of samples must inherit from PyoObject.
# Always provide a __doc__ string with the syntax below.
class Gain(PyoObject):
    """
    Adjusts the gain of an input signal according to a value in decibels.
 
    Parentclass: PyoObject
   
    Parameters:
    
    input : PyoObject
        Input signal to process.
    db : float or PyoObject, optional
        Gain in decibels, 0 is nominal.
        Defaults to -3.

    Methods:

    setInput(x, fadetime) : Replace the `input` attribute.
    setDB(x) : Replace the `db` attribute.

    Attributes:

    input : PyoObject. Input signal to process.
    db : float or PyoObject. Gain in decibels.
    
    Examples:
    
    >>> s = Server().boot()
    >>> s.start()
    >>> a = SineLoop([249,250], feedback=0.07)
    >>> lfo = Sine(1, mul=30, add=-40)
    >>> b = Gain(a, db=lfo).out()

    """

    # Do not forget "mul" and "add" attributes.
    def __init__(self, input, db=-3, mul=1, add=0):
        PyoObject.__init__(self, mul, add)
        # Keep trace of arguments (same name preceded by an underscore)
        self._input = input
        self._db = db
        # Always use InputFader for the input sound. That allows crossfade on input changes.
        self._in_fader = InputFader(input)
        # Converts every arguments to lists (for multi-channel expansion).
        in_fader, db, mul, add, lmax = convertArgsToLists(self._in_fader, db, mul, add)
        # self._base_objs contains the list of XXX_base objects. Use "wrap" function to prevent "out of range" errors.
        self._base_objs = [Gain_base(wrap(in_fader, i), wrap(db, i), wrap(mul, i), wrap(add, i)) for i in range(lmax)]

    # # setInput uses the "setInput" method of InputFader to set the crossfade time.
    def setInput(self, x, fadetime=0.05):
        """
        Replace the `input` attribute.
        
        Parameters:

        x : PyoObject
            New signal to process.
        fadetime : float, optional
            Crossfade time between old and new input. Default to 0.05.

        """
        # No need to convert argument to list because InputFader will do it.
        self._input = x
        self._in_fader.setInput(x, fadetime)

    # Every attribute must have its setXXX method.
    def setDB(self, x):
        """
        Replace the `db` attribute.
        
        Parameters:

        x : float or PyoObject
            New `db` attribute.

        """
        # Keep trace of the new value and convert argument to
        # list before the assignment to XXX_base objects.
        self._db = x
        x, lmax = convertArgsToLists(x)
        [obj.setDB(wrap(x, i)) for i, obj in enumerate(self._base_objs)]

    # ctrl method shows to slider window of the object.
    # Look the man page of SLMap for the object's configuration.
    # self._map_list is the default list of SLMap objects.
    # This method must be defined only if the object uses slider controls.
    def ctrl(self, map_list=None, title=None, wxnoserver=False):
        self._map_list = [SLMap(-120, 18, "lin", "db", self._db), SLMapMul(self._mul)]
        PyoObject.ctrl(self, map_list, title, wxnoserver)

    # setter and getter properties. Each modifiable attribute returns its internal
    # state (self._attr) and must be linked with its setXXX method.
    @property
    def input(self):
        """PyoObject. Input signal to process."""
        return self._input

    @input.setter
    def input(self, x):
        self.setInput(x)

    @property
    def db(self):
        """float or PyoObject. Gain in decibels."""
        return self._db

    @db.setter
    def db(self, x):
        self.setDB(x)