Debian Codegraph @

pyo/examples/x05-envelopes/05-breakpoints-functions.py

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