Orxonox  0.0.5 Codename: Arcturus
BaseSound.h
Go to the documentation of this file.
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 <memory>
36 #include <OgreDataStream.h>
37 #include "core/object/Listable.h"
38 
39 namespace orxonox
40 {
45  class _OrxonoxExport BaseSound : virtual public Listable
46  {
47  public:
48  BaseSound();
49 
50  void XMLPortExtern(Element& xmlelement, XMLPort::Mode mode);
51 
52  virtual void play() { this->doPlay(); }
53  virtual bool stop() { return this->doStop(); } // returns true if the sound source was destroyed
54  virtual void pause() { this->doPause(); }
55 
56  bool isPlaying() const { return this->state_ == State::Playing; }
57  bool isPaused() const { return this->state_ == State::Paused; }
58  bool isStopped() const { return this->state_ == State::Stopped; }
59 
60  virtual void setSource(const std::string& source);
61  virtual const std::string& getSource() const
62  { return this->source_; }
63 
64  void setVolume(float vol);
65  float getVolume() const
66  { return this->volume_; }
67  void updateVolume();
68 
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 
77  protected:
78  enum class State
79  {
80  Stopped,
81  Playing,
82  Paused
83  };
84 
85  virtual ~BaseSound();
86 
87  void doPlay();
88  bool doStop(); // returns true if the sound source was destroyed
89  void doPause();
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 
108  bool bPooling_;
109  std::shared_ptr<SoundBuffer> soundBuffer_;
111  float volume_;
112  bool bLooping_;
113  State state_; // This Variable is actually of type State
114  float pitch_;
115 
116  private:
118  };
119 }
120 
121 #endif /* _BaseSound_H__ */
void pitchChanged()
Definition: BaseSound.h:92
void source(const std::string &filename)
Reads the content of a file and executes the commands in it line by line.
Definition: ConsoleCommandCompilation.cc:167
bool getLooping() const
Definition: BaseSound.h:69
State
Definition: BaseSound.h:78
Listable stores the entries of all object lists pointing to this instance.
Definition: Listable.h:50
virtual bool stop()
Definition: BaseSound.h:53
::std::string string
Definition: gtest-port.h:756
float getPitch() const
Definition: BaseSound.h:73
The BaseSound class is the base class for all sound file loader classes.
Definition: BaseSound.h:45
float pitch_
Definition: BaseSound.h:114
bool bLooping_
Definition: BaseSound.h:112
xmlelement
Definition: Super.h:519
bool bPooling_
Definition: BaseSound.h:108
void sourceChanged()
Definition: BaseSound.h:98
DataStreamPtr dataStream_
Definition: BaseSound.h:117
SharedPtr< DataStream > DataStreamPtr
Definition: CorePrereqs.h:365
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
Mode
Definition: CorePrereqs.h:102
float getVolume() const
Definition: BaseSound.h:65
bool isStopped() const
Definition: BaseSound.h:58
void volumeChanged()
Definition: BaseSound.h:96
Shared library macros, enums, constants and forward declarations for the orxonox library ...
std::string source_
Definition: BaseSound.h:110
bool isPaused() const
Definition: BaseSound.h:57
virtual void play()
Definition: BaseSound.h:52
Declaration of Listable, the base of all classes whose instances can be stored in object lists...
#define _OrxonoxExport
Definition: OrxonoxPrereqs.h:60
ALuint audioSource_
Definition: BaseSound.h:107
virtual void pause()
Definition: BaseSound.h:54
void loopingChanged()
Definition: BaseSound.h:94
std::shared_ptr< SoundBuffer > soundBuffer_
Definition: BaseSound.h:109
int ALint
Definition: OrxonoxPrereqs.h:223
unsigned int ALuint
Definition: OrxonoxPrereqs.h:222
virtual const std::string & getSource() const
Definition: BaseSound.h:61
bool isPlaying() const
Definition: BaseSound.h:56
State state_
Definition: BaseSound.h:113
float volume_
Definition: BaseSound.h:111