# HG changeset patch # User prock@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1273268785 0 # Node ID e29853880e8704ccf4c96a0180bd652e36110607 # Parent 16ceb32283244f17f2c7319fb77454268eb3beb2 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. diff -r 16ceb3228324 -r e29853880e87 demos/rio_de_hola/run.py --- a/demos/rio_de_hola/run.py Fri May 07 21:07:27 2010 +0000 +++ b/demos/rio_de_hola/run.py Fri May 07 21:46:25 2010 +0000 @@ -123,17 +123,6 @@ self.listener = ApplicationListener(self.engine, self.world) self.world.load(str(TDS.readSetting("MapFile"))) - self.soundmanager = self.engine.getSoundManager() - self.soundmanager.init() - - if int(TDS.readSetting("PlaySounds")): - # play track as background music - emitter = self.soundmanager.createEmitter() - id = self.engine.getSoundClipPool().addResourceFromFile('music/rio_de_hola.ogg') - emitter.setSoundClip(id) - emitter.setLooping(True) - emitter.play() - def loadSettings(self): """ Load the settings from a python file and load them into the engine. diff -r 16ceb3228324 -r e29853880e87 demos/rio_de_hola/scripts/world.py --- a/demos/rio_de_hola/scripts/world.py Fri May 07 21:07:27 2010 +0000 +++ b/demos/rio_de_hola/scripts/world.py Fri May 07 21:46:25 2010 +0000 @@ -29,6 +29,7 @@ from scripts.common.eventlistenerbase import EventListenerBase from fife.extensions.loaders import loadMapFile from fife.extensions.savers import saveMapFile +from fife.extensions.soundmanager import SoundManager from agents.hero import Hero from agents.girl import Girl from agents.cloud import Cloud @@ -82,6 +83,9 @@ self.instance_to_agent = {} self.dynamic_widgets = {} + self.soundmanager = SoundManager(self.engine) + self.music = None + def show_instancemenu(self, clickpoint, instance): """ Build and show a popupmenu for an instance that the player @@ -136,6 +140,9 @@ """ Clear the agent information and reset the moving secondary camera state. """ + if self.music: + self.music.stop() + self.map, self.agentlayer = None, None self.cameras = {} self.hero, self.girl, self.clouds, self.beekeepers = None, None, [], [] @@ -147,6 +154,7 @@ """ Load a xml map and setup agents and cameras. """ + self.filename = filename self.reset() self.map = loadMapFile(filename, self.engine) @@ -155,6 +163,18 @@ self.initAgents() self.initCameras() + if int(TDS.readSetting("PlaySounds")): + # play track as background music + self.music = self.soundmanager.createSoundEmitter('music/rio_de_hola.ogg') + self.music.looping = True + self.music.gain = 128.0 + self.music.play() + + self.waves = self.soundmanager.createSoundEmitter('sounds/waves.ogg') + self.waves.looping = True + self.waves.gain = 16.0 + self.waves.play() + def initAgents(self): """ Setup agents. diff -r 16ceb3228324 -r e29853880e87 engine/python/fife/extensions/soundmanager.py --- a/engine/python/fife/extensions/soundmanager.py Fri May 07 21:07:27 2010 +0000 +++ b/engine/python/fife/extensions/soundmanager.py Fri May 07 21:46:25 2010 +0000 @@ -212,7 +212,6 @@ @param clip The SoundEmitter to be played """ - if clip.fifeemitter: if clip.callback: if clip.timer: @@ -224,7 +223,7 @@ def real_callback(c, e, g): c() e.stop() - e.setGain(g) + e.setGain(float(g)/255.0) e.play() clip.callback = cbwa(real_callback, clip.callback, clip.fifeemitter, clip.gain) @@ -232,10 +231,21 @@ else: repeat = 1 - clip.timer = fife_timer.delayCall(clip.duration, clip.callback) - #clip.timer.start() + clip.timer = fife_timer.Timer(clip.duration, clip.callback, repeat) + clip.timer.start() + else: + if clip.looping: + def real_callback(e, g): + e.stop() + e.setGain(float(g)/255.0) + e.play() + + clip.callback = cbwa(real_callback, clip.fifeemitter, clip.gain) + clip.timer = fife_timer.Timer(clip.duration, clip.callback, 0) + clip.timer.start() + - clip.fifeemitter.setGain(clip.gain) + clip.fifeemitter.setGain(float(clip.gain)/255.0) clip.fifeemitter.play() else: clip = self.createSoundEmitter(clip.name)