| 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 | virtual ~BaseSound(); |
|---|
| 54 | |
|---|
| 55 | void XMLPortExtern(Element& xmlelement, XMLPort::Mode mode); |
|---|
| 56 | |
|---|
| 57 | virtual void play(); |
|---|
| 58 | virtual void stop(); |
|---|
| 59 | virtual void pause(); |
|---|
| 60 | |
|---|
| 61 | bool isPlaying() const { return this->state_ == Playing; } |
|---|
| 62 | bool isPaused() const { return this->state_ == Paused; } |
|---|
| 63 | bool isStopped() const { return this->state_ == Stopped; } |
|---|
| 64 | |
|---|
| 65 | void setPlaying(bool val) |
|---|
| 66 | { val ? this->play() : this->stop(); } |
|---|
| 67 | |
|---|
| 68 | virtual void setSource(const std::string& source); |
|---|
| 69 | virtual const std::string& getSource() const |
|---|
| 70 | { return this->source_; } |
|---|
| 71 | |
|---|
| 72 | void setVolume(float vol); |
|---|
| 73 | float getVolume() const |
|---|
| 74 | { return this->volume_; } |
|---|
| 75 | void updateVolume(); |
|---|
| 76 | |
|---|
| 77 | bool getLooping() const |
|---|
| 78 | { return this->bLooping_; } |
|---|
| 79 | void setLooping(bool val); |
|---|
| 80 | |
|---|
| 81 | float getPitch() const |
|---|
| 82 | { return this->pitch_; } |
|---|
| 83 | void setPitch(float pitch); |
|---|
| 84 | |
|---|
| 85 | protected: |
|---|
| 86 | enum State |
|---|
| 87 | { |
|---|
| 88 | Stopped, |
|---|
| 89 | Playing, |
|---|
| 90 | Paused |
|---|
| 91 | }; |
|---|
| 92 | |
|---|
| 93 | // network callbacks |
|---|
| 94 | inline void pitchChanged() |
|---|
| 95 | { this->setPitch(this->pitch_); } |
|---|
| 96 | inline void loopingChanged() |
|---|
| 97 | { this->setLooping(this->bLooping_); } |
|---|
| 98 | inline void volumeChanged() |
|---|
| 99 | { this->setVolume(this->volume_); } |
|---|
| 100 | inline void sourceChanged() |
|---|
| 101 | { this->setSource(this->source_); } |
|---|
| 102 | void stateChanged(); |
|---|
| 103 | |
|---|
| 104 | virtual void initialiseSource(); |
|---|
| 105 | ALint getSourceState() const; |
|---|
| 106 | |
|---|
| 107 | virtual float getRealVolume() = 0; |
|---|
| 108 | |
|---|
| 109 | ALuint audioSource_; |
|---|
| 110 | bool bPooling_; |
|---|
| 111 | shared_ptr<SoundBuffer> soundBuffer_; |
|---|
| 112 | std::string source_; |
|---|
| 113 | float volume_; |
|---|
| 114 | bool bLooping_; |
|---|
| 115 | State state_; |
|---|
| 116 | float pitch_; |
|---|
| 117 | |
|---|
| 118 | private: |
|---|
| 119 | DataStreamPtr dataStream_; |
|---|
| 120 | }; |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | #endif /* _BaseSound_H__ */ |
|---|