1 | /* |
---|
2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * > www.orxonox.net < |
---|
4 | * |
---|
5 | * |
---|
6 | * License notice: |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU General Public License |
---|
10 | * as published by the Free Software Foundation; either version 2 |
---|
11 | * of the License, or (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
21 | * |
---|
22 | * Author: |
---|
23 | * Erwin 'vaiursch' Herrsche |
---|
24 | * Co-authors: |
---|
25 | * Reto Grieder |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | #ifndef _BaseSound_H__ |
---|
30 | #define _BaseSound_H__ |
---|
31 | |
---|
32 | #include "OrxonoxPrereqs.h" |
---|
33 | |
---|
34 | #include <string> |
---|
35 | #include <boost/shared_ptr.hpp> |
---|
36 | #include <OgreDataStream.h> |
---|
37 | #include "core/OrxonoxClass.h" |
---|
38 | |
---|
39 | namespace orxonox |
---|
40 | { |
---|
41 | // forward declaration |
---|
42 | class SoundBuffer; |
---|
43 | |
---|
44 | /** |
---|
45 | * The BaseSound class is the base class for all sound file loader classes. |
---|
46 | * It server as main interface to the OpenAL library. |
---|
47 | * |
---|
48 | */ |
---|
49 | class _OrxonoxExport BaseSound : virtual public OrxonoxClass |
---|
50 | { |
---|
51 | public: |
---|
52 | BaseSound(); |
---|
53 | |
---|
54 | void XMLPortExtern(Element& xmlelement, XMLPort::Mode mode); |
---|
55 | |
---|
56 | virtual void play() { this->doPlay(); } |
---|
57 | virtual void stop() { this->doStop(); } |
---|
58 | virtual void pause() { this->doPause(); } |
---|
59 | |
---|
60 | bool isPlaying() const { return this->state_ == Playing; } |
---|
61 | bool isPaused() const { return this->state_ == Paused; } |
---|
62 | bool isStopped() const { return this->state_ == Stopped; } |
---|
63 | |
---|
64 | virtual void setSource(const std::string& source); |
---|
65 | virtual const std::string& getSource() const |
---|
66 | { return this->source_; } |
---|
67 | |
---|
68 | void setVolume(float vol); |
---|
69 | float getVolume() const |
---|
70 | { return this->volume_; } |
---|
71 | void updateVolume(); |
---|
72 | |
---|
73 | bool getLooping() const |
---|
74 | { return this->bLooping_; } |
---|
75 | void setLooping(bool val); |
---|
76 | |
---|
77 | float getPitch() const |
---|
78 | { return this->pitch_; } |
---|
79 | void setPitch(float pitch); |
---|
80 | |
---|
81 | protected: |
---|
82 | enum State |
---|
83 | { |
---|
84 | Stopped, |
---|
85 | Playing, |
---|
86 | Paused |
---|
87 | }; |
---|
88 | |
---|
89 | virtual ~BaseSound(); |
---|
90 | |
---|
91 | void doPlay(); |
---|
92 | void doStop(); |
---|
93 | void doPause(); |
---|
94 | |
---|
95 | // network callbacks |
---|
96 | inline void pitchChanged() |
---|
97 | { this->setPitch(this->pitch_); } |
---|
98 | inline void loopingChanged() |
---|
99 | { this->setLooping(this->bLooping_); } |
---|
100 | inline void volumeChanged() |
---|
101 | { this->setVolume(this->volume_); } |
---|
102 | inline void sourceChanged() |
---|
103 | { this->setSource(this->source_); } |
---|
104 | void stateChanged(); |
---|
105 | |
---|
106 | virtual void initialiseSource(); |
---|
107 | ALint getSourceState() const; |
---|
108 | |
---|
109 | virtual float getRealVolume() = 0; |
---|
110 | |
---|
111 | ALuint audioSource_; |
---|
112 | bool bPooling_; |
---|
113 | shared_ptr<SoundBuffer> soundBuffer_; |
---|
114 | std::string source_; |
---|
115 | float volume_; |
---|
116 | bool bLooping_; |
---|
117 | State state_; |
---|
118 | float pitch_; |
---|
119 | |
---|
120 | private: |
---|
121 | DataStreamPtr dataStream_; |
---|
122 | }; |
---|
123 | } |
---|
124 | |
---|
125 | #endif /* _BaseSound_H__ */ |
---|