Debian Codegraph @

pyo/examples/x09-callbacks/02-score-calls.py

raw symbols SCIP
1 """
2 02-score-calls.py - Sequencing the function calls.
3
4 The Score object takes in input an audio stream containing integers
5 and any time the integer changes, it calls a function with a generic
6 name to which the integer is added. This allows the user to build a
7 sequence of functions and to control how and when each one is called.
8
9 This example uses a metronome and a counter to generate a stream of
10 integers at a specific rate. The called functions change the oscillator
11 frequencies to produce a chords sequence.
12
13 """
14 from pyo import *
15
16 s = Server().boot()
17
18 # A four-streams oscillator to produce a chord.
19 osc = SineLoop(freq=[0, 0, 0, 0], feedback=0.05, mul=0.2)
20 rev = WGVerb(osc.mix(2), feedback=0.8, cutoff=4000, bal=0.2).out()
21
22
23 def set_osc_freqs(notes):
24 # PyoObject.set() method allow to change the value of an attribute
25 # with an audio ramp to smooth out the change.
26 osc.set(attr="freq", value=midiToHz(notes), port=0.005)
27
28
29 # The sequence of functions (some call set_osc_freqs to change the notes).
30 def event_0():
31 set_osc_freqs([60, 64, 67, 72])
32
33
34 def event_1():
35 pass
36
37
38 def event_2():
39 set_osc_freqs([60, 64, 67, 69])
40
41
42 def event_3():
43 pass
44
45
46 def event_4():
47 set_osc_freqs([60, 65, 69, 76])
48
49
50 def event_5():
51 pass
52
53
54 def event_6():
55 set_osc_freqs([62, 65, 69, 74])
56
57
58 def event_7():
59 set_osc_freqs([59, 65, 67, 74])
60
61
62 # Integer generator (more about triggers in section 12-triggers)
63 metro = Metro(time=0.5).play()
64 count = Counter(metro, min=0, max=8)
65
66 # Score calls the function named "event_" + count. (if count is 3,
67 # function named "event_3" is called without argument.
68 score = Score(count, fname="event_")
69
70 s.gui(locals())