| 1 |
02-parameters.py - Built-in arguments and conversions. |
| 2 |
============================================================================================================================================ |
| 3 |
|
| 4 |
|
| 5 |
An Events object is build on top of the python's dictionary. Any argument |
| 6 |
passed at the creation of the object becomes a key inside the built-in |
| 7 |
structure. A lot of argument are pre-defined automatically processed to |
| 8 |
facilitate the construction of event's frequency, duration, amplitude, |
| 9 |
and envelope. |
| 10 |
|
| 11 |
Duration |
| 12 |
-------- |
| 13 |
|
| 14 |
The duration of an event can be defined with 'dur' argument, which is a |
| 15 |
duration in seconds, or with 'beat' argument. A value given to 'beat' is |
| 16 |
converted in seconds (and registered at the key 'dur'), according to the |
| 17 |
value given to the 'bpm' argument (which defaults to 120). A beat value |
| 18 |
of 1 is the duration of the quarter note, 2 is a half note, 1/2 is an |
| 19 |
eighth note, and so on... |
| 20 |
|
| 21 |
The first argument that reaches the end of its sequence triggers the end |
| 22 |
of the Events's playback:: |
| 23 |
|
| 24 |
e = Events(freq = EventSeq([250, 300, 350, 400]), |
| 25 |
beat = EventSeq([1/2., 1/4., 1/4., 1], occurrences=4)).play() |
| 26 |
|
| 27 |
The 'durmul' argument allow to change the note duration without changing |
| 28 |
the time gap between successive events:: |
| 29 |
|
| 30 |
# Staccato |
| 31 |
e1 = Events(freq = EventSeq([250, 300, 350, 400]), |
| 32 |
beat = EventSeq([1/2., 1/4., 1/4., 1], occurrences=4), |
| 33 |
durmul = 0.5).play() |
| 34 |
|
| 35 |
# Overlapping |
| 36 |
e2 = Events(freq = EventSeq([250, 300, 350, 400]), |
| 37 |
beat = EventSeq([1/2., 1/4., 1/4., 1], occurrences=4), |
| 38 |
durmul = 1.5).play() |
| 39 |
|
| 40 |
Frequency |
| 41 |
--------- |
| 42 |
|
| 43 |
The 'freq' argument can be used directly to specify the root note. But |
| 44 |
it is sometimes easier to create a melody with 'midinote' or 'degree', |
| 45 |
and let the engine do the conversion to frequency for you. The 'midinote' |
| 46 |
argument is a MIDI note number between 0 and 127, fractionnal numbers |
| 47 |
are allowed to do micro-tonal scaling. The 'degree' argument needs a |
| 48 |
value in octave.degree format where octave is the number of the desired |
| 49 |
octave and degree is a 2-digits degree number between 00 and 11. For |
| 50 |
an example, the MIDI note 48 is 4.00 in octave.degree notation. |
| 51 |
|
| 52 |
The midinote and degree arguments will automatically convert and store |
| 53 |
the frequency, in Hz, as the 'freq' argument:: |
| 54 |
|
| 55 |
e3 = Events(midinote = EventSeq([60, 64, 67, 72]), |
| 56 |
beat = EventSeq([1/2., 1/4., 1/4., 1], occurrences=4)).play() |
| 57 |
|
| 58 |
The 'degree' argument uses an octave.degree notation. Ex.: 6.07 means |
| 59 |
the perfect fifth (07) of the sixth octave:: |
| 60 |
|
| 61 |
e4 = Events(degree = EventSeq([5.00, 5.04, 5.07, 6.00]), |
| 62 |
beat = EventSeq([1/2., 1/4., 1/4., 1], occurrences=4)).play() |
| 63 |
|
| 64 |
One can transpose an entire sequence (or sequence the transposition |
| 65 |
values) with the 'transpo' argument. Transposition values are relative |
| 66 |
midi note (0 means no transposition, -12 is the lower octave):: |
| 67 |
|
| 68 |
e5 = Events(degree = EventSeq([5.00, 5.04, 5.07, 6.00]), |
| 69 |
beat = EventSeq([1/2., 1/4., 1/4., 1], occurrences=4), |
| 70 |
transpo = -12).play() |
| 71 |
|
| 72 |
Amplitude |
| 73 |
--------- |
| 74 |
|
| 75 |
Amplitude values are given either with 'amp' (linear amplitude), 'db' |
| 76 |
(decibel values) or 'midivel' (MIDI velocity between 0 and 127). Decibel |
| 77 |
values and MIDI velocity are internally converted to linear gain and stored |
| 78 |
as the 'amp' argument:: |
| 79 |
|
| 80 |
# Sequence with accented notes. |
| 81 |
e6 = Events(degree = EventSeq([5.00, 5.04, 5.07, 6.00]), |
| 82 |
beat = EventSeq([1/2., 1/4., 1/4., 1], occurrences=4), |
| 83 |
db = EventSeq([-3, -6, -12, -3])).play() |
| 84 |
|
| 85 |
Envelope |
| 86 |
-------- |
| 87 |
|
| 88 |
Different shapes for the amplitude envelope are defined according to the |
| 89 |
presence of certain parameters. The amplitude envelope is automatically |
| 90 |
created in the EventGenerator __init__ method. |
| 91 |
|
| 92 |
If 'envelope' receives a PyoTableObject, it will be used as the amplitude |
| 93 |
envelope of the events. If 'envelope' is None and 'decay' gets a value, |
| 94 |
the envelope will be an ADSR built with 'attack', 'decay', 'sustain' and |
| 95 |
'release' argument. If both 'envelope' and 'decay' are None, the envelope |
| 96 |
will be an ASR, defined with 'attack', 'sustain' and 'release' arguments. |
| 97 |
|
| 98 |
The following defines an Adsr envelope:: |
| 99 |
|
| 100 |
e7 = Events(degree = EventSeq([5.00, 5.04, 5.07, 6.00]), |
| 101 |
beat = EventSeq([1/2., 1/4., 1/4., 1], occurrences=4), |
| 102 |
attack = 0.001, decay = 0.05, sustain = 0.5, release = 0.005, |
| 103 |
db = EventSeq([-3, -6, -12, -3])).play() |
| 104 |
|
| 105 |
Complete Example |
| 106 |
---------------- |
| 107 |
|
| 108 |
.. code-block:: python |
| 109 |
|
| 110 |
from pyo import * |
| 111 |
|
| 112 |
s = Server().boot() |
| 113 |
|
| 114 |
### Envelope |
| 115 |
|
| 116 |
# Using a PyoTableObject to define the envelope. |
| 117 |
env = CosTable([(0, 0.0), (128, 1.0), (1024, 0.7), (4096, 0.7), (8192, 0.0)]) |
| 118 |
|
| 119 |
e8 = Events( |
| 120 |
degree=EventSeq([5.00, 5.04, 5.07, 6.00]), |
| 121 |
beat=EventSeq([1 / 2.0, 1 / 4.0, 1 / 4.0, 1], occurrences=4), |
| 122 |
db=EventSeq([-3, -6, -12, -3]), |
| 123 |
envelope=env, |
| 124 |
).play() |
| 125 |
|
| 126 |
s.gui(locals()) |
| 127 |
|