| 1 |
Setting audio object parameter's value with portamento |
| 2 |
============================================================================================================================================ |
| 3 |
|
| 4 |
|
| 5 |
**03-set-method.py** |
| 6 |
|
| 7 |
The set() method of the PyoObject lets the user define a new |
| 8 |
value for a given parameter with a portamento time to reach |
| 9 |
the target. Optionally, a function to call at the end of the |
| 10 |
ramp can be given to the `callback` argument. |
| 11 |
|
| 12 |
The signature of the method is:: |
| 13 |
|
| 14 |
PyoObject.set(attr, value, port=0.03, callback=None) |
| 15 |
|
| 16 |
Where: |
| 17 |
|
| 18 |
- `attr` is the name of the attribute as a string. |
| 19 |
- `value` is the target value (can be a list if object has |
| 20 |
multiple streams). |
| 21 |
- `port` is the portamento time in seconds. |
| 22 |
- `callback` is a function to call when the ramp is done. |
| 23 |
|
| 24 |
.. code-block:: python |
| 25 |
|
| 26 |
from pyo import * |
| 27 |
from random import uniform |
| 28 |
|
| 29 |
s = Server(duplex=0).boot() |
| 30 |
|
| 31 |
# 10 frequency modulations with random parameters. |
| 32 |
a = FM( |
| 33 |
carrier=[uniform(197, 203) for i in range(10)], |
| 34 |
ratio=[uniform(0.99, 1.01) for i in range(10)], |
| 35 |
index=[uniform(5, 10) for i in range(10)], |
| 36 |
mul=0.05, |
| 37 |
).out() |
| 38 |
|
| 39 |
|
| 40 |
def go(): |
| 41 |
"Linear ramps between the current values and the new ones in 9.5 sec." |
| 42 |
# Choose new targets and start the ramps. |
| 43 |
a.set("carrier", [uniform(395, 405) for i in range(10)], 9.5) |
| 44 |
a.set("ratio", [uniform(0.49, 0.51) for i in range(10)], 9.5) |
| 45 |
# Call the reset() function when portamentos are done. |
| 46 |
a.set("index", [uniform(10, 15) for i in range(10)], 9.5, callback=reset) |
| 47 |
|
| 48 |
|
| 49 |
def reset(): |
| 50 |
"Instantaneous jumps to new values." |
| 51 |
a.carrier = [uniform(197, 203) for i in range(10)] |
| 52 |
a.ratio = [uniform(0.99, 1.01) for i in range(10)] |
| 53 |
a.index = [uniform(5, 10) for i in range(10)] |
| 54 |
|
| 55 |
|
| 56 |
# Call the go() function every 10 seconds. |
| 57 |
pat = Pattern(go, time=10).play() |
| 58 |
|
| 59 |
s.gui(locals()) |
| 60 |
|