Mercurial > boomslang
comparison pyntnclick/sound.py @ 548:ded4324b236e pyntnclick
Moved stuff around, broke everything.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Sat, 11 Feb 2012 13:10:18 +0200 |
parents | gamelib/sound.py@6df527142e69 |
children | 2f7aa3cad77c |
comparison
equal
deleted
inserted
replaced
547:33ce7ff757c3 | 548:ded4324b236e |
---|---|
1 # Sound management for Suspended Sentence | |
2 | |
3 # This re-implements some of the albow.resource code to | |
4 # a) work around an annoying bugs | |
5 # b) add some missing functionality (disable_sound) | |
6 | |
7 import os | |
8 | |
9 import pygame | |
10 from pygame.mixer import music | |
11 from albow.resource import _resource_path, dummy_sound | |
12 import albow.music | |
13 | |
14 sound_cache = {} | |
15 | |
16 | |
17 def get_sound(*names): | |
18 if sound_cache is None: | |
19 return dummy_sound | |
20 path = _resource_path("sounds", names) | |
21 sound = sound_cache.get(path) | |
22 if not sound: | |
23 if not os.path.isfile(path): | |
24 missing_sound("File does not exist", path) | |
25 return dummy_sound | |
26 try: | |
27 from pygame.mixer import Sound | |
28 except ImportError, e: | |
29 no_sound(e) | |
30 return dummy_sound | |
31 try: | |
32 sound = Sound(path) | |
33 except pygame.error, e: | |
34 missing_sound(e, path) | |
35 return dummy_sound | |
36 sound_cache[path] = sound | |
37 return sound | |
38 | |
39 | |
40 def no_sound(e): | |
41 global sound_cache | |
42 print "get_sound: %s" % e | |
43 print "get_sound: Sound not available, continuing without it" | |
44 sound_cache = None | |
45 albow.music.music_enabled = False | |
46 | |
47 | |
48 def disable_sound(): | |
49 global sound_cache | |
50 sound_cache = None | |
51 albow.music.music_enabled = False | |
52 | |
53 | |
54 def missing_sound(e, name): | |
55 print "albow.resource.get_sound: %s: %s" % (name, e) | |
56 | |
57 | |
58 def start_next_music(): | |
59 """Start playing the next item from the current playlist immediately.""" | |
60 if albow.music.music_enabled and albow.music.current_playlist: | |
61 next_music = albow.music.current_playlist.next() | |
62 if next_music: | |
63 #print "albow.music: loading", repr(next_music) | |
64 music.load(next_music) | |
65 music.play() | |
66 albow.music.next_change_delay = albow.music.change_delay | |
67 albow.music.current_music = next_music | |
68 | |
69 | |
70 def get_current_playlist(): | |
71 if albow.music.music_enabled and albow.music.current_playlist: | |
72 return albow.music.current_playlist | |
73 | |
74 # Monkey patch | |
75 albow.music.start_next_music = start_next_music |