zenilib: zenilib/jni/external/zenilib/zeni_audio/Zeni/Sound_Source_Pool.h Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Sound_Source_Pool.h
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2 * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3 *
4 * zenilib is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * zenilib is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16 */
17
35 #ifndef ZENI_SOUND_SOURCE_POOL_H
36 #define ZENI_SOUND_SOURCE_POOL_H
37
38 #include <Zeni/Singleton.h>
39 #include <Zeni/Sound_Source.h>
40
41 #include <vector>
42
43 #include <Zeni/Define.h>
44
45 namespace Zeni {
46
47 class Sound_Source_Pool;
48
49 #ifdef _WINDOWS
50 ZENI_AUDIO_EXT template class ZENI_AUDIO_DLL Singleton<Sound_Source_Pool>;
51 #endif
52
53 class ZENI_AUDIO_DLL Sound_Source_Pool : public Singleton<Sound_Source_Pool> {
54 friend class Singleton<Sound_Source_Pool>;
55 friend class Sound_Source;
56 friend ZENI_AUDIO_DLL void play_sound(
57 const String &sound_name,
58 const float &pitch,
59 const float &gain,
60 const Point3f &position,
61 const Vector3f &velocity);
62
63 static Sound_Source_Pool * create();
64
65 #ifdef _WINDOWS
66 #pragma warning( push )
67 #pragma warning( disable : 4251 )
68 #endif
69 static Uninit g_uninit;
70 static Reinit g_reinit;
71 #ifdef _WINDOWS
72 #pragma warning( pop )
73 #endif
74
75 Sound_Source_Pool();
76 ~Sound_Source_Pool();
77
78 // Undefined
79 Sound_Source_Pool(const Sound_Source_Pool &);
80 Sound_Source_Pool & operator=(const Sound_Source_Pool &);
81
82 public:
83 class ZENI_AUDIO_DLL Replacement_Policy {
84 public:
85 virtual ~Replacement_Policy() {};
86
88 virtual bool operator()(const Sound_Source &lhs, const Sound_Source &rhs) const;
89
90 bool operator()(const Sound_Source * const &lhs, const Sound_Source * const &rhs) const;
91 };
92
93 class ZENI_AUDIO_DLL Positional_Replacement_Policy : public Replacement_Policy {
94 public:
95 Positional_Replacement_Policy(const Point3f &listener_position_);
96
98 virtual bool operator()(const Sound_Source &lhs, const Sound_Source &rhs) const;
99
100 Point3f listener_position;
101 };
102
103 const Replacement_Policy & get_Replacement_Policy() const;
104 void give_Replacement_Policy(Replacement_Policy * const &replacement_policy);
105 void lend_Replacement_Policy(Replacement_Policy * const &replacement_policy);
106
107 void pause_all();
108 void unpause_all();
109 void purge();
110
111 void update();
112
113 private:
114 void play_and_destroy(Sound_Source * const &sound_source);
115
116 void set_Replacement_Policy(Replacement_Policy * const &replacement_policy);
117 void insert_Sound_Source(Sound_Source &sound_source); // on Sound_Source construction
118 void remove_Sound_Source(Sound_Source &sound_source); // on Sound_Source destruction
119
120 void destroy_all_hw();
121
122 #ifdef _WINDOWS
123 #pragma warning( push )
124 #pragma warning( disable : 4251 )
125 #endif
126 std::vector<Sound_Source *> m_handles;
127 std::vector<Sound_Source *> m_playing_and_destroying;
128 #ifdef _WINDOWS
129 #pragma warning( pop )
130 #endif
131
132 Replacement_Policy * m_replacement_policy;
133 bool delete_m_replacement_policy;
134
135 bool m_muted;
136 };
137
138 ZENI_AUDIO_DLL Sound_Source_Pool & get_Sound_Source_Pool();
139
143 ZENI_AUDIO_DLL void play_sound(
144 const String &sound_name,
145 const float &pitch = ZENI_DEFAULT_PITCH,
146 const float &gain = ZENI_DEFAULT_GAIN,
147 const Point3f &position = Point3f(),
148 const Vector3f &velocity = Vector3f());
149
150 }
151
152 #include <Zeni/Undefine.h>
153
154 #endif
Zeni::Sound_Source_Pool::Positional_Replacement_Policy
Definition: Sound_Source_Pool.h:93
Zeni::Singleton< Sound_Source_Pool >
Zeni::get_Sound_Source_Pool
Sound_Source_Pool & get_Sound_Source_Pool()
Get access to the singleton.
Definition: Sound_Source_Pool.cpp:347
Sound_Source.h
ZENI_DEFAULT_PITCH
#define ZENI_DEFAULT_PITCH
Definition: Define.h:54
Undefine.h
ZENI_DEFAULT_GAIN
#define ZENI_DEFAULT_GAIN
Definition: Define.h:55
Zeni::String
Definition: String.h:29
Zeni::Point3f
A 3D Point represented with floats.
Definition: Coordinate.h:133
Zeni::Sound_Source
Plays Sound Data.
Definition: Sound_Source.h:147
Zeni::Vector3f
A Featureful 3-Space Vector Class.
Definition: Vector3f.h:58
Zeni::Sound_Source_Pool::Positional_Replacement_Policy::listener_position
Point3f listener_position
Definition: Sound_Source_Pool.h:100
Define.h
Singleton.h
Zeni::Sound_Source_Pool
This class manages Sound_Sources.
Definition: Sound_Source_Pool.h:53
Zeni::Sound_Source_Pool::Replacement_Policy
Definition: Sound_Source_Pool.h:83
Zeni::Sound_Source_Pool::Replacement_Policy::~Replacement_Policy
virtual ~Replacement_Policy()
Definition: Sound_Source_Pool.h:85
Zeni::play_sound
void play_sound(const String &sound_name, const float &pitch, const float &gain, const Point3f &position, const Vector3f &velocity)
Definition: Sound_Source_Pool.cpp:351
Zeni::Sound_Source_Pool::Sound_Source
friend class Sound_Source
Definition: Sound_Source_Pool.h:55