Cafu Engine
MixerTrack.hpp
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
6 
7 #ifndef CAFU_SOUNDSYS_MIXER_TRACK_HPP_INCLUDED
8 #define CAFU_SOUNDSYS_MIXER_TRACK_HPP_INCLUDED
9 
10 #include "OpenALIncl.hpp"
11 
12 #include <string>
13 
14 
15 class SoundImplT;
16 
17 
18 /// A mixer track represents/encapsulates/abstracs an OpenAL sound source.
19 /// Playing a sound assigns a mixer track to the sound (and the sounds buffer to the mixer track).
20 /// A mixer track can only be assigned to and play back one sound at a time.
21 /// Mixer tracks are a limited resource; they are reused and managed by the MixerTrackManT singleton.
23 {
24  public:
25 
26  /// The constructor. Throws an exception of type std::runtime_error on failure.
27  MixerTrackT();
28 
29  /// The destructor. Stops the sound, detaches, and releases the OpenAL source.
30  ~MixerTrackT();
31 
32  /// Plays a sound.
33  /// The previously assigned sound is stopped and detached, the new sound is attached and played.
34  /// @param Sound The sound to play.
35  /// @returns whether the attempt to play the sound was succesful.
36  bool Play(SoundImplT* Sound);
37 
38  /// Pauses the currently played sound.
39  void Pause();
40 
41  /// Resumes a previously paused sound.
42  void Resume();
43 
44  /// Stops the currently played sound and detaches it from this mixer track.
45  void StopAndDetach();
46 
47  /// Checks if this mixer track is playing the sound currently attached to it.
48  /// @return Whether the sound is currently playing.
49  bool IsPlaying();
50 
51  /// Checks if this mixer track is currently used the sound currently attached to it.
52  /// This is more general than IsPlaying() since it also returns mixer tracks as used if the
53  /// sound attached to them is not playing but paused. Stopped sounds will result don't mark
54  /// a mixer track as used.
55  /// @return Whether the mixer track is currently used.
56  bool IsUsed();
57 
58  /// Returns information about the priority of the currently played sound object.
59  /// @return Priority of the currently played sound object. Higher values mean higher priority.
60  unsigned int GetPriority();
61 
62  /// Updates the mixer track according to the attached sound.
63  /// Updated attributes include the position, velocity and direction, as well as shader attributes
64  /// like the minimal distance, the volume, etc.
65  void Update();
66 
67  /// Returns the handle to the OpenAL "source" that is encapsulated by this mixer track.
68  ALuint GetOpenALSource() const { return m_SourceHandle; }
69 
70 
71  private:
72 
73  MixerTrackT(const MixerTrackT&); ///< Use of the Copy Constructor is not allowed.
74  void operator = (const MixerTrackT&); ///< Use of the Assignment Operator is not allowed.
75 
76  SoundImplT* m_Sound; ///< The sound that is currently attached (but not necessarily played) to the mixer track.
77  ALuint m_SourceHandle; ///< The OpenAL source handle encapsulated by this mixer track.
78 };
79 
80 #endif
bool IsUsed()
Checks if this mixer track is currently used the sound currently attached to it.
Definition: MixerTrack.cpp:105
A mixer track represents/encapsulates/abstracs an OpenAL sound source.
Definition: MixerTrack.hpp:22
MixerTrackT()
The constructor. Throws an exception of type std::runtime_error on failure.
Definition: MixerTrack.cpp:15
OpenAL implementation of the SoundI interface.
Definition: SoundImpl.hpp:21
bool Play(SoundImplT *Sound)
Plays a sound.
Definition: MixerTrack.cpp:38
void Update()
Updates the mixer track according to the attached sound.
Definition: MixerTrack.cpp:124
void Resume()
Resumes a previously paused sound.
Definition: MixerTrack.cpp:68
void Pause()
Pauses the currently played sound.
Definition: MixerTrack.cpp:59
unsigned int GetPriority()
Returns information about the priority of the currently played sound object.
Definition: MixerTrack.cpp:116
void StopAndDetach()
Stops the currently played sound and detaches it from this mixer track.
Definition: MixerTrack.cpp:77
ALuint GetOpenALSource() const
Returns the handle to the OpenAL "source" that is encapsulated by this mixer track.
Definition: MixerTrack.hpp:68
~MixerTrackT()
The destructor. Stops the sound, detaches, and releases the OpenAL source.
Definition: MixerTrack.cpp:29
bool IsPlaying()
Checks if this mixer track is playing the sound currently attached to it.
Definition: MixerTrack.cpp:93