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