Debian Codegraph @

pyo/examples/x22-events/09-embedding-generators.py

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