comparison engine/python/fife/extensions/soundmanager.py @ 493:e29853880e87

Adapted rio_do_hola to use the new SoundManager. Fixed a bug in the sound manager that caused a sound to not be looped if it did not have a callback assigned to it. Looping a stream using timers doesn't loop perfectly. I'll fix this in the future.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Fri, 07 May 2010 21:46:25 +0000
parents 16ceb3228324
children e241d7553496
comparison
equal deleted inserted replaced
492:16ceb3228324 493:e29853880e87
210 You cannot play the same sound more than once at a time unless you create 210 You cannot play the same sound more than once at a time unless you create
211 the SoundEmitter with the forceUnique paramater set to True. 211 the SoundEmitter with the forceUnique paramater set to True.
212 212
213 @param clip The SoundEmitter to be played 213 @param clip The SoundEmitter to be played
214 """ 214 """
215
216 if clip.fifeemitter: 215 if clip.fifeemitter:
217 if clip.callback: 216 if clip.callback:
218 if clip.timer: 217 if clip.timer:
219 clip.timer.stop() 218 clip.timer.stop()
220 timer = None 219 timer = None
222 if clip.looping: 221 if clip.looping:
223 repeat = 0 222 repeat = 0
224 def real_callback(c, e, g): 223 def real_callback(c, e, g):
225 c() 224 c()
226 e.stop() 225 e.stop()
227 e.setGain(g) 226 e.setGain(float(g)/255.0)
228 e.play() 227 e.play()
229 228
230 clip.callback = cbwa(real_callback, clip.callback, clip.fifeemitter, clip.gain) 229 clip.callback = cbwa(real_callback, clip.callback, clip.fifeemitter, clip.gain)
231 230
232 else: 231 else:
233 repeat = 1 232 repeat = 1
234 233
235 clip.timer = fife_timer.delayCall(clip.duration, clip.callback) 234 clip.timer = fife_timer.Timer(clip.duration, clip.callback, repeat)
236 #clip.timer.start() 235 clip.timer.start()
237 236 else:
238 clip.fifeemitter.setGain(clip.gain) 237 if clip.looping:
238 def real_callback(e, g):
239 e.stop()
240 e.setGain(float(g)/255.0)
241 e.play()
242
243 clip.callback = cbwa(real_callback, clip.fifeemitter, clip.gain)
244 clip.timer = fife_timer.Timer(clip.duration, clip.callback, 0)
245 clip.timer.start()
246
247
248 clip.fifeemitter.setGain(float(clip.gain)/255.0)
239 clip.fifeemitter.play() 249 clip.fifeemitter.play()
240 else: 250 else:
241 clip = self.createSoundEmitter(clip.name) 251 clip = self.createSoundEmitter(clip.name)
242 self.playClip(clip) 252 self.playClip(clip)
243 253