Debian Codegraph @

pyo/examples/x22-events/11-filters.py

raw symbols SCIP
1 """
2 11-filters.py - Modifying generator's output with filters.
3
4 The EventGenerator class contains many methods that can be used to filter
5 the sequence of output values in order to get the desired results. These
6 filters return an EventFilter object, which is also a child of EventGenerator,
7 that perform the operation.
8
9 Available filter methods are:
10
11 - floor:
12 Return an EventFilter computing the largest integer less than or
13 equal to its input value.
14 - ceil:
15 Return an EventFilter computing the smallest integer greater than
16 or equal to its input value.
17 - round:
18 Return an EventFilter computing the nearest integer to its input value.
19 - snap:
20 Return an EventFilter which choose the nearest value of its input
21 value in a list of choices.
22 - deviate:
23 Return an EventFilter which randomly move, up or down, its input value.
24 - clip:
25 Return an EventFilter which clips its input value between predefined
26 limits.
27 - scale:
28 Return an EventFilter which maps its input value, in the range 0 to 1,
29 to an output range, with a scaling curve.
30 - rescale:
31 Return an EventFilter which maps its input value, given in an input
32 range, to an output range with a scaling curve.
33 - iftrue:
34 Return an EventFilter which compares its input value to a comparison
35 value and outputs it if the comparison is True.
36
37 """
38
39 from random import weibullvariate
40 from pyo import *
41
42 s = Server().boot()
43
44 scl = EventScale(root="C", scale="wholeTone", first=4, octaves=3)
45
46 # Takes a Weibull distribution, scales the values between 48 and 84, rounds
47 # them to the nearest integer, then snaps to the nearest value in the given
48 # scale and uses the result as midi note if it's below 84.
49 e = Events(
50 midinote=EventCall(weibullvariate, 0.5, 0.5).scale(48, 84, 1).round().snap(scl).iftrue("<", 84),
51 beat=1 / 4.0,
52 db=-6,
53 attack=0.001,
54 decay=0.05,
55 sustain=0.5,
56 release=0.005,
57 ).play()
58
59 # Rescale values from a pink noise to the range 48 to 72 and snap to the given scale.
60 e2 = Events(
61 midinote=EventNoise(type=1).rescale(-1, 1, 48, 72, 1).snap(scl),
62 beat=1 / 4.0,
63 db=-6,
64 transpo=12,
65 attack=0.001,
66 decay=0.05,
67 sustain=0.5,
68 release=0.005,
69 ).play()
70
71 s.gui(locals())