Debian Codegraph @

docs/_sources/examples/22-events/08-function-calls.rst.txt

raw
1 08-function-calls.py - Using custom algorithms with python function calls.
2 ============================================================================================================================================
3
4
5 **EventCall** ::
6
7 EventCall(function, *args, occurrences=inf, stopEventsWhenDone=True)
8
9 EventCall calls a function, with any number of arguments (\*args) and uses
10 its return value for the given parameter. The example below use a function
11 from the random module, *randrange*, with arguments and a user-defined
12 function, without argument, to create a rising, then falling, amplitude curve.
13
14 .. code-block:: python
15
16 import random
17 from pyo import *
18
19 s = Server().boot()
20
21 db = -30
22 dir = 1
23
24
25 def riseFallAmp():
26 "Rises and falls amplitude between -30 and -3 dB, 1 db at the time."
27 global db, dir
28 db += dir
29 if db >= -3:
30 dir = -1
31 elif db < -30:
32 dir = 1
33 return db
34
35
36 # Midi notes are chosen randomly with a function from the random module,
37 # while the amplitude change according to the riseFallAmp function's output.
38 e = Events(
39 midinote=EventCall(random.randrange, 48, 72, 3),
40 beat=1 / 4.0,
41 db=EventCall(riseFallAmp),
42 attack=0.001,
43 decay=0.05,
44 sustain=0.5,
45 release=0.005,
46 ).play()
47
48
49 s.gui(locals())
50