Wednesday, August 17, 2016

Minim 9. loop

This program demonstrates the loop() method of a AudioPlayer object, once '1' is pressed.


The file 'groove.mp3' has to be in the data directory of the sketch.


# Ex9.pyde
# Based on Java File in Examples: loop.pde

'''
This sketch demonstrates how to use the loop
method of a Playable class. The class used
here is AudioPlayer, but you can also loop
an AudioSnippet. When you call loop() it will
make the Playable playback in an infinite loop.
If you want to make it stop looping you can
call play() and it will finish the current loop
and then stop. Press 'l' to start the player
looping.
'''

add_library('minim')

groove = None

def setup():
    size(512, 200)
    global groove
    minim = Minim(this)
    groove = minim.loadFile("groove.mp3", 2048)
    
def draw():
    background(0)
    stroke(255)
    for i in range(groove.bufferSize()-1):
        line(i, 50 + groove.left.get(i)*50, 
             i+1, 50 + groove.left.get(i+1)*50 )
        line(i, 150 + groove.right.get(i)*50,
             i+1, 150 + groove.right.get(i+1)*50)
        
def keyPressed():
    if key == 'l': groove.loop()

This is the output:


No comments:

Post a Comment