Mercurial > fife-parpg
annotate engine/python/fife/extensions/soundmanager.py @ 656:99e3ef63495b
* The RPG and Shooter demos now clear the screen when in OpenGL mode
* Small update to the soundmanager to stop the stack overflow problem.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Fri, 22 Oct 2010 16:01:57 +0000 |
parents | 2851e232a113 |
children |
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 |
651
2851e232a113
* Modified the sound manager to better take care of sound clips. (Hope this fixes the crash at the end of the shooter demo)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
575
diff
changeset
|
96 |
2851e232a113
* Modified the sound manager to better take care of sound clips. (Hope this fixes the crash at the end of the shooter demo)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
575
diff
changeset
|
97 def __del__(self): |
2851e232a113
* Modified the sound manager to better take care of sound clips. (Hope this fixes the crash at the end of the shooter demo)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
575
diff
changeset
|
98 self._soundmanager.unregisterClip(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 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
|
101 self._soundmanager.playClip(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 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
|
104 self._soundmanager.stopClip(self) |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
105 |
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
|
106 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
|
107 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
|
108 |
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 _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
|
110 return self._gain |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
111 |
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
|
112 def _setGain(self, gain): |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
113 """ |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
114 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
|
115 |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
116 @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
|
117 volume of the clip. |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
118 @type gain: C{int} |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
119 """ |
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
|
120 self._gain = float(gain) |
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 _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
|
123 return self._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 _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
|
126 self._looping = looping |
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 _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
|
129 return self._fifeemitter |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
130 |
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
|
131 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
|
132 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
|
133 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
|
134 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
|
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 _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
|
137 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
|
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 _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
|
140 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
|
141 |
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 _setCallback(self, cb): |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
143 self._callback = cb |
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 _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
|
146 return self._duration |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
147 |
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
|
148 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
|
149 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
|
150 |
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 _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
|
152 return self._timer |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
153 |
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
|
154 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
|
155 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
|
156 |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
157 def _setPosition(self, position): |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
158 self._position = 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 _getPosition(self): |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
161 return self._position |
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 _setRolloff(self, rolloff): |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
164 self._rolloff = 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 def _getRolloff(self): |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
167 return self._rolloff |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
168 |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
169 rolloff = property(_getRolloff, _setRolloff) |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
170 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
|
171 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
|
172 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
|
173 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
|
174 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
|
175 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
|
176 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
|
177 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
|
178 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
|
179 |
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 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
|
181 """ |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
182 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
|
183 |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
184 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
|
185 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
|
186 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
|
187 """ |
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
|
188 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
|
189 """ |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
190 @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
|
191 @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
|
192 """ |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
193 |
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
|
194 self._engine = engine |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
195 |
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
|
196 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
|
197 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
|
198 |
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
|
199 self._fifesoundmanager.setListenerOrientation(0,1,0) |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
200 |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
201 # basic rolloff used for positional sounds |
500
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
202 self._rolloff = 1 |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
203 |
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
|
204 #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
|
205 self._loadedclips = {} |
500
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
206 |
651
2851e232a113
* Modified the sound manager to better take care of sound clips. (Hope this fixes the crash at the end of the shooter demo)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
575
diff
changeset
|
207 #A list of created clips |
2851e232a113
* Modified the sound manager to better take care of sound clips. (Hope this fixes the crash at the end of the shooter demo)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
575
diff
changeset
|
208 self._soundclips = [] |
2851e232a113
* Modified the sound manager to better take care of sound clips. (Hope this fixes the crash at the end of the shooter demo)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
575
diff
changeset
|
209 |
500
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
210 #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
|
211 self._listenerposition = None |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
212 |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
213 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
|
214 """ |
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 Returns a valid SoundEmitter instance. |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
216 |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
217 @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
|
218 @type clip: C{string} |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
219 @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
|
220 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
|
221 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
|
222 @type forceUnique: C{boolean} |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
223 @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
|
224 is to be created at. |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
225 @type position: L{tuple} |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
226 |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
227 @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
|
228 @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
|
229 """ |
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 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
|
231 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
|
232 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
|
233 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
|
234 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
|
235 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
|
236 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
|
237 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
|
238 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
|
239 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
|
240 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
|
241 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
|
242 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
|
243 fifeemitter.setSoundClip(clipid) |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
244 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
|
245 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
|
246 fifeemitter = self._loadedclips[filename][0] |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
247 |
575
872a7a94563e
- Updated the soundmanager extension to reflect changes made in last commit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
501
diff
changeset
|
248 clip = SoundEmitter(self, fifeemitter.getId(), filename, 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
|
249 clip.duration = fifeemitter.getDuration() |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
250 |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
251 if position is not None: |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
252 clip.position = position |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
253 clip.rolloff = self.rolloff |
651
2851e232a113
* Modified the sound manager to better take care of sound clips. (Hope this fixes the crash at the end of the shooter demo)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
575
diff
changeset
|
254 |
2851e232a113
* Modified the sound manager to better take care of sound clips. (Hope this fixes the crash at the end of the shooter demo)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
575
diff
changeset
|
255 self._soundclips.append(clip) |
2851e232a113
* Modified the sound manager to better take care of sound clips. (Hope this fixes the crash at the end of the shooter demo)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
575
diff
changeset
|
256 |
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 return clip |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
258 |
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
|
259 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
|
260 """ |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
261 Plays a sound clip. |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
262 |
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 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
|
264 "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
|
265 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
|
266 |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
267 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
|
268 to load it before playing it. |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
269 |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
270 @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
|
271 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
|
272 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
|
273 |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
274 @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
|
275 @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
|
276 """ |
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
|
277 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
|
278 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
|
279 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
|
280 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
|
281 timer = None |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
282 |
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
|
283 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
|
284 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
|
285 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
|
286 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
|
287 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
|
288 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
|
289 # 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
|
290 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
|
291 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
|
292 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
|
293 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
|
294 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
|
295 |
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
|
296 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
|
297 |
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
|
298 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
|
299 |
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
|
300 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
|
301 repeat = 1 |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
302 |
493
e29853880e87
Adapted rio_do_hola to use the new SoundManager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
303 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
|
304 |
493
e29853880e87
Adapted rio_do_hola to use the new SoundManager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
305 else: |
e29853880e87
Adapted rio_do_hola to use the new SoundManager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
306 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
|
307 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
|
308 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
|
309 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
|
310 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
|
311 # 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
|
312 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
|
313 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
|
314 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
|
315 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
|
316 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
|
317 |
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
|
318 clip.fifeemitter.play() |
493
e29853880e87
Adapted rio_do_hola to use the new SoundManager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
319 |
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
|
320 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
|
321 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
|
322 |
493
e29853880e87
Adapted rio_do_hola to use the new SoundManager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
323 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
|
324 |
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
325 if self.listenerposition and clip.position: |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
326 # 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
|
327 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
|
328 clip.fifeemitter.setRolloff(clip.rolloff) |
500
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
329 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
|
330 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
|
331 clip.fifeemitter.setRolloff(self.rolloff) |
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
332 |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
333 clip.fifeemitter.play() |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
334 if clip.timer: |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
335 clip.timer.start() |
500
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
336 |
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 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
|
338 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
|
339 self.playClip(clip) |
651
2851e232a113
* Modified the sound manager to better take care of sound clips. (Hope this fixes the crash at the end of the shooter demo)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
575
diff
changeset
|
340 |
2851e232a113
* Modified the sound manager to better take care of sound clips. (Hope this fixes the crash at the end of the shooter demo)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
575
diff
changeset
|
341 def unregisterClip(self, clip): |
2851e232a113
* Modified the sound manager to better take care of sound clips. (Hope this fixes the crash at the end of the shooter demo)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
575
diff
changeset
|
342 self.stopClip(clip) |
2851e232a113
* Modified the sound manager to better take care of sound clips. (Hope this fixes the crash at the end of the shooter demo)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
575
diff
changeset
|
343 |
2851e232a113
* Modified the sound manager to better take care of sound clips. (Hope this fixes the crash at the end of the shooter demo)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
575
diff
changeset
|
344 if clip in self._soundclips: |
2851e232a113
* Modified the sound manager to better take care of sound clips. (Hope this fixes the crash at the end of the shooter demo)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
575
diff
changeset
|
345 self._soundclips.remove(clip) |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
346 |
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
|
347 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
|
348 """ |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
349 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
|
350 use the same FIFE emitter. |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
351 |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
352 @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
|
353 @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
|
354 """ |
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 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
|
356 clip.fifeemitter.stop() |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
357 |
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
|
358 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
|
359 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
|
360 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
|
361 |
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 def stopAllSounds(self): |
651
2851e232a113
* Modified the sound manager to better take care of sound clips. (Hope this fixes the crash at the end of the shooter demo)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
575
diff
changeset
|
363 for clip in self._soundclips: |
2851e232a113
* Modified the sound manager to better take care of sound clips. (Hope this fixes the crash at the end of the shooter demo)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
575
diff
changeset
|
364 self.stopClip(clip) |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
365 |
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
|
366 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
|
367 """ |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
368 Releases all instances of L{fife.SoundEmitter}. |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
369 |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
493
diff
changeset
|
370 @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
|
371 """ |
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
|
372 self.stopAllSounds() |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
373 |
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
|
374 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
|
375 for emitter in emitterlist: |
575
872a7a94563e
- Updated the soundmanager extension to reflect changes made in last commit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
501
diff
changeset
|
376 self._fifesoundmanager.releaseEmitter(emitter.getId()) |
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
|
377 emitter = None |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
378 |
651
2851e232a113
* Modified the sound manager to better take care of sound clips. (Hope this fixes the crash at the end of the shooter demo)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
575
diff
changeset
|
379 self._loadedclips.clear() |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
380 |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
381 def _getRolloff(self): |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
382 return self._rolloff |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
383 |
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
384 def _setRolloff(self, rolloff): |
500
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
385 self._rolloff = rolloff |
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
386 |
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
387 def _getListenerPosition(self): |
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
388 return self._listenerposition |
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
389 |
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
390 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
|
391 self._listenerposition = position |
498
5ff83f209333
Added positioning to the soundmanager classes
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
495
diff
changeset
|
392 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
|
393 |
500
5e6ff32a46fb
Added listener position to the soundmanager.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
498
diff
changeset
|
394 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
|
395 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
|
396 |