File: 05-breakpoints-functions.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 (55 lines) | stat: -rw-r--r-- 1,515 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
"""
05-breakpoints-functions.py - Multi-segments envelopes.

Linseg and Expseg objects draw a series of line segments between 
specified break-points, either linear or exponential.

These objects wait for play() call to start reading the envelope.

They have methods to set loop mode, call pause/play without reset,
and replace the breakpoints.

One can use the graph() method to open a graphical display of the current 
envelope, edit it, and copy the points (in the list format) to the 
clipboard (Menu "File" of the graph display => "Copy all Points ..."). 
This makes it easier to explore and paste the result into the python 
script when happy with the envelope!

"""
from pyo import *
import random

s = Server().boot()

# Randomly built 10-points amplitude envelope.
t = 0
points = [(0.0, 0.0), (2.0, 0.0)]
for i in range(8):
    t += random.uniform(0.1, 0.2)
    v = random.uniform(0.1, 0.9)
    points.insert(-1, (t, v))

amp = Expseg(points, exp=3, mul=0.3)
amp.graph(title="Amplitude envelope")

sig = RCOsc(freq=[150, 151], sharp=0.85, mul=amp)

# A simple linear function to vary the amount of frequency shifting.
sft = Linseg([(0.0, 0.0), (0.5, 20.0), (2, 0.0)])
sft.graph(yrange=(0.0, 20.0), title="Frequency shift")

fsg = FreqShift(sig, shift=sft).out()

rev = WGVerb(sig + fsg, feedback=0.9, cutoff=3500, bal=0.3).out()


def playnote():
    "Start the envelopes to play an event."
    amp.play()
    sft.play()


# Periodically call a function.
pat = Pattern(playnote, 2).play()

s.gui(locals())