Debian Codegraph @

docs/_sources/examples/22-events/09-embedding-generators.rst.txt

raw
1 09-embedding-generators.py - From words to musical phrases.
2 ============================================================================================================================================
3
4
5 If we consider that an EventGenerator is producing a word, then a sequence of
6 EventGenerator can be used to build a sentence or a phrase. When a generators
7 encounters another generator as its value, the inner generator is embedded
8 into the output stream. That is, the inner generator takes over until it runs
9 out of values to return. Then, the control returns to the outer generator.
10 There is no limit to the number of levels of embedding.
11
12 .. code-block:: python
13
14 from pyo import *
15
16 s = Server().boot()
17
18 # Random walk over 3-note melody segments.
19 e = Events(
20 degree=EventDrunk(
21 [
22 EventSeq([5.00, 5.02, 5.03], 1),
23 EventSeq([5.07, 5.05, 5.03], 1),
24 EventSeq([5.07, 5.08, 5.11], 1),
25 EventSeq([6.00, 6.07, 6.03], 1),
26 EventSeq([6.07, 6.05, 6.07], 1),
27 EventSeq([6.07, 6.08, 6.11], 1),
28 EventSeq([7.00, 7.03, 7.02], 1),
29 EventSeq([7.05, 7.08, 7.07], 1),
30 EventSeq([7.08, 7.11, 8.00], 1),
31 EventSeq([8.00, 7.07, 7.03], 1),
32 ],
33 maxStep=EventSeq([2] * 8 + [0] * 4),
34 occurrences=inf,
35 ),
36 beat=1 / 3.0,
37 db=[-6, -12, -12],
38 attack=0.001,
39 decay=0.05,
40 sustain=0.5,
41 release=0.005,
42 ).play()
43
44 # Chord progression: I - II - I - V.
45 e2 = Events(
46 degree=EventSeq(
47 [
48 EventSeq([4.00, 4.03, 4.07], 2),
49 EventSeq([4.02, 4.05, 4.08], 2),
50 EventSeq([4.00, 4.03, 4.07], 2),
51 EventSeq([3.11, 4.02, 4.07], 2),
52 ],
53 occurrences=inf,
54 ),
55 beat=1 / 3.0,
56 db=[-6, -12, -12],
57 attack=0.001,
58 decay=0.05,
59 sustain=0.5,
60 release=0.005,
61 ).play()
62
63 s.gui(locals())
64