Debian Codegraph @

pyo/examples/x22-events/06-randoms.py

raw symbols SCIP
1 """
2 06-randoms.py - Exploring random generators.
3
4 This example presents two more generators that randomly choose values.
5
6 **EventChoice** ::
7
8 EventChoice(values, occurrences=inf, stopEventsWhenDone=True)
9
10 EventChoice randomly pick a new value in a list of possible values.
11
12 **EventDrunk** ::
13
14 EventDrunk(values, maxStep=2, occurrences=inf, stopEventsWhenDone=True)
15
16 EventDrunk performs a random walk over a list of values. The 'maxStep'
17 argument determine the larger step in the list the walk can do between
18 two successive events. A negative 'maxStep' is the same but repetition
19 are not allowed.
20
21 """
22
23 from pyo import *
24
25 s = Server().boot()
26
27 scl = [5.00, 5.02, 5.03, 5.05, 5.07, 5.08, 5.10, 6.00, 6.02, 6.03, 6.05, 6.07]
28
29 # Random walk for the melody.
30 e1 = Events(
31 degree=EventDrunk(scl, maxStep=-2), beat=1 / 4.0, db=-6, attack=0.001, decay=0.05, sustain=0.5, release=0.005,
32 ).play()
33
34 # Choose randomly for the bass.
35 e2 = Events(
36 degree=EventChoice(scl), beat=1, db=-6, transpo=-12, attack=0.001, decay=0.05, sustain=0.5, release=0.005,
37 ).play()
38
39 s.gui(locals())