Mercurial > fife-parpg
annotate demos/shooter/scripts/soundmanager.py @ 491:c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Thu, 06 May 2010 19:34:21 +0000 |
parents | 939a4dc12ca1 |
children |
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 # #################################################################### |
491
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
4 # Copyright (C) 2005-2010 by the FIFE team |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
5 # http://www.fifengine.net |
480
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): |
491
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
38 """ |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
39 @param soundmanager A reference to the SoundManager |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
40 @param clipid The FIFE sound clip ID from the sound clip pool |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
41 @param soundname The filename of the sound |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
42 @param emitter A reference to the FIFE SoundEmitter associated with this clip |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
43 |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
44 """ |
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
|
45 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
|
46 self._name = soundname |
491
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
47 |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
48 #The FIFE SoundEmitter associated with this SoundClip. |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
49 #Note that we do NOT own the 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
|
50 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
|
51 self._fifeemitter.thisown = 0 |
491
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
52 self._fifeclipid = clipid |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
53 |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
54 #0 = mute, 255 = normal volume |
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
|
55 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
|
56 self._looping = False |
491
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
57 |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
58 #if you set the callback it will be executed after the sound |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
59 #has finished playing. |
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
|
60 self._callback = None |
491
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
61 |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
62 #length of the sound |
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
|
63 self._duration = 0 |
491
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
64 |
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
|
65 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
|
66 |
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
|
67 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
|
68 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
|
69 |
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
|
70 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
|
71 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
|
72 |
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
|
73 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
|
74 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
|
75 |
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
|
76 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
|
77 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
|
78 |
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
|
79 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
|
80 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
|
81 |
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
|
82 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
|
83 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
|
84 |
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
|
85 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
|
86 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
|
87 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
|
88 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
|
89 |
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
|
90 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
|
91 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
|
92 |
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
|
93 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
|
94 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
|
95 |
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
|
96 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
|
97 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
|
98 |
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 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
|
100 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
|
101 |
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
|
102 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
|
103 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
|
104 |
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
|
105 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
|
106 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
|
107 |
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 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
|
109 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
|
110 |
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 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
|
112 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
|
113 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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 |
480
85fa5fa486a8
Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
120 class SoundManager(object): |
490
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
121 """ |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
122 SoundManger |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
123 |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
124 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
|
125 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
|
126 FIFE SoundEmitter per unique sound. |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
127 """ |
480
85fa5fa486a8
Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
128 def __init__(self, engine): |
491
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
129 """ |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
130 @param engine A reference to the FIFE engine |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
131 """ |
480
85fa5fa486a8
Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
132 self._engine = engine |
85fa5fa486a8
Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
133 |
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
|
134 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
|
135 self._fifesoundmanager.init() |
480
85fa5fa486a8
Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
136 |
491
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
137 #A dict of fife 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
|
138 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
|
139 |
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
|
140 def loadSoundClip(self, filename): |
490
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
141 """ |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
142 Returns a valid SoundClip instance. |
491
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
143 |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
144 @param filename the relative path and filename of the sound file |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
145 |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
146 @return Returns a new SoundClip instance. |
490
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
147 """ |
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 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
|
149 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
|
150 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
|
151 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
|
152 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
|
153 |
490
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
154 self._loadedclips[filename] = fifeemitter |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
155 clip = SoundClip(self, clipid, filename, fifeemitter) |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
156 clip.duration = fifeemitter.getDuration() |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
157 else: |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
158 fifeemitter = self._loadedclips[filename] |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
159 clip = SoundClip(self, fifeemitter.getID(), filename, fifeemitter) |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
160 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
|
161 |
490
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
162 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
|
163 |
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
|
164 def playClip(self, clip): |
491
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
165 """ |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
166 Plays a sound clip. |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
167 |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
168 This function does not use the FIFE |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
169 emitters "looping" property to loop a sound. Instead |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
170 it registers a new timer and uses the duration of the |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
171 clip as the timer length. |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
172 |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
173 If the SoundClip is invalid (no fifeemitter) then |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
174 it attempts to load it before playing it. |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
175 |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
176 Note that this will stop any clips that use the same |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
177 FIFE emitter. You cannot play the same sound more than |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
178 once at a time. |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
179 |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
180 @param clip The SoundClip to be played |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
181 """ |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
182 |
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
|
183 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
|
184 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
|
185 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
|
186 clip.timer.stop() |
487
7f1c42b66aa4
Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
485
diff
changeset
|
187 timer = None |
7f1c42b66aa4
Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
485
diff
changeset
|
188 |
7f1c42b66aa4
Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
485
diff
changeset
|
189 if clip.looping: |
7f1c42b66aa4
Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
485
diff
changeset
|
190 repeat = 0 |
490
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
191 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
|
192 c() |
7f1c42b66aa4
Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
485
diff
changeset
|
193 e.stop() |
490
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
194 e.setGain(g) |
487
7f1c42b66aa4
Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
485
diff
changeset
|
195 e.play() |
7f1c42b66aa4
Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
485
diff
changeset
|
196 |
490
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
197 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
|
198 |
7f1c42b66aa4
Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
485
diff
changeset
|
199 else: |
7f1c42b66aa4
Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
485
diff
changeset
|
200 repeat = 1 |
7f1c42b66aa4
Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
485
diff
changeset
|
201 |
7f1c42b66aa4
Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
485
diff
changeset
|
202 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
|
203 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
|
204 |
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
|
205 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
|
206 clip.fifeemitter.play() |
480
85fa5fa486a8
Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
207 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
|
208 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
|
209 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
|
210 |
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
|
211 def stopClip(self, clip): |
491
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
212 """ |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
213 Stops playing the sound clip. Note that this will |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
214 affect all clips that use the same FIFE emitter. |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
215 |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
216 @parm clip The SoundClip to stop. |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
217 """ |
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
|
218 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
|
219 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
|
220 |
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
|
221 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
|
222 clip.timer.stop() |
487
7f1c42b66aa4
Moved the shooter demo Timer() class to helpers.py.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
485
diff
changeset
|
223 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
|
224 |
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
|
225 def stopAllSounds(self): |
490
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
226 for emitter in self._loadedclips.values(): |
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
227 emitter.stop() |
480
85fa5fa486a8
Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
228 |
85fa5fa486a8
Added a simple sound manager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
229 def destroy(self): |
491
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
230 """ |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
231 Releases all FIFE emitters. This does not free the resources |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
232 from the FIFE sound clip pool. |
c4168eb47a44
Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
490
diff
changeset
|
233 """ |
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
|
234 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
|
235 |
490
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
236 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
|
237 self._fifesoundmanager.releaseEmitter(emitter.getID()) |
490
939a4dc12ca1
Starting to add some comments.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
489
diff
changeset
|
238 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
|
239 |
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
|
240 self._loadedclips.clear() |