File: 06-randoms.rst.txt

package info (click to toggle)
python-pyo 1.0.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,332 kB
  • sloc: python: 135,133; ansic: 127,822; javascript: 16,116; sh: 395; makefile: 388; cpp: 242
file content (41 lines) | stat: -rw-r--r-- 1,306 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
06-randoms.py - Exploring random generators.
============================================================================================================================================


This example presents two more generators that randomly choose values.

**EventChoice** ::

    EventChoice(values, occurrences=inf, stopEventsWhenDone=True)

EventChoice randomly pick a new value in a list of possible values.

**EventDrunk** ::

    EventDrunk(values, maxStep=2, occurrences=inf, stopEventsWhenDone=True)

EventDrunk performs a random walk over a list of values. The 'maxStep'
argument determine the larger step in the list the walk can do between
two successive events. A negative 'maxStep' is the same but repetition
are not allowed.

.. code-block:: python

    from pyo import *
    
    s = Server().boot()
    
    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]
    
    # Random walk for the melody.
    e1 = Events(
        degree=EventDrunk(scl, maxStep=-2), beat=1 / 4.0, db=-6, attack=0.001, decay=0.05, sustain=0.5, release=0.005,
    ).play()
    
    # Choose randomly for the bass.
    e2 = Events(
        degree=EventChoice(scl), beat=1, db=-6, transpo=-12, attack=0.001, decay=0.05, sustain=0.5, release=0.005,
    ).play()
    
    s.gui(locals())