Planeshift
handle.h
Go to the documentation of this file.
1 /*
2  * handle.h
3  *
4  * Copyright (C) 2001-2010 Atomic Blue (info@planeshift.it, http://www.planeshift.it)
5  *
6  * Credits : Saul Leite <leite@engineer.com>
7  * Mathias 'AgY' Voeroes <agy@operswithoutlife.net>
8  * and all past and present planeshift coders
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation (version 2 of the License.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  *
22  */
23 
24 #ifndef _SOUND_HANDLE_H_
25 #define _SOUND_HANDLE_H_
26 
27 
28 //====================================================================================
29 // Crystal Space Includes
30 //====================================================================================
31 #include <crystalspace.h>
32 
33 //====================================================================================
34 // Local Includes
35 //====================================================================================
36 #include "soundctrl.h"
37 
38 //------------------------------------------------------------------------------------
39 // Forward Declarations
40 //------------------------------------------------------------------------------------
41 class SoundSystemManager;
42 
43 
44 enum
45 {
46  FADE_DOWN = 0,
47  FADE_UP = 1,
48  FADE_STOP = -1
49 };
50 
51 class SoundHandle: public scfImplementation1<SoundHandle, iTimerEvent>, public iSoundControlListener
52 {
53 public:
54  csString name;
56 
57  csRef<iSndSysData> snddata;
58  csRef<iSndSysStream> sndstream;
59  csRef<iSndSysSource> sndsource;
60  csRef<iSndSysSource3D> sndsource3d;
61  csRef<iSndSysSource3DDirectionalSimple> sndsourcedir;
62 
63  SoundHandle();
64  virtual ~SoundHandle();
65 
72  void Fade(float volume, int time, int direction);
73 
77  void FadeStep();
78 
89  virtual bool Init(const char* resname, bool loop,
90  float volume_preset, int type,
91  SoundControl* &ctrl, bool dopplerEffect);
92 
96  virtual bool Perform(iTimerEvent* /*ev*/);
97 
108  void ConvertTo3D(float mindist, float maxdist,
109  csVector3 pos, csVector3 dir,
110  float rad);
111 
116  bool Is3D();
117 
122  bool IsDopplerEffectEnabled();
123 
129  bool IsWithinMaximumDistance(csVector3 listenerPos) const;
130 
135  uint GetID() const { return id; }
136 
141  void SetID(uint identifier) { id = identifier; }
142 
149  csVector3 GetSourcePosition();
150 
157  void SetAutoRemove(bool toggle);
158 
162  bool GetAutoRemove();
163 
168  void UnpauseAfterDelay(unsigned int delay);
169 
175  void SetCallback(void (*object), void (*function) (void *));
179  void RemoveCallback();
180 
181  // From iSoundControlListener
182  //----------------------------
183  virtual void OnSoundChange(SoundControl* sndCtrl);
184 
185 protected:
188 
189 private:
190  uint id;
191  int fadeSteps;
192  bool fadeStop;
193  float maxDistance;
194  bool hasCallback;
195  void (*callbackobject);
196  void (*callbackfunction) (void *);
197 
198  bool autoremove;
199  bool delayActive;
200 
205  void Callback();
206 
207 };
208 
209 #endif /*_SOUND_HANDLE_H_*/
Interface to implement to handle SoundControl&#39;s events.
Definition: soundctrl.h:49
bool GetAutoRemove()
Returns state of AutoRemove.
bool Is3D()
Detects if the source of this handle is 3D.
csRef< iSndSysSource3D > sndsource3d
sndsource if 3D
Definition: handle.h:54
void SetCallback(void(*object), void(*function)(void *))
Sets a Callback to a object function.
uint GetID() const
Gets the ID of this handle.
Definition: handle.h:135
void Fade(float volume, int time, int direction)
Does fading calculation for this Handle.
csRef< iSndSysSource3DDirectionalSimple > sndsourcedir
additional source if 3D and directional
Definition: handle.h:55
virtual void OnSoundChange(SoundControl *sndCtrl)
This function is called everytime the volume or the toggle change.
void FadeStep()
Perform a fading step if it is needed.
csRef< iSndSysStream > sndstream
sound stream
Definition: handle.h:52
bool autoremove
remove this handle when pause?
Definition: handle.h:49
void RemoveCallback()
Remove the callback.
void SetID(uint identifier)
Sets the ID of this handle.
Definition: handle.h:141
bool IsDopplerEffectEnabled()
Check if the doppler effect is enabled for this sound.
bool IsWithinMaximumDistance(csVector3 listenerPos) const
Check if the listener is within the maximum distance allowed.
virtual bool Perform(iTimerEvent *)
Unpause the sound after the given delay has elapsed.
Definition: handle.h:36
SoundControl * sndCtrl
Definition: handle.h:44
csString name
name of the resource or the file - not unique
Definition: handle.h:43
A Volume and Sound control class.
Definition: control.h:40
csRef< iSndSysData > snddata
pointer to sound data
Definition: handle.h:51
void ConvertTo3D(float mindist, float maxdist, csVector3 pos, csVector3 dir, float rad)
Converts this Handle to a 3D Handle.
void UnpauseAfterDelay(unsigned int delay)
Unpause the sound stream of this header after the given delay.
~SoundHandle()
destructor
bool Init(const char *resname, bool loop, float volume_preset, int type, SoundControl *&ctrl)
Initialize this Handle.
SoundHandle()
constructor
csRef< iSndSysSource > sndsource
sndsource if 2D
Definition: handle.h:53
bool dopplerEffect
true if the doppler effect is enabled for this sound
Definition: handle.h:186
This Manager Object is used to play all sounds.
Definition: manager.h:62
float currentVolume
the volume all calculations are based upon.
Definition: handle.h:187
void SetAutoRemove(bool toggle)
Whether to remove this Sound/Handle on pause.
csVector3 GetSourcePosition()
Gets the position of the source.