| 1 |
05-breakpoints-functions.py - Multi-segments envelopes. |
| 2 |
============================================================================================================================================ |
| 3 |
|
| 4 |
|
| 5 |
Linseg and Expseg objects draw a series of line segments between |
| 6 |
specified break-points, either linear or exponential. |
| 7 |
|
| 8 |
These objects wait for play() call to start reading the envelope. |
| 9 |
|
| 10 |
They have methods to set loop mode, call pause/play without reset, |
| 11 |
and replace the breakpoints. |
| 12 |
|
| 13 |
One can use the graph() method to open a graphical display of the current |
| 14 |
envelope, edit it, and copy the points (in the list format) to the |
| 15 |
clipboard (Menu "File" of the graph display => "Copy all Points ..."). |
| 16 |
This makes it easier to explore and paste the result into the python |
| 17 |
script when happy with the envelope! |
| 18 |
|
| 19 |
.. code-block:: python |
| 20 |
|
| 21 |
from pyo import * |
| 22 |
import random |
| 23 |
|
| 24 |
s = Server().boot() |
| 25 |
|
| 26 |
# Randomly built 10-points amplitude envelope. |
| 27 |
t = 0 |
| 28 |
points = [(0.0, 0.0), (2.0, 0.0)] |
| 29 |
for i in range(8): |
| 30 |
t += random.uniform(0.1, 0.2) |
| 31 |
v = random.uniform(0.1, 0.9) |
| 32 |
points.insert(-1, (t, v)) |
| 33 |
|
| 34 |
amp = Expseg(points, exp=3, mul=0.3) |
| 35 |
amp.graph(title="Amplitude envelope") |
| 36 |
|
| 37 |
sig = RCOsc(freq=[150, 151], sharp=0.85, mul=amp) |
| 38 |
|
| 39 |
# A simple linear function to vary the amount of frequency shifting. |
| 40 |
sft = Linseg([(0.0, 0.0), (0.5, 20.0), (2, 0.0)]) |
| 41 |
sft.graph(yrange=(0.0, 20.0), title="Frequency shift") |
| 42 |
|
| 43 |
fsg = FreqShift(sig, shift=sft).out() |
| 44 |
|
| 45 |
rev = WGVerb(sig + fsg, feedback=0.9, cutoff=3500, bal=0.3).out() |
| 46 |
|
| 47 |
|
| 48 |
def playnote(): |
| 49 |
"Start the envelopes to play an event." |
| 50 |
amp.play() |
| 51 |
sft.play() |
| 52 |
|
| 53 |
|
| 54 |
# Periodically call a function. |
| 55 |
pat = Pattern(playnote, 2).play() |
| 56 |
|
| 57 |
s.gui(locals()) |
| 58 |
|