comparison pytouhou/ui/music.pyx @ 590:e15672733c93

Switch to Python 3.x instead of 2.7.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 30 Sep 2014 17:14:24 +0200
parents a50c0a1b628f
children c84227022765
comparison
equal deleted inserted replaced
589:0768122da817 590:e15672733c93
14 14
15 15
16 from os.path import join 16 from os.path import join
17 from glob import glob 17 from glob import glob
18 from pytouhou.lib import sdl 18 from pytouhou.lib import sdl
19 from pytouhou.lib cimport sdl 19 from pytouhou.lib.sdl cimport load_music, Music, load_chunk, Chunk
20 from pytouhou.utils.helpers import get_logger 20 from pytouhou.utils.helpers import get_logger
21 from pytouhou.game.music cimport MusicPlayer 21 from pytouhou.game.music cimport MusicPlayer
22 22
23 logger = get_logger(__name__) 23 logger = get_logger(__name__)
24 24
35 posname = bgm[1].replace('bgm/', '').replace('.mid', '.pos') 35 posname = bgm[1].replace('bgm/', '').replace('.mid', '.pos')
36 try: 36 try:
37 track = resource_loader.get_track(posname) 37 track = resource_loader.get_track(posname)
38 except KeyError: 38 except KeyError:
39 track = None 39 track = None
40 logger.warn(u'Music description “%s” not found, continuing without looping data.', posname) 40 logger.warn('Music description “%s” not found, continuing without looping data.', posname)
41 globname = join(resource_loader.game_dir, bgm[1].encode('ascii')).replace('.mid', '.*') 41 globname = join(resource_loader.game_dir, bgm[1]).replace('.mid', '.*')
42 filenames = glob(globname) 42 filenames = glob(globname)
43 for filename in reversed(filenames): 43 for filename in reversed(filenames):
44 try: 44 try:
45 source = sdl.load_music(filename) 45 source = load_music(filename)
46 except sdl.SDLError as error: 46 except sdl.SDLError as error:
47 logger.debug(u'Music file “%s” unreadable: %s', filename, error) 47 logger.debug('Music file “%s” unreadable: %s', filename, error)
48 continue 48 continue
49 else: 49 else:
50 if track is not None: 50 if track is not None:
51 source.set_loop_points(track.start / 44100., track.end / 44100.) #TODO: retrieve the sample rate from the actual track. 51 source.set_loop_points(track.start / 44100., track.end / 44100.) #TODO: retrieve the sample rate from the actual track.
52 self.bgms.append(source) 52 self.bgms.append(source)
53 logger.debug(u'Music file “%s” opened.', filename) 53 logger.debug('Music file “%s” opened.', filename)
54 break 54 break
55 else: 55 else:
56 self.bgms.append(None) 56 self.bgms.append(None)
57 logger.warn(u'No working music file for “%s”, disabling bgm.', globname) 57 logger.warn('No working music file for “%s”, disabling bgm.', globname)
58 58
59 cpdef play(self, index): 59 cpdef play(self, index):
60 cdef sdl.Music bgm 60 cdef Music bgm
61 bgm = self.bgms[index] 61 bgm = self.bgms[index]
62 if bgm is not None: 62 if bgm is not None:
63 bgm.play(-1) 63 bgm.play(-1)
64 64
65 65
80 if name not in self.channels: 80 if name not in self.channels:
81 self.channels[name] = self.next_channel 81 self.channels[name] = self.next_channel
82 self.next_channel += 1 82 self.next_channel += 1
83 return self.channels[name] 83 return self.channels[name]
84 84
85 cdef sdl.Chunk get_sound(self, name): 85 cdef Chunk get_sound(self, name):
86 cdef sdl.Chunk chunk 86 cdef Chunk chunk
87 if name not in self.sounds: 87 if name not in self.sounds:
88 wave_file = self.loader.get_file(name) 88 wave_file = self.loader.get_file(name)
89 try: 89 try:
90 chunk = sdl.load_chunk(wave_file) 90 chunk = load_chunk(wave_file)
91 except sdl.SDLError as error: 91 except sdl.SDLError as error:
92 logger.warn(u'Sound “%s” not found: %s', name, error) 92 logger.warn(u'Sound “%s” not found: %s', name, error)
93 chunk = None 93 chunk = None
94 else: 94 else:
95 chunk.set_volume(self.volume) 95 chunk.set_volume(self.volume)