annotate demos/shooter/scripts/soundmanager.py @ 487:7f1c42b66aa4

Moved the shooter demo Timer() class to helpers.py. Changed the formula that calculates the length of the audio clip to be correct. The shooter demo now demonstrates the use of the audio clip callbacks correctly. Fixed the fife_timer extension to actually work.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 03 May 2010 19:58:16 +0000
parents d365eb58f3d6
children 0324a3533988
rev   line source
480
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
1 # -*- coding: utf-8 -*-
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
2
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
3 # ####################################################################
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
4 # Copyright (C) 2005-2009 by the FIFE team
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
5 # http://www.fifengine.de
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
6 # This file is part of FIFE.
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
7 #
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
8 # FIFE is free software; you can redistribute it and/or
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
9 # modify it under the terms of the GNU Lesser General Public
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
10 # License as published by the Free Software Foundation; either
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
11 # version 2.1 of the License, or (at your option) any later version.
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
12 #
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
13 # This library is distributed in the hope that it will be useful,
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
16 # Lesser General Public License for more details.
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
17 #
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
18 # You should have received a copy of the GNU Lesser General Public
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
19 # License along with this library; if not, write to the
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
20 # Free Software Foundation, Inc.,
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
22 # ####################################################################
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
23
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
24 from fife import fife
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
25
487
7f1c42b66aa4 Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 485
diff changeset
26 from scripts.common.helpers import Timer
7f1c42b66aa4 Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 485
diff changeset
27 from fife.extensions.pychan.tools import callbackWithArguments as cbwa
485
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
28
483
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
29 class SoundClip(object):
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
30 def __init__(self, soundmanager, clipid, soundname, emitter):
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
31 self._soundmanager = soundmanager
481
1f37adc9a685 Added a SoundEmitter class that encapsulates the FIFE sound emitter. The SoundManager is now a factory for SoundEmitters. Also working on getting a callback going for when the sound is finished playing.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 480
diff changeset
32 self._name = soundname
1f37adc9a685 Added a SoundEmitter class that encapsulates the FIFE sound emitter. The SoundManager is now a factory for SoundEmitters. Also working on getting a callback going for when the sound is finished playing.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 480
diff changeset
33 self._fifeclipid = clipid
483
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
34 self._fifeemitter = emitter
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
35 self._fifeemitter.thisown = 0
481
1f37adc9a685 Added a SoundEmitter class that encapsulates the FIFE sound emitter. The SoundManager is now a factory for SoundEmitters. Also working on getting a callback going for when the sound is finished playing.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 480
diff changeset
36 self._gain = 255.0
483
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
37 self._looping = False
485
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
38 self._callback = None
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
39 self._duration = 0
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
40 self._timer = None
481
1f37adc9a685 Added a SoundEmitter class that encapsulates the FIFE sound emitter. The SoundManager is now a factory for SoundEmitters. Also working on getting a callback going for when the sound is finished playing.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 480
diff changeset
41
483
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
42 def _getClipID(self):
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
43 return self._fifeclipid
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
44
481
1f37adc9a685 Added a SoundEmitter class that encapsulates the FIFE sound emitter. The SoundManager is now a factory for SoundEmitters. Also working on getting a callback going for when the sound is finished playing.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 480
diff changeset
45 def _getGain(self):
1f37adc9a685 Added a SoundEmitter class that encapsulates the FIFE sound emitter. The SoundManager is now a factory for SoundEmitters. Also working on getting a callback going for when the sound is finished playing.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 480
diff changeset
46 return self._gain
1f37adc9a685 Added a SoundEmitter class that encapsulates the FIFE sound emitter. The SoundManager is now a factory for SoundEmitters. Also working on getting a callback going for when the sound is finished playing.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 480
diff changeset
47
1f37adc9a685 Added a SoundEmitter class that encapsulates the FIFE sound emitter. The SoundManager is now a factory for SoundEmitters. Also working on getting a callback going for when the sound is finished playing.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 480
diff changeset
48 def _setGain(self, gain):
1f37adc9a685 Added a SoundEmitter class that encapsulates the FIFE sound emitter. The SoundManager is now a factory for SoundEmitters. Also working on getting a callback going for when the sound is finished playing.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 480
diff changeset
49 self._gain = float(gain)
1f37adc9a685 Added a SoundEmitter class that encapsulates the FIFE sound emitter. The SoundManager is now a factory for SoundEmitters. Also working on getting a callback going for when the sound is finished playing.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 480
diff changeset
50
483
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
51 def _getLooping(self):
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
52 return self._looping
481
1f37adc9a685 Added a SoundEmitter class that encapsulates the FIFE sound emitter. The SoundManager is now a factory for SoundEmitters. Also working on getting a callback going for when the sound is finished playing.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 480
diff changeset
53
483
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
54 def _setLooping(self, looping):
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
55 self._looping = looping
481
1f37adc9a685 Added a SoundEmitter class that encapsulates the FIFE sound emitter. The SoundManager is now a factory for SoundEmitters. Also working on getting a callback going for when the sound is finished playing.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 480
diff changeset
56
1f37adc9a685 Added a SoundEmitter class that encapsulates the FIFE sound emitter. The SoundManager is now a factory for SoundEmitters. Also working on getting a callback going for when the sound is finished playing.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 480
diff changeset
57 def _getFifeEmitter(self):
1f37adc9a685 Added a SoundEmitter class that encapsulates the FIFE sound emitter. The SoundManager is now a factory for SoundEmitters. Also working on getting a callback going for when the sound is finished playing.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 480
diff changeset
58 return self._fifeemitter
1f37adc9a685 Added a SoundEmitter class that encapsulates the FIFE sound emitter. The SoundManager is now a factory for SoundEmitters. Also working on getting a callback going for when the sound is finished playing.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 480
diff changeset
59
1f37adc9a685 Added a SoundEmitter class that encapsulates the FIFE sound emitter. The SoundManager is now a factory for SoundEmitters. Also working on getting a callback going for when the sound is finished playing.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 480
diff changeset
60 def _setFifeEmitter(self, emitter):
1f37adc9a685 Added a SoundEmitter class that encapsulates the FIFE sound emitter. The SoundManager is now a factory for SoundEmitters. Also working on getting a callback going for when the sound is finished playing.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 480
diff changeset
61 self._fifeemitter = emitter
483
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
62 if self._fifeemitter:
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
63 self._fifeemitter.thisown = 0
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
64
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
65 def _getName(self):
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
66 return self._name
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
67
485
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
68 def _getCallback(self):
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
69 return self._callback
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
70
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
71 def _setCallback(self, cb):
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
72 self._callback = cb
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
73
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
74 def _getDuration(self):
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
75 return self._duration
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
76
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
77 def _setDuration(self, millliseconds):
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
78 self._duration = millliseconds
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
79
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
80 def _getTimer(self):
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
81 return self._timer
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
82
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
83 def _setTimer(self, timer):
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
84 self._timer = timer
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
85
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
86 timer = property(_getTimer, _setTimer)
481
1f37adc9a685 Added a SoundEmitter class that encapsulates the FIFE sound emitter. The SoundManager is now a factory for SoundEmitters. Also working on getting a callback going for when the sound is finished playing.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 480
diff changeset
87 clipid = property(_getClipID)
483
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
88 gain = property(_getGain, _setGain)
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
89 looping = property(_getLooping, _setLooping)
481
1f37adc9a685 Added a SoundEmitter class that encapsulates the FIFE sound emitter. The SoundManager is now a factory for SoundEmitters. Also working on getting a callback going for when the sound is finished playing.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 480
diff changeset
90 fifeemitter = property(_getFifeEmitter, _setFifeEmitter)
483
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
91 name = property(_getName)
485
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
92 callback = property(_getCallback, _setCallback)
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
93 duration = property(_getDuration, _setDuration)
481
1f37adc9a685 Added a SoundEmitter class that encapsulates the FIFE sound emitter. The SoundManager is now a factory for SoundEmitters. Also working on getting a callback going for when the sound is finished playing.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 480
diff changeset
94
480
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
95 class SoundManager(object):
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
96 def __init__(self, engine):
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
97 self._engine = engine
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
98
485
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
99 self._fifesoundmanager = self._engine.getSoundManager()
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
100 self._fifesoundmanager.init()
480
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
101
483
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
102 self._emitters = []
481
1f37adc9a685 Added a SoundEmitter class that encapsulates the FIFE sound emitter. The SoundManager is now a factory for SoundEmitters. Also working on getting a callback going for when the sound is finished playing.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 480
diff changeset
103 self._loadedclips = {}
483
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
104
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
105 def loadSoundClip(self, filename):
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
106 if not self._loadedclips.has_key(filename):
481
1f37adc9a685 Added a SoundEmitter class that encapsulates the FIFE sound emitter. The SoundManager is now a factory for SoundEmitters. Also working on getting a callback going for when the sound is finished playing.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 480
diff changeset
107 clipid = self._engine.getSoundClipPool().addResourceFromFile(filename)
485
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
108 fifeemitter = self._fifesoundmanager.createEmitter()
483
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
109 fifeemitter.thisown = 0
481
1f37adc9a685 Added a SoundEmitter class that encapsulates the FIFE sound emitter. The SoundManager is now a factory for SoundEmitters. Also working on getting a callback going for when the sound is finished playing.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 480
diff changeset
110 fifeemitter.setSoundClip(clipid)
485
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
111
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
112 time = fifeemitter.getDuration()
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
113
483
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
114 self._loadedclips[filename] = SoundClip(self, clipid, filename, fifeemitter)
487
7f1c42b66aa4 Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 485
diff changeset
115 self._loadedclips[filename].duration = time
483
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
116 self._emitters.append(fifeemitter)
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
117
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
118 return self._loadedclips[filename]
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
119
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
120 def playClip(self, clip):
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
121 if clip.fifeemitter:
485
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
122 if clip.callback:
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
123 if clip.timer:
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
124 clip.timer.stop()
487
7f1c42b66aa4 Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 485
diff changeset
125 timer = None
7f1c42b66aa4 Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 485
diff changeset
126
7f1c42b66aa4 Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 485
diff changeset
127 if clip.looping:
7f1c42b66aa4 Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 485
diff changeset
128 repeat = 0
7f1c42b66aa4 Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 485
diff changeset
129 print "setting up callback1"
7f1c42b66aa4 Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 485
diff changeset
130
7f1c42b66aa4 Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 485
diff changeset
131 def real_callback(c, e):
7f1c42b66aa4 Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 485
diff changeset
132 c()
7f1c42b66aa4 Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 485
diff changeset
133 print "in here"
7f1c42b66aa4 Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 485
diff changeset
134 e.stop()
7f1c42b66aa4 Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 485
diff changeset
135 e.play()
7f1c42b66aa4 Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 485
diff changeset
136
7f1c42b66aa4 Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 485
diff changeset
137 clip.callback = cbwa(real_callback, clip.callback, clip.fifeemitter)
7f1c42b66aa4 Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 485
diff changeset
138
7f1c42b66aa4 Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 485
diff changeset
139 else:
7f1c42b66aa4 Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 485
diff changeset
140 repeat = 1
7f1c42b66aa4 Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 485
diff changeset
141
7f1c42b66aa4 Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 485
diff changeset
142
7f1c42b66aa4 Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 485
diff changeset
143 clip.timer = Timer(self._engine.getTimeManager(), clip.duration, clip.callback, repeat)
485
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
144 clip.timer.start()
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
145
483
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
146 clip.fifeemitter.setGain(clip.gain)
487
7f1c42b66aa4 Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 485
diff changeset
147 #clip.fifeemitter.setLooping(clip.looping)
483
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
148 clip.fifeemitter.play()
480
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
149 else:
485
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
150 clip = self.loadSoundClip(clip.name)
487
7f1c42b66aa4 Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 485
diff changeset
151 self.playClip(clip)
483
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
152
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
153 def stopClip(self, clip):
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
154 if clip.fifeemitter:
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
155 clip.fifeemitter.stop()
485
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
156
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
157 if clip.timer:
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
158 clip.timer.stop()
487
7f1c42b66aa4 Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 485
diff changeset
159 clip.timer = None
481
1f37adc9a685 Added a SoundEmitter class that encapsulates the FIFE sound emitter. The SoundManager is now a factory for SoundEmitters. Also working on getting a callback going for when the sound is finished playing.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 480
diff changeset
160
1f37adc9a685 Added a SoundEmitter class that encapsulates the FIFE sound emitter. The SoundManager is now a factory for SoundEmitters. Also working on getting a callback going for when the sound is finished playing.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 480
diff changeset
161 def stopAllSounds(self):
485
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
162 for clip in self._loadedclips.values():
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
163 self.stopClip(clip)
480
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
164
85fa5fa486a8 Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
165 def destroy(self):
485
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
166 self.stopAllSounds()
483
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
167
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
168 for emitter in self._emitters[:]:
485
d365eb58f3d6 SoundClip can now fire a callback after a sound has completed being played (i.e. the duration of the sound has passed by). I have added an example of this with the scene music. [t:346]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 483
diff changeset
169 self._fifesoundmanager.releaseEmitter(emitter.getID())
483
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
170 self._emitters.remove(emitter)
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
171
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
172 for clip in self._loadedclips.values():
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
173 clip.fifeemitter = None
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
174
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
175
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
176 self._emitters = list()
82d44c471959 Modified the SoundManager to not create unique FIFE sound emitters for each object. There is now only one FIFE emitter per unique sound.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 481
diff changeset
177 self._loadedclips.clear()