Debian Codegraph @

pyo/examples/x22-events/10-arithmetic-ops.py

raw symbols SCIP
1 """
2 10-arithmetic-ops.py - Using arithmetic with event generators.
3
4 Arithmetic operators can be used with EventGenerator objects to control
5 their behaviour (and change the pattern of the sequence of values).
6
7 Available operators are:
8
9 `+` : addition
10
11 `-` : substraction
12
13 `*` : multiplication
14
15 `/` : division
16
17 `**`: exponent
18
19 `%` : modulo (remaining of the division)
20
21 `//`: quantizer (returns te nearest multiple of its argument)
22
23 Arithmetic can be done with event generators as both operand and operator.
24
25 """
26
27 from pyo import *
28
29 s = Server().boot()
30
31 # Half-semitone scale (the octave is divided in 24 equally-spaced steps).
32 # The integer (a semitone in midi note) is divided by 2, which mean that
33 # there are two values inside a single integer.
34 e = Events(
35 midinote=EventDrunk(list(range(48)), maxStep=-2) / 2.0 + 72,
36 beat=1 / 4.0,
37 db=-12,
38 attack=0.001,
39 decay=0.05,
40 sustain=0.5,
41 release=0.005,
42 ).play()
43
44 # Quantize to multiples of a minor third.
45 e2 = Events(
46 midinote=EventCall(random.uniform, 60, 72) // 3,
47 beat=1 / 4.0,
48 db=-12,
49 durmul=1,
50 attack=0.001,
51 decay=0.05,
52 sustain=0.5,
53 release=0.005,
54 ).play()
55
56 # EventGenerator as arithmetic operator. Kind of ostinato.
57 e3 = Events(
58 midinote=EventSeq([48, 50, 52]) - EventSeq([0, 2, 4, 6]),
59 beat=1 / 4.0,
60 db=-12,
61 durmul=1,
62 attack=0.001,
63 decay=0.05,
64 sustain=0.5,
65 release=0.005,
66 ).play()
67
68 s.gui(locals())