| 1 |
11-filters.py - Modifying generator's output with filters. |
| 2 |
============================================================================================================================================ |
| 3 |
|
| 4 |
|
| 5 |
The EventGenerator class contains many methods that can be used to filter |
| 6 |
the sequence of output values in order to get the desired results. These |
| 7 |
filters return an EventFilter object, which is also a child of EventGenerator, |
| 8 |
that perform the operation. |
| 9 |
|
| 10 |
Available filter methods are: |
| 11 |
|
| 12 |
- floor: |
| 13 |
Return an EventFilter computing the largest integer less than or |
| 14 |
equal to its input value. |
| 15 |
- ceil: |
| 16 |
Return an EventFilter computing the smallest integer greater than |
| 17 |
or equal to its input value. |
| 18 |
- round: |
| 19 |
Return an EventFilter computing the nearest integer to its input value. |
| 20 |
- snap: |
| 21 |
Return an EventFilter which choose the nearest value of its input |
| 22 |
value in a list of choices. |
| 23 |
- deviate: |
| 24 |
Return an EventFilter which randomly move, up or down, its input value. |
| 25 |
- clip: |
| 26 |
Return an EventFilter which clips its input value between predefined |
| 27 |
limits. |
| 28 |
- scale: |
| 29 |
Return an EventFilter which maps its input value, in the range 0 to 1, |
| 30 |
to an output range, with a scaling curve. |
| 31 |
- rescale: |
| 32 |
Return an EventFilter which maps its input value, given in an input |
| 33 |
range, to an output range with a scaling curve. |
| 34 |
- iftrue: |
| 35 |
Return an EventFilter which compares its input value to a comparison |
| 36 |
value and outputs it if the comparison is True. |
| 37 |
|
| 38 |
.. code-block:: python |
| 39 |
|
| 40 |
from random import weibullvariate |
| 41 |
from pyo import * |
| 42 |
|
| 43 |
s = Server().boot() |
| 44 |
|
| 45 |
scl = EventScale(root="C", scale="wholeTone", first=4, octaves=3) |
| 46 |
|
| 47 |
# Takes a Weibull distribution, scales the values between 48 and 84, rounds |
| 48 |
# them to the nearest integer, then snaps to the nearest value in the given |
| 49 |
# scale and uses the result as midi note if it's below 84. |
| 50 |
e = Events( |
| 51 |
midinote=EventCall(weibullvariate, 0.5, 0.5).scale(48, 84, 1).round().snap(scl).iftrue("<", 84), |
| 52 |
beat=1 / 4.0, |
| 53 |
db=-6, |
| 54 |
attack=0.001, |
| 55 |
decay=0.05, |
| 56 |
sustain=0.5, |
| 57 |
release=0.005, |
| 58 |
).play() |
| 59 |
|
| 60 |
# Rescale values from a pink noise to the range 48 to 72 and snap to the given scale. |
| 61 |
e2 = Events( |
| 62 |
midinote=EventNoise(type=1).rescale(-1, 1, 48, 72, 1).snap(scl), |
| 63 |
beat=1 / 4.0, |
| 64 |
db=-6, |
| 65 |
transpo=12, |
| 66 |
attack=0.001, |
| 67 |
decay=0.05, |
| 68 |
sustain=0.5, |
| 69 |
release=0.005, |
| 70 |
).play() |
| 71 |
|
| 72 |
s.gui(locals()) |
| 73 |
|