Initial commit from version 1e-99
[beatscape.git] / util.py
1 import pygame
2 import os.path
3
4 import config
5
6 def loadWAV(path,library=False):
7         try:
8                 return pygame.mixer.Sound(path)
9         except pygame.error:
10                 (dir,file) = os.path.split(path)
11                 try:
12                         return pygame.mixer.Sound(os.path.join(dir,file.lower()))
13                 except pygame.error:
14                         if library:
15                                 return None
16                         else:
17                                 # Ok, try the system sample library...
18                                 return loadWAV(os.path.join(config.librarypath,file),True)
19
20 def loadMP3(path):
21         pygame.mixer.music.load(path)
22         return pygame.mixer.music
23
24 def loadBMP(path):
25         try:
26                 return pygame.image.load(path).convert()
27         except pygame.error:
28                 (dir,file) = os.path.split(path)
29                 try:
30                         return pygame.image.load(os.path.join(dir,file.lower())).convert()
31                 except pygame.error:
32                         return None
33