#! /usr/bin/python -O
#    This file is part of pysdl_mixer.
#
#    pysdl_mixer is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    pysdl_mixer is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with pysdl_mixer; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

import pysdl_mixer as mixer
import time

mixer.init()

testfile="test.wav"

print "playing test file as sample"

# pysdl_mixer.Sample should be capable of opening WAVE, AIFF, RIFF, OGG, and VOC 
# files.

a=mixer.Sample(testfile)
a.play()

while mixer.channel_is_playing():
	time.sleep(1)

print "playing 4 samples at the same time"

# simply playing the sample will play the sample on the first free channel
# you can play to specific channels if you want. also channel volumes can be 
# controlled seperatly.
for i in range(0,4):
	a.play()

# calling channel_is_playing without and argument or with -1 will
# return True when any channel is playing something 
while mixer.channel_is_playing():
	time.sleep(1)

print "playing testfile as music"

# pysdl_mixer.Music should be able to load WAVE, MOD, MIDI, OGG, MP3 files
m=mixer.Music(testfile)
m.play()

# is_playing returns True all the time the music is playing 
while m.is_playing():
	time.sleep(1)

# we use these as values to fade in. they are times in ms 
times=[100,500,1000,1500]

# there are several play functions for Sample and Music

for t in times:
	print "playing test file as music with a %d ms fade in" % t
	m.play_fade_in(t)

	while m.is_playing():
		time.sleep(1)

	
