Mercurial > fife-parpg
annotate demos/shooter/scripts/soundmanager.py @ 490:939a4dc12ca1
Starting to add some comments.
Cleaned up some old commented out code.
The SoundManager now creates a new SoundClip rather than only creating one per FIFE SoundEmitter.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Wed, 05 May 2010 21:39:31 +0000 |
parents | 0324a3533988 |
children | c4168eb47a44 |
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): |
490
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
30 """ |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
31 SoundClip |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
32 |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
33 This class stores an instance of a FIFE SoundEmitter class along |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
34 with some information about a sound clip (like gain and if its |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
35 looping). All instances of SoundClip should be created by SoundManager. |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
36 """ |
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 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
|
38 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
|
39 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
|
40 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
|
41 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
|
42 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
|
43 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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 |
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
|
49 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
|
50 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
|
51 |
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
|
52 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
|
53 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
|
54 |
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
|
55 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
|
56 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
|
57 |
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
|
58 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
|
59 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
|
60 |
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
|
61 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
|
62 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
|
63 |
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
|
64 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
|
65 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
|
66 |
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
|
67 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
|
68 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
|
69 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
|
70 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
|
71 |
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
|
72 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
|
73 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
|
74 |
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
|
75 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
|
76 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
|
77 |
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 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
|
79 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
|
80 |
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 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
|
82 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
|
83 |
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 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
|
85 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
|
86 |
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
|
87 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
|
88 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
|
89 |
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
|
90 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
|
91 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
|
92 |
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 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
|
94 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
|
95 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
|
96 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
|
97 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
|
98 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
|
99 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
|
100 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
|
101 |
480
85fa5fa486a8
Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
102 class SoundManager(object): |
490
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
103 """ |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
104 SoundManger |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
105 |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
106 This class manages and plays all the sounds of the game. |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
107 It creates SoundClips and ensures that there is only one |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
108 FIFE SoundEmitter per unique sound. |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
109 """ |
480
85fa5fa486a8
Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
110 def __init__(self, engine): |
85fa5fa486a8
Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
111 self._engine = engine |
85fa5fa486a8
Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
112 |
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
|
113 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
|
114 self._fifesoundmanager.init() |
480
85fa5fa486a8
Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
115 |
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
|
116 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
|
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 def loadSoundClip(self, filename): |
490
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
119 """ |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
120 Returns a valid SoundClip instance. |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
121 """ |
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
|
122 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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 |
490
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
128 self._loadedclips[filename] = fifeemitter |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
129 clip = SoundClip(self, clipid, filename, fifeemitter) |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
130 clip.duration = fifeemitter.getDuration() |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
131 else: |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
132 fifeemitter = self._loadedclips[filename] |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
133 clip = SoundClip(self, fifeemitter.getID(), filename, fifeemitter) |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
134 clip.duration = fifeemitter.getDuration() |
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
|
135 |
490
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
136 return 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
|
137 |
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
|
138 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
|
139 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
|
140 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
|
141 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
|
142 clip.timer.stop() |
487
7f1c42b66aa4
Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
485
diff
changeset
|
143 timer = None |
7f1c42b66aa4
Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
485
diff
changeset
|
144 |
7f1c42b66aa4
Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
485
diff
changeset
|
145 if clip.looping: |
7f1c42b66aa4
Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
485
diff
changeset
|
146 repeat = 0 |
490
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
147 def real_callback(c, e, g): |
487
7f1c42b66aa4
Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
485
diff
changeset
|
148 c() |
7f1c42b66aa4
Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
485
diff
changeset
|
149 e.stop() |
490
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
150 e.setGain(g) |
487
7f1c42b66aa4
Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
485
diff
changeset
|
151 e.play() |
7f1c42b66aa4
Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
485
diff
changeset
|
152 |
490
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
153 clip.callback = cbwa(real_callback, clip.callback, clip.fifeemitter, clip.gain) |
487
7f1c42b66aa4
Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
485
diff
changeset
|
154 |
7f1c42b66aa4
Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
485
diff
changeset
|
155 else: |
7f1c42b66aa4
Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
485
diff
changeset
|
156 repeat = 1 |
7f1c42b66aa4
Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
485
diff
changeset
|
157 |
7f1c42b66aa4
Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
485
diff
changeset
|
158 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
|
159 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
|
160 |
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
|
161 clip.fifeemitter.setGain(clip.gain) |
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
|
162 clip.fifeemitter.play() |
480
85fa5fa486a8
Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
163 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
|
164 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
|
165 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
|
166 |
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 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
|
168 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
|
169 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
|
170 |
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
|
171 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
|
172 clip.timer.stop() |
487
7f1c42b66aa4
Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
485
diff
changeset
|
173 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
|
174 |
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
|
175 def stopAllSounds(self): |
490
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
176 for emitter in self._loadedclips.values(): |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
177 emitter.stop() |
480
85fa5fa486a8
Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
178 |
85fa5fa486a8
Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
179 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
|
180 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
|
181 |
490
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
182 for emitter in self._loadedclips.values(): |
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
|
183 self._fifesoundmanager.releaseEmitter(emitter.getID()) |
490
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
184 emitter = None |
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
|
185 |
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
|
186 self._loadedclips.clear() |