Debian Codegraph @

pyo/examples/x22-events/02-parameters.py

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