Debian Codegraph @

pyo/examples/x22-events/12-sharing-values.py

raw symbols SCIP
1 """
2 12-sharing-values.py - Reading and using other parameter's value.
3
4 So far, we've seen events that are independent of each other. They
5 are not aware of the data produced by the others. Making these data
6 available adds musical intelligence to our processes. There is two
7 ways to share values with events. The first one is to read a value
8 produced by the same Events object where we want to use it. The
9 second way is to read the data from a parameter of another Events
10 object.
11
12 In both cases, if the parameter that is read is not yet processed by
13 the Events object, it will first be computed, and stored for further
14 uses, and then shared.
15
16 We use the `EventKey(key, master=None)` to read the value of another
17 parameter.
18
19 """
20
21 from pyo import *
22
23 s = Server().boot()
24
25 scl = EventScale(root="C", scale="major", first=4, octaves=3)
26
27 e = Events(
28 midinote=EventDrunk(scl, maxStep=2),
29 # The higher the pitch, the lower the amplitude.
30 db=EventKey("midinote").rescale(48, 84, -3, -24, 1),
31 beat=1 / 4.0,
32 transpo=12,
33 attack=0.001,
34 decay=0.05,
35 sustain=0.5,
36 release=0.005,
37 ).play()
38
39 e2 = Events( # Define arguments (unused in the instrument) to build phrases.
40 line1=EventSeq([0, 4, 2, 0, 4, 2, 0, 2, 4, 6, 4, 2], occurrences=2, stopEventsWhenDone=False),
41 line2=EventSeq([0, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1], occurrences=2, stopEventsWhenDone=False),
42 # Use previously defined arguments to create a sequence of pitch phrases.
43 midinote=EventIndex(scl, EventSeq([EventKey("line1"), EventKey("line2")])),
44 # Use the db amplitude from the previous Events object (`master` argument).
45 db=EventKey("db", master=e),
46 beat=1 / 4.0,
47 ).play()
48
49 s.gui(locals())