comparison pytouhou/lib/sdl.pyx @ 501:4778c482f24a

Make SDL(sound=False) work again, and disable sound if an exception occurs while setting it up.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 23 Oct 2013 18:24:07 +0200
parents 2276229282fd
children b39ad30c6620
comparison
equal deleted inserted replaced
500:777544d11578 501:4778c482f24a
9 ## This program is distributed in the hope that it will be useful, 9 ## This program is distributed in the hope that it will be useful,
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of 10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ## GNU General Public License for more details. 12 ## GNU General Public License for more details.
13 ## 13 ##
14
15 from pytouhou.utils.helpers import get_logger
16
17 logger = get_logger(__name__)
18
14 19
15 GL_CONTEXT_MAJOR_VERSION = SDL_GL_CONTEXT_MAJOR_VERSION 20 GL_CONTEXT_MAJOR_VERSION = SDL_GL_CONTEXT_MAJOR_VERSION
16 GL_CONTEXT_MINOR_VERSION = SDL_GL_CONTEXT_MINOR_VERSION 21 GL_CONTEXT_MINOR_VERSION = SDL_GL_CONTEXT_MINOR_VERSION
17 GL_DOUBLEBUFFER = SDL_GL_DOUBLEBUFFER 22 GL_DOUBLEBUFFER = SDL_GL_DOUBLEBUFFER
18 GL_DEPTH_SIZE = SDL_GL_DEPTH_SIZE 23 GL_DEPTH_SIZE = SDL_GL_DEPTH_SIZE
54 img_init(IMG_INIT_PNG) 59 img_init(IMG_INIT_PNG)
55 ttf_init() 60 ttf_init()
56 61
57 if self.sound: 62 if self.sound:
58 mix_init(0) 63 mix_init(0)
59 mix_open_audio(44100, MIX_DEFAULT_FORMAT, 2, 4096) 64 try:
60 mix_allocate_channels(MAX_CHANNELS) #TODO: make it dependent on the SFX number. 65 mix_open_audio(44100, MIX_DEFAULT_FORMAT, 2, 4096)
66 except SDLError as error:
67 logger.error(u'Impossible to set up audio subsystem: %s', error)
68 self.sound = False
69 else:
70 mix_allocate_channels(MAX_CHANNELS) #TODO: make it dependent on the SFX number.
61 71
62 def __exit__(self, *args): 72 def __exit__(self, *args):
63 if self.sound: 73 if self.sound:
64 Mix_CloseAudio() 74 Mix_CloseAudio()
65 Mix_Quit() 75 Mix_Quit()