| 1 |
02-read-from-disk-2.py - Catching the `end-of-file` signal from the SfPlayer object. |
| 2 |
============================================================================================================================================ |
| 3 |
|
| 4 |
|
| 5 |
This example demonstrates how to use the `end-of-file` signal |
| 6 |
of the SfPlayer object to trigger another playback (possibly |
| 7 |
with another sound, another speed, etc.). |
| 8 |
|
| 9 |
When a SfPlayer reaches the end of the file, it sends a trigger |
| 10 |
(more on trigger later) that the user can retrieve with the |
| 11 |
syntax : |
| 12 |
|
| 13 |
variable_name["trig"] |
| 14 |
|
| 15 |
.. code-block:: python |
| 16 |
|
| 17 |
from pyo import * |
| 18 |
import random |
| 19 |
|
| 20 |
s = Server().boot() |
| 21 |
|
| 22 |
# Sound bank |
| 23 |
folder = "../snds/" |
| 24 |
sounds = ["alum1.wav", "alum2.wav", "alum3.wav", "alum4.wav"] |
| 25 |
|
| 26 |
# Creates the left and right players |
| 27 |
sfL = SfPlayer(folder + sounds[0], speed=1, mul=0.5).out() |
| 28 |
sfR = SfPlayer(folder + sounds[0], speed=1, mul=0.5).out(1) |
| 29 |
|
| 30 |
# Function to choose a new sound and a new speed for the left player |
| 31 |
def newL(): |
| 32 |
sfL.path = folder + sounds[random.randint(0, 3)] |
| 33 |
sfL.speed = random.uniform(0.75, 1.5) |
| 34 |
sfL.out() |
| 35 |
|
| 36 |
|
| 37 |
# The "end-of-file" signal triggers the function "newL" |
| 38 |
tfL = TrigFunc(sfL["trig"], newL) |
| 39 |
|
| 40 |
# Function to choose a new sound and a new speed for the right player |
| 41 |
def newR(): |
| 42 |
sfR.path = folder + sounds[random.randint(0, 3)] |
| 43 |
sfR.speed = random.uniform(0.75, 1.5) |
| 44 |
sfR.out(1) |
| 45 |
|
| 46 |
|
| 47 |
# The "end-of-file" signal triggers the function "newR" |
| 48 |
tfR = TrigFunc(sfR["trig"], newR) |
| 49 |
|
| 50 |
s.gui(locals()) |
| 51 |
|