File: 07-moving-points.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 (45 lines) | stat: -rw-r--r-- 1,559 bytes parent folder | download | duplicates (2)
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
07-moving-points.py - Periodically rewrite a break-point function table.
============================================================================================================================================


This example shows how we can dynamically modify a function table to create a
curve that varies over time.

Note: Rewriting a large table can produce xruns in the audio output. Usually,
for this kind of processes, we want to keep the table size relatively small.

.. code-block:: python

    from pyo import *
    
    s = Server().boot()
    
    # Initialize an empty table.
    table = LinTable([(0, 0), (255, 0)], size=256)
    table.view()
    
    # Two LFOs whose values will change the center points in the table.
    lfo1 = Sine(0.1, phase=0.75, mul=0.5, add=0.5)
    lfo2 = Sine(0.15, phase=0.75, mul=0.5, add=0.5)
    
    
    def create_line():
        "Function to create a new line."
        lst = [(0, 0)]  # First point of the table at value 0.
        lst.append((8, lfo1.get()))  # Second point, from first LFO.
        lst.append((128, lfo2.get()))  # Third point, from second LFO.
        lst.append((255, 0))  # Last point of the table at value 0.
    
        # Replace the table content with the new list of points.
        table.replace(lst)
    
    
    # Call the function "create_line" every 50 ms.
    pat = Pattern(function=create_line, time=0.05).play()
    
    # Little test case...
    amp = Osc(table, freq=4, mul=0.4)
    synth = RCOsc(freq=[99.5, 100], sharp=0.3, mul=amp).out()
    
    s.gui(locals())