Debian Codegraph @

docs/_sources/examples/22-events/12-sharing-values.rst.txt

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