File: 10-arithmetic-ops.rst.txt

package info (click to toggle)
python-pyo 1.0.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,332 kB
  • sloc: python: 135,133; ansic: 127,822; javascript: 16,116; sh: 395; makefile: 388; cpp: 242
file content (70 lines) | stat: -rw-r--r-- 1,765 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
10-arithmetic-ops.py - Using arithmetic with event generators.
============================================================================================================================================


Arithmetic operators can be used with EventGenerator objects to control
their behaviour (and change the pattern of the sequence of values).

Available operators are:

`+` : addition

`-` : substraction

`*` : multiplication

`/` : division

`**`: exponent

`%` : modulo (remaining of the division)

`//`: quantizer (returns te nearest multiple of its argument)

Arithmetic can be done with event generators as both operand and operator.

.. code-block:: python

    from pyo import *
    
    s = Server().boot()
    
    # Half-semitone scale (the octave is divided in 24 equally-spaced steps).
    # The integer (a semitone in midi note) is divided by 2, which mean that
    # there are two values inside a single integer.
    e = Events(
        midinote=EventDrunk(list(range(48)), maxStep=-2) / 2.0 + 72,
        beat=1 / 4.0,
        db=-12,
        attack=0.001,
        decay=0.05,
        sustain=0.5,
        release=0.005,
    ).play()
    
    # Quantize to multiples of a minor third.
    e2 = Events(
        midinote=EventCall(random.uniform, 60, 72) // 3,
        beat=1 / 4.0,
        db=-12,
        durmul=1,
        attack=0.001,
        decay=0.05,
        sustain=0.5,
        release=0.005,
    ).play()
    
    # EventGenerator as arithmetic operator. Kind of ostinato.
    e3 = Events(
        midinote=EventSeq([48, 50, 52]) - EventSeq([0, 2, 4, 6]),
        beat=1 / 4.0,
        db=-12,
        durmul=1,
        attack=0.001,
        decay=0.05,
        sustain=0.5,
        release=0.005,
    ).play()
    
    s.gui(locals())