Mercurial > fife-parpg
annotate engine/python/fife/extensions/soundmanager.py @ 571:edc9efe969c2
This commit should fix the coloring overlay bug exposed by the commit in revision 3386. The InstanceRenderer was caching the overlays based on whether the current image had changed. The fix takes into account the current image as well as the overlay color to decide whether or not the overlay needs to be reproduced.
author | vtchill@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Tue, 29 Jun 2010 02:26:28 +0000 |
parents | 6614a5446352 |
children | 872a7a94563e |
rev | line source |
---|---|
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
2 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
3 # #################################################################### |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
4 # Copyright (C) 2005-2010 by the FIFE team |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
5 # http://www.fifengine.net |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
6 # This file is part of FIFE. |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
7 # |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
8 # FIFE is free software; you can redistribute it and/or |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
9 # modify it under the terms of the GNU Lesser General Public |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
10 # License as published by the Free Software Foundation; either |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
11 # version 2.1 of the License, or (at your option) any later version. |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
12 # |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
13 # This library is distributed in the hope that it will be useful, |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
16 # Lesser General Public License for more details. |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
17 # |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
18 # You should have received a copy of the GNU Lesser General Public |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
19 # License along with this library; if not, write to the |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
20 # Free Software Foundation, Inc., |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
22 # #################################################################### |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
23 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
24 """ |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
25 Sound Manager |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
26 ================================== |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
27 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
28 This is a simple implementation of a sound manager that was originaly |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
29 intended for the shooter demo. It was functional enough that we decided |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
30 to include it in the FIFE extensions. This is by no means a fully featured |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
31 implementation for several reasons. It doesnt limit how many sounds can |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
32 play at once or allow the positioning of sounds. It does however provide |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
33 a good starting point for a more advanced version of a sound manager. |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
34 |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
35 Usage:: |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
36 soundmanager = SoundManager(my_fife_engine) |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
37 |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
38 emitter = soundmanager.createSoundEmitter("path/filename.ogg") |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
39 emitter.gain = 128 |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
40 emitter.play() |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
41 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
42 """ |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
43 |
495
ae9f5383f5b1
Added a new log module called Script. This should be used by the python modules.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
44 from fife import fife |
ae9f5383f5b1
Added a new log module called Script. This should be used by the python modules.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
45 |
ae9f5383f5b1
Added a new log module called Script. This should be used by the python modules.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
46 import fife.extensions.fife_timer as fife_timer |
ae9f5383f5b1
Added a new log module called Script. This should be used by the python modules.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
47 from fife.extensions.pychan.tools import callbackWithArguments as cbwa |
ae9f5383f5b1
Added a new log module called Script. This should be used by the python modules.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
494
diff
changeset
|
48 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
49 class SoundEmitter(object): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
50 """ |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
51 Wraps the L{fife.SoundEmitter} class. |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
52 |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
53 This class wraps an instance of a L{fife.SoundEmitter} class along |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
54 with some information about a sound clip (like gain and if its |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
55 looping). All instances of SoundEmitter should be created by SoundManager. |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
56 |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
57 @todo: At some point this class will store positional information |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
58 and also be responsible for updating the L{fife.SoundEmitter} position. |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
59 """ |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
60 def __init__(self, soundmanager, clipid, soundname, emitter): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
61 """ |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
62 @param soundmanager: A reference to the SoundManager |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
63 @type soundmanager: L{SoundManager} |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
64 @param clipid: The FIFE sound clip ID from the sound clip pool |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
65 @type clipid: C{int} |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
66 @param soundname: The filename of the sound |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
67 @type soundname: C{string} |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
68 @param emitter: A reference to the L{fife.SoundEmitter} associated with this clip |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
69 @type emitter: L{fife.SoundEmitter} |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
70 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
71 """ |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
72 self._soundmanager = soundmanager |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
73 self._name = soundname |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
74 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
75 #The FIFE SoundEmitter associated with this SoundEmitter. |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
76 #Note that we do NOT own the emitter. |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
77 self._fifeemitter = emitter |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
78 self._fifeemitter.thisown = 0 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
79 self._fifeclipid = clipid |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
80 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
81 #0 = mute, 255 = normal volume |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
82 self._gain = 255.0 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
83 self._looping = False |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
84 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
85 #if you set the callback it will be executed after the sound |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
86 #has finished playing. |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
87 self._callback = None |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
88 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
89 #length of the sound |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
90 self._duration = 0 |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
91 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
92 self._timer = None |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
93 |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
94 self._position = None |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
95 self._rolloff = 0 |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
96 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
97 def play(self): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
98 self._soundmanager.playClip(self) |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
99 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
100 def stop(self): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
101 self._soundmanager.stopClip(self) |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
102 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
103 def _getClipID(self): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
104 return self._fifeclipid |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
105 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
106 def _getGain(self): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
107 return self._gain |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
108 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
109 def _setGain(self, gain): |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
110 """ |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
111 Sets the volume of the L{SoundEmitter}. |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
112 |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
113 @param gain: Value should be from 0-255. 0 being mute and 255 being the normal |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
114 volume of the clip. |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
115 @type gain: C{int} |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
116 """ |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
117 self._gain = float(gain) |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
118 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
119 def _getLooping(self): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
120 return self._looping |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
121 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
122 def _setLooping(self, looping): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
123 self._looping = looping |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
124 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
125 def _getFifeEmitter(self): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
126 return self._fifeemitter |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
127 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
128 def _setFifeEmitter(self, emitter): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
129 self._fifeemitter = emitter |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
130 if self._fifeemitter: |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
131 self._fifeemitter.thisown = 0 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
132 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
133 def _getName(self): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
134 return self._name |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
135 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
136 def _getCallback(self): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
137 return self._callback |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
138 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
139 def _setCallback(self, cb): |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
140 self._callback = cb |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
141 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
142 def _getDuration(self): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
143 return self._duration |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
144 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
145 def _setDuration(self, millliseconds): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
146 self._duration = millliseconds |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
147 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
148 def _getTimer(self): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
149 return self._timer |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
150 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
151 def _setTimer(self, timer): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
152 self._timer = timer |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
153 |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
154 def _setPosition(self, position): |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
155 self._position = position |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
156 |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
157 def _getPosition(self): |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
158 return self._position |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
159 |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
160 def _setRolloff(self, rolloff): |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
161 self._rolloff = rolloff |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
162 |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
163 def _getRolloff(self): |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
164 return self._rolloff |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
165 |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
166 rolloff = property(_getRolloff, _setRolloff) |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
167 position = property(_getPosition, _setPosition) |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
168 timer = property(_getTimer, _setTimer) |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
169 clipid = property(_getClipID) |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
170 gain = property(_getGain, _setGain) |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
171 looping = property(_getLooping, _setLooping) |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
172 fifeemitter = property(_getFifeEmitter, _setFifeEmitter) |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
173 name = property(_getName) |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
174 callback = property(_getCallback, _setCallback) |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
175 duration = property(_getDuration, _setDuration) |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
176 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
177 class SoundManager(object): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
178 """ |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
179 A simple sound manager class. |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
180 |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
181 This class manages and plays all the sounds of the game. |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
182 It creates SoundEmitters and ensures that there is only one |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
183 L{fife.SoundEmitter} per unique sound. |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
184 """ |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
185 def __init__(self, engine): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
186 """ |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
187 @param engine: A reference to the FIFE engine |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
188 @type engine: L{fife.Engine} |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
189 """ |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
190 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
191 self._engine = engine |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
192 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
193 self._fifesoundmanager = self._engine.getSoundManager() |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
194 self._fifesoundmanager.init() |
501
6614a5446352
Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
500
diff
changeset
|
195 |
6614a5446352
Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
500
diff
changeset
|
196 self._fifesoundmanager.setListenerOrientation(0,1,0) |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
197 |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
198 # basic rolloff used for positional sounds |
500
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
199 self._rolloff = 1 |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
200 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
201 #A dict of fife emitters |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
202 self._loadedclips = {} |
500
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
203 |
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
204 #A tuple representing the listener position (x,y) |
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
205 self._listenerposition = None |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
206 |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
207 def createSoundEmitter(self, filename, forceUnique=False, position=None): |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
208 """ |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
209 Returns a valid SoundEmitter instance. |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
210 |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
211 @param filename: The relative path and filename of the sound file |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
212 @type clip: C{string} |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
213 @param forceUnique: This forces a new L{fife.SoundEmitter} to be created. |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
214 This is useful if you want more than one instance of the same sound |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
215 to be played at the same time. |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
216 @type forceUnique: C{boolean} |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
217 @param position: The position on the map that the sound emitter |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
218 is to be created at. |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
219 @type position: L{tuple} |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
220 |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
221 @return: Returns a new L{SoundEmitter} instance. |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
222 @rtype: L{SoundEmitter} |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
223 """ |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
224 if not self._loadedclips.has_key(filename): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
225 clipid = self._engine.getSoundClipPool().addResourceFromFile(filename) |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
226 fifeemitter = self._fifesoundmanager.createEmitter() |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
227 fifeemitter.thisown = 0 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
228 fifeemitter.setSoundClip(clipid) |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
229 self._loadedclips[filename] = [fifeemitter] |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
230 clip = SoundEmitter(self, clipid, filename, fifeemitter) |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
231 clip.duration = fifeemitter.getDuration() |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
232 else: |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
233 if forceUnique: |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
234 clipid = self._engine.getSoundClipPool().addResourceFromFile(filename) |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
235 fifeemitter = self._fifesoundmanager.createEmitter() |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
236 fifeemitter.thisown = 0 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
237 fifeemitter.setSoundClip(clipid) |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
238 self._loadedclips[filename].append(fifeemitter) |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
239 else: |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
240 fifeemitter = self._loadedclips[filename][0] |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
241 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
242 clip = SoundEmitter(self, fifeemitter.getID(), filename, fifeemitter) |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
243 clip.duration = fifeemitter.getDuration() |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
244 |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
245 if position is not None: |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
246 clip.position = position |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
247 clip.rolloff = self.rolloff |
500
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
248 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
249 return clip |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
250 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
251 def playClip(self, clip): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
252 """ |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
253 Plays a sound clip. |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
254 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
255 This function does not use the L{fife.SoundEmitter} |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
256 "looping" property to loop a sound. Instead it registers |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
257 a new timer and uses the duration of the clip as the timer length. |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
258 |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
259 If the SoundEmitter is invalid (no fifeemitter) then it attempts |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
260 to load it before playing it. |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
261 |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
262 @note: This will stop any clips that use the same L{fife.SoundEmitter}. |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
263 You cannot play the same sound more than once at a time unless you create |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
264 the SoundEmitter with the forceUnique paramater set to True. |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
265 |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
266 @param clip: The L{SoundEmitter} to be played |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
267 @type clip: L{SoundEmitter} |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
268 """ |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
269 if clip.fifeemitter: |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
270 if clip.callback: |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
271 if clip.timer: |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
272 clip.timer.stop() |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
273 timer = None |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
274 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
275 if clip.looping: |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
276 repeat = 0 |
501
6614a5446352
Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
500
diff
changeset
|
277 def real_callback(clip): |
6614a5446352
Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
500
diff
changeset
|
278 clip.callback() |
6614a5446352
Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
500
diff
changeset
|
279 clip.fifeemitter.stop() |
6614a5446352
Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
500
diff
changeset
|
280 clip.fifeemitter.setGain(float(clip.gain)/255.0) |
6614a5446352
Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
500
diff
changeset
|
281 if self.listenerposition and clip.position: |
6614a5446352
Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
500
diff
changeset
|
282 # Use 1 as z coordinate, no need to specify it |
6614a5446352
Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
500
diff
changeset
|
283 clip.fifeemitter.setPosition(clip.position[0], clip.position[1], 1) |
6614a5446352
Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
500
diff
changeset
|
284 clip.fifeemitter.setRolloff(clip.rolloff) |
6614a5446352
Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
500
diff
changeset
|
285 elif self.listenerposition and not clip.position: |
6614a5446352
Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
500
diff
changeset
|
286 clip.fifeemitter.setPosition(self._listenerposition[0], self._listenerposition[1], 1) |
6614a5446352
Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
500
diff
changeset
|
287 clip.fifeemitter.setRolloff(self.rolloff) |
6614a5446352
Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
500
diff
changeset
|
288 |
6614a5446352
Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
500
diff
changeset
|
289 clip.fifeemitter.play() |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
290 |
501
6614a5446352
Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
500
diff
changeset
|
291 clip.callback = cbwa(real_callback, clip) |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
292 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
293 else: |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
294 repeat = 1 |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
295 |
493
e29853880e87
Adapted rio_do_hola to use the new SoundManager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
296 clip.timer = fife_timer.Timer(clip.duration, clip.callback, repeat) |
500
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
297 |
493
e29853880e87
Adapted rio_do_hola to use the new SoundManager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
298 else: |
e29853880e87
Adapted rio_do_hola to use the new SoundManager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
299 if clip.looping: |
501
6614a5446352
Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
500
diff
changeset
|
300 def real_callback(clip): |
6614a5446352
Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
500
diff
changeset
|
301 clip.fifeemitter.stop() |
6614a5446352
Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
500
diff
changeset
|
302 clip.fifeemitter.setGain(float(clip.gain)/255.0) |
6614a5446352
Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
500
diff
changeset
|
303 if self.listenerposition and clip.position: |
6614a5446352
Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
500
diff
changeset
|
304 # Use 1 as z coordinate, no need to specify it |
6614a5446352
Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
500
diff
changeset
|
305 clip.fifeemitter.setPosition(clip.position[0], clip.position[1], 1) |
6614a5446352
Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
500
diff
changeset
|
306 clip.fifeemitter.setRolloff(clip.rolloff) |
6614a5446352
Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
500
diff
changeset
|
307 elif self.listenerposition and not clip.position: |
6614a5446352
Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
500
diff
changeset
|
308 clip.fifeemitter.setPosition(self._listenerposition[0], self._listenerposition[1], 1) |
6614a5446352
Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
500
diff
changeset
|
309 clip.fifeemitter.setRolloff(self.rolloff) |
6614a5446352
Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
500
diff
changeset
|
310 |
6614a5446352
Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
500
diff
changeset
|
311 clip.fifeemitter.play() |
493
e29853880e87
Adapted rio_do_hola to use the new SoundManager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
312 |
501
6614a5446352
Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
500
diff
changeset
|
313 clip.callback = cbwa(real_callback, clip) |
493
e29853880e87
Adapted rio_do_hola to use the new SoundManager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
314 clip.timer = fife_timer.Timer(clip.duration, clip.callback, 0) |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
315 |
493
e29853880e87
Adapted rio_do_hola to use the new SoundManager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
316 clip.fifeemitter.setGain(float(clip.gain)/255.0) |
500
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
317 |
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
318 if self.listenerposition and clip.position: |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
319 # Use 1 as z coordinate, no need to specify it |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
320 clip.fifeemitter.setPosition(clip.position[0], clip.position[1], 1) |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
321 clip.fifeemitter.setRolloff(clip.rolloff) |
500
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
322 elif self.listenerposition and not clip.position: |
501
6614a5446352
Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
500
diff
changeset
|
323 clip.fifeemitter.setPosition(self._listenerposition[0], self._listenerposition[1], 1) |
500
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
324 clip.fifeemitter.setRolloff(self.rolloff) |
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
325 |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
326 clip.fifeemitter.play() |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
327 if clip.timer: |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
328 clip.timer.start() |
500
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
329 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
330 else: |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
331 clip = self.createSoundEmitter(clip.name) |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
332 self.playClip(clip) |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
333 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
334 def stopClip(self, clip): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
335 """ |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
336 Stops playing the sound clip. Note that this will stop all clips that |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
337 use the same FIFE emitter. |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
338 |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
339 @param clip: The SoundEmitter to stop. |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
340 @type clip: L{SoundEmitter} |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
341 """ |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
342 if clip.fifeemitter: |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
343 clip.fifeemitter.stop() |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
344 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
345 if clip.timer: |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
346 clip.timer.stop() |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
347 clip.timer = None |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
348 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
349 def stopAllSounds(self): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
350 for emitterlist in self._loadedclips.values(): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
351 for emitter in emitterlist: |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
352 emitter.stop() |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
353 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
354 def destroy(self): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
355 """ |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
356 Releases all instances of L{fife.SoundEmitter}. |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
357 |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
358 @note: This does not free the resources from the FIFE sound clip pool. |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
359 """ |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
360 self.stopAllSounds() |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
361 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
362 for emitterlist in self._loadedclips.values(): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
363 for emitter in emitterlist: |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
364 self._fifesoundmanager.releaseEmitter(emitter.getID()) |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
365 emitter = None |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
366 |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
367 self._loadedclips.clear() |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
368 |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
369 def _getRolloff(self): |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
370 return self._rolloff |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
371 |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
372 def _setRolloff(self, rolloff): |
500
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
373 self._rolloff = rolloff |
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
374 |
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
375 def _getListenerPosition(self): |
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
376 return self._listenerposition |
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
377 |
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
378 def _setListenerPosition(self, position): |
501
6614a5446352
Positional sounds now work. There are some odd things happening when the sound does not have positional data and I assign the listeners position to the emitters position. There is a little more work required here.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
500
diff
changeset
|
379 self._listenerposition = position |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
380 self._fifesoundmanager.setListenerPosition(self._listenerposition[0], self._listenerposition[1], 10) |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
381 |
500
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
382 rolloff = property(_getRolloff, _setRolloff) |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
383 listenerposition = property(_getListenerPosition, _setListenerPosition) |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
384 |