[3060] | 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: |
---|
[5896] | 23 | * Erwin 'vaiursch' Herrsche |
---|
[3060] | 24 | * Co-authors: |
---|
[5896] | 25 | * Reto Grieder |
---|
[3060] | 26 | * |
---|
| 27 | */ |
---|
[6417] | 28 | |
---|
[5896] | 29 | #ifndef _BaseSound_H__ |
---|
| 30 | #define _BaseSound_H__ |
---|
[3060] | 31 | |
---|
[8007] | 32 | #include "sound/SoundPrereqs.h" |
---|
[3060] | 33 | |
---|
[5896] | 34 | #include <string> |
---|
[6417] | 35 | #include <boost/shared_ptr.hpp> |
---|
[5904] | 36 | #include <OgreDataStream.h> |
---|
[5896] | 37 | #include "core/OrxonoxClass.h" |
---|
| 38 | |
---|
[3060] | 39 | namespace orxonox |
---|
| 40 | { |
---|
| 41 | /** |
---|
[5896] | 42 | * The BaseSound class is the base class for all sound file loader classes. |
---|
[7854] | 43 | * It serves as main interface to the OpenAL library. |
---|
[3060] | 44 | */ |
---|
[5896] | 45 | class _OrxonoxExport BaseSound : virtual public OrxonoxClass |
---|
[3060] | 46 | { |
---|
| 47 | public: |
---|
[5896] | 48 | BaseSound(); |
---|
[3060] | 49 | |
---|
[6417] | 50 | void XMLPortExtern(Element& xmlelement, XMLPort::Mode mode); |
---|
[3060] | 51 | |
---|
[6417] | 52 | virtual void play() { this->doPlay(); } |
---|
[7856] | 53 | virtual bool stop() { return this->doStop(); } // returns true if the sound source was destroyed |
---|
[6417] | 54 | virtual void pause() { this->doPause(); } |
---|
[3060] | 55 | |
---|
[6417] | 56 | bool isPlaying() const { return this->state_ == Playing; } |
---|
| 57 | bool isPaused() const { return this->state_ == Paused; } |
---|
| 58 | bool isStopped() const { return this->state_ == Stopped; } |
---|
[3060] | 59 | |
---|
[6417] | 60 | virtual void setSource(const std::string& source); |
---|
| 61 | virtual const std::string& getSource() const |
---|
| 62 | { return this->source_; } |
---|
[5896] | 63 | |
---|
[6417] | 64 | void setVolume(float vol); |
---|
| 65 | float getVolume() const |
---|
| 66 | { return this->volume_; } |
---|
| 67 | void updateVolume(); |
---|
[5896] | 68 | |
---|
[6417] | 69 | bool getLooping() const |
---|
| 70 | { return this->bLooping_; } |
---|
| 71 | void setLooping(bool val); |
---|
| 72 | |
---|
| 73 | float getPitch() const |
---|
| 74 | { return this->pitch_; } |
---|
| 75 | void setPitch(float pitch); |
---|
| 76 | |
---|
[5896] | 77 | protected: |
---|
[6417] | 78 | enum State |
---|
| 79 | { |
---|
| 80 | Stopped, |
---|
| 81 | Playing, |
---|
| 82 | Paused |
---|
| 83 | }; |
---|
[5896] | 84 | |
---|
[6417] | 85 | virtual ~BaseSound(); |
---|
[3060] | 86 | |
---|
[8007] | 87 | virtual void doPlay(); |
---|
| 88 | virtual bool doStop(); // returns true if the sound source was destroyed |
---|
| 89 | virtual void doPause(); |
---|
[6417] | 90 | |
---|
| 91 | // network callbacks |
---|
| 92 | inline void pitchChanged() |
---|
| 93 | { this->setPitch(this->pitch_); } |
---|
| 94 | inline void loopingChanged() |
---|
| 95 | { this->setLooping(this->bLooping_); } |
---|
| 96 | inline void volumeChanged() |
---|
| 97 | { this->setVolume(this->volume_); } |
---|
| 98 | inline void sourceChanged() |
---|
| 99 | { this->setSource(this->source_); } |
---|
| 100 | void stateChanged(); |
---|
| 101 | |
---|
| 102 | virtual void initialiseSource(); |
---|
| 103 | ALint getSourceState() const; |
---|
| 104 | |
---|
| 105 | virtual float getRealVolume() = 0; |
---|
| 106 | |
---|
| 107 | ALuint audioSource_; |
---|
| 108 | bool bPooling_; |
---|
| 109 | shared_ptr<SoundBuffer> soundBuffer_; |
---|
| 110 | std::string source_; |
---|
| 111 | float volume_; |
---|
| 112 | bool bLooping_; |
---|
[7163] | 113 | uint8_t state_; // This Variable is actually of type State |
---|
[6417] | 114 | float pitch_; |
---|
| 115 | |
---|
[5896] | 116 | private: |
---|
[6417] | 117 | DataStreamPtr dataStream_; |
---|
[5896] | 118 | }; |
---|
| 119 | } |
---|
[3060] | 120 | |
---|
[5896] | 121 | #endif /* _BaseSound_H__ */ |
---|