| 1 |
01-simple-sequences.py - Looping over a list of values. |
| 2 |
============================================================================================================================================ |
| 3 |
|
| 4 |
|
| 5 |
The purpose of the Events framework is to allow the user to generate a |
| 6 |
sequence of events with as few as possible parameters to specify. |
| 7 |
|
| 8 |
The Events object is at the heart of the framework. An Events object |
| 9 |
compute parameters, generally designed with event generator objects, |
| 10 |
build the events and play the sequence. |
| 11 |
|
| 12 |
The framework provides a default instrument to play the sequence. We'll |
| 13 |
see later how to build our own synthesizers and use them to play the events. |
| 14 |
|
| 15 |
EventSeq |
| 16 |
-------- |
| 17 |
|
| 18 |
The basic event generator is EventSeq, which loop over a list of values:: |
| 19 |
|
| 20 |
e = Events(freq = EventSeq([250, 300, 350, 400])).play() |
| 21 |
|
| 22 |
EventSeq has an "occurrences" keyword, which can be used to fix how many |
| 23 |
times we want to play the sequence of values. The default value is 'inf', |
| 24 |
which means loop forever:: |
| 25 |
|
| 26 |
# This one stops after playing twice the sequence. |
| 27 |
e1 = Events(freq = EventSeq([500, 600, 700, 800], occurrences=2)).play() |
| 28 |
|
| 29 |
When an Events's parameter is given a list or a single value, it is |
| 30 |
internally converted to an EventSeq. This is the same as the first example:: |
| 31 |
|
| 32 |
e2 = Events(freq = [250, 300, 350, 400]) |
| 33 |
|
| 34 |
Complete Example |
| 35 |
---------------- |
| 36 |
|
| 37 |
.. code-block:: python |
| 38 |
|
| 39 |
from pyo import * |
| 40 |
|
| 41 |
s = Server().boot() |
| 42 |
s.amp = 0.25 |
| 43 |
|
| 44 |
# Simple infinite sequence. |
| 45 |
e = Events(freq=EventSeq([250, 300, 350, 400])).play() |
| 46 |
|
| 47 |
# This will play the same note forever. |
| 48 |
e3 = Events(freq=200).play() |
| 49 |
|
| 50 |
s.gui(locals()) |
| 51 |
|