| 1 |
""" |
| 2 |
03-delayed-calls.py - Calling a function once, after a given delay. |
| 3 |
|
| 4 |
If you want to setup a callback once in the future, the CallAfter |
| 5 |
object is very easy to use. You just give it the function name, the |
| 6 |
time to wait before making the call and an optional argument. |
| 7 |
|
| 8 |
""" |
| 9 |
from pyo import * |
| 10 |
|
| 11 |
s = Server().boot() |
| 12 |
|
| 13 |
|
| 14 |
amp = Fader(fadein=0.005, fadeout=0.05, mul=0.2).play() |
| 15 |
osc = SineLoop(freq=[0, 0, 0, 0], feedback=0.05, mul=amp) |
| 16 |
rev = WGVerb(osc.mix(2), feedback=0.8, cutoff=4000, bal=0.2).out() |
| 17 |
|
| 18 |
|
| 19 |
def set_osc_freqs(notes): |
| 20 |
print(notes) |
| 21 |
osc.set(attr="freq", value=midiToHz(list(notes)), port=0.005) |
| 22 |
amp.play() |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
set_osc_freqs([60, 64, 67, 72]) |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
call = None |
| 32 |
|
| 33 |
|
| 34 |
def new_notes(notes): |
| 35 |
global call |
| 36 |
amp.stop() |
| 37 |
|
| 38 |
call = CallAfter(set_osc_freqs, time=0.05, arg=notes) |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
c1 = CallAfter(new_notes, time=0.95, arg=(60, 64, 67, 69)) |
| 48 |
c2 = CallAfter(new_notes, time=1.95, arg=(60, 65, 69, 76)) |
| 49 |
c3 = CallAfter(new_notes, time=2.95, arg=(62, 65, 69, 74)) |
| 50 |
c4 = CallAfter(new_notes, time=3.45, arg=(59, 65, 67, 74)) |
| 51 |
c5 = CallAfter(new_notes, time=3.95, arg=(60, 64, 67, 72)) |
| 52 |
|
| 53 |
c6 = CallAfter(amp.stop, time=5.95, arg=None) |
| 54 |
|
| 55 |
s.gui(locals()) |