Mockup: pspsnd.py

Line 
1 #pspsnd.py
2 #pygame-wrapper to fake pspsnd module as found on http://fraca7.free.fr/pspwiki/doku.php?id=pspsnd
3 #meant merely to allow pypsp games to be made on a computer
4
5 #This is under a BSD License, copyright Kousu <kousue@gmail.com> 2006
6
7 import pygame
8
9 pygame.mixer.init()
10
11 sndFxVolume = 255 #volume of Sound class
12 musicVolume = 255 #volume of Music class
13
14 def setSndFxVolume(volume):
15         if 0<=volume<=255:
16                 global sndFxVolume
17                 sndFxVolume = volume
18
19 def setMusicVolume(volume):
20         if 0<=volume<=255:
21                 global musicVolume
22                 musicVolume = volume
23
24 class Sound:
25         loops = 0
26         def __init__(self, filename):
27                 self.snd = pygame.mixer.Sound(filename)
28                 self.snd.set_volume(sndFxVolume)
29        
30         def start(self):
31                 self.snd.play(self.loops)
32
33 class Music(Sound):
34         """For now Music is just another Sound, because I have no idea what
35         fraca is trying to do by having two classes that do the same thing,
36         and even though I could read the source I'm lazy
37         (sorry for saying it was closed source though, Fraca)"""
38        
39         def __init__(self, filename, maxchan = 128, loop = False):
40                 """maxchan is I have no clue, loop makes it loop"""
41                 Sound.__init__(self, filename)
42                 if loop: self.loops = -1 #play indefinitely
43                 else: self.loops = 0 #no looping
44                 self.snd.set_volume(musicVolume)
45        
46         def stop(self):
47                 self.snd.stop()