Mercurial > fife-parpg
comparison engine/python/fife/extensions/soundmanager.py @ 500:5e6ff32a46fb
Added listener position to the soundmanager.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Fri, 14 May 2010 20:28:05 +0000 |
parents | 5ff83f209333 |
children | 6614a5446352 |
comparison
equal
deleted
inserted
replaced
499:3dff106b945b | 500:5e6ff32a46fb |
---|---|
192 | 192 |
193 self._fifesoundmanager = self._engine.getSoundManager() | 193 self._fifesoundmanager = self._engine.getSoundManager() |
194 self._fifesoundmanager.init() | 194 self._fifesoundmanager.init() |
195 | 195 |
196 # basic rolloff used for positional sounds | 196 # basic rolloff used for positional sounds |
197 self._rolloff = 1.9 | 197 self._rolloff = 1 |
198 | 198 |
199 #A dict of fife emitters | 199 #A dict of fife emitters |
200 self._loadedclips = {} | 200 self._loadedclips = {} |
201 | |
202 #A tuple representing the listener position (x,y) | |
203 self._listenerposition = None | |
201 | 204 |
202 def createSoundEmitter(self, filename, forceUnique=False, position=None): | 205 def createSoundEmitter(self, filename, forceUnique=False, position=None): |
203 """ | 206 """ |
204 Returns a valid SoundEmitter instance. | 207 Returns a valid SoundEmitter instance. |
205 | 208 |
238 clip.duration = fifeemitter.getDuration() | 241 clip.duration = fifeemitter.getDuration() |
239 | 242 |
240 if position is not None: | 243 if position is not None: |
241 clip.position = position | 244 clip.position = position |
242 clip.rolloff = self.rolloff | 245 clip.rolloff = self.rolloff |
246 | |
243 return clip | 247 return clip |
244 | 248 |
245 def playClip(self, clip): | 249 def playClip(self, clip): |
246 """ | 250 """ |
247 Plays a sound clip. | 251 Plays a sound clip. |
278 | 282 |
279 else: | 283 else: |
280 repeat = 1 | 284 repeat = 1 |
281 | 285 |
282 clip.timer = fife_timer.Timer(clip.duration, clip.callback, repeat) | 286 clip.timer = fife_timer.Timer(clip.duration, clip.callback, repeat) |
283 #clip.timer.start() | 287 |
284 else: | 288 else: |
285 if clip.looping: | 289 if clip.looping: |
286 def real_callback(e, g): | 290 def real_callback(e, g): |
287 e.stop() | 291 e.stop() |
288 e.setGain(float(g)/255.0) | 292 e.setGain(float(g)/255.0) |
289 e.play() | 293 e.play() |
290 | 294 |
291 clip.callback = cbwa(real_callback, clip.fifeemitter, clip.gain) | 295 clip.callback = cbwa(real_callback, clip.fifeemitter, clip.gain) |
292 clip.timer = fife_timer.Timer(clip.duration, clip.callback, 0) | 296 clip.timer = fife_timer.Timer(clip.duration, clip.callback, 0) |
293 #clip.timer.start() | |
294 | |
295 | 297 |
296 clip.fifeemitter.setGain(float(clip.gain)/255.0) | 298 clip.fifeemitter.setGain(float(clip.gain)/255.0) |
297 if clip.position is not None: | 299 |
300 if self.listenerposition and clip.position: | |
298 # Use 1 as z coordinate, no need to specify it | 301 # Use 1 as z coordinate, no need to specify it |
299 clip.fifeemitter.setPosition(clip.position[0], clip.position[1], 1) | 302 clip.fifeemitter.setPosition(clip.position[0], clip.position[1], 1) |
300 clip.fifeemitter.setRolloff(clip.rolloff) | 303 clip.fifeemitter.setRolloff(clip.rolloff) |
304 elif self.listenerposition and not clip.position: | |
305 clip.fifeemitter.setPosition(self.listenerposition[0], self.listenerposition[1], 1) | |
306 clip.fifeemitter.setRolloff(self.rolloff) | |
307 | |
301 clip.fifeemitter.play() | 308 clip.fifeemitter.play() |
302 if clip.timer: | 309 if clip.timer: |
303 clip.timer.start() | 310 clip.timer.start() |
311 | |
304 else: | 312 else: |
305 clip = self.createSoundEmitter(clip.name) | 313 clip = self.createSoundEmitter(clip.name) |
306 self.playClip(clip) | 314 self.playClip(clip) |
307 | 315 |
308 def stopClip(self, clip): | 316 def stopClip(self, clip): |
343 def _getRolloff(self): | 351 def _getRolloff(self): |
344 return self._rolloff | 352 return self._rolloff |
345 | 353 |
346 def _setRolloff(self, rolloff): | 354 def _setRolloff(self, rolloff): |
347 self._rolloff = rolloff | 355 self._rolloff = rolloff |
356 | |
357 def _getListenerPosition(self): | |
358 return self._listenerposition | |
359 | |
360 def _setListenerPosition(self, position): | |
361 self._listenerposition = position | |
362 self._fifesoundmanager.setListenerPosition(self._listenerposition[0], self._listenerposition[1], 1) | |
348 | 363 |
349 rolloff = property(_getRolloff, _setRolloff) | 364 rolloff = property(_getRolloff, _setRolloff) |
365 listenerposition = property(_getListenerPosition, _setListenerPosition) | |
350 | 366 |
351 __all__ = ['SoundEmitter','SoundManager'] | 367 __all__ = ['SoundEmitter','SoundManager'] |