Otclient  14/8/2020
soundsource.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 OTClient <https://github.com/edubart/otclient>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 #ifndef SOUNDSOURCE_H
24 #define SOUNDSOURCE_H
25 
26 #include "declarations.h"
27 #include "soundbuffer.h"
29 
30 class SoundSource : public LuaObject
31 {
32 protected:
33  SoundSource(uint sourceId) : m_sourceId(sourceId) { }
34 
35 public:
37 
38  SoundSource();
39  virtual ~SoundSource();
40 
41  virtual void play();
42  virtual void stop();
43 
44  virtual bool isBuffering();
45  virtual bool isPlaying() { return isBuffering(); }
46 
47  void setName(const std::string& name) { m_name = name; }
48  virtual void setLooping(bool looping);
49  virtual void setRelative(bool relative);
50  virtual void setReferenceDistance(float distance);
51  virtual void setGain(float gain);
52  virtual void setPitch(float pitch);
53  virtual void setPosition(const Point& pos);
54  virtual void setVelocity(const Point& velocity);
55  virtual void setFading(FadeState state, float fadetime);
56 
57  std::string getName() { return m_name; }
58  uchar getChannel() { return m_channel; }
59  float getGain() { return m_gain; }
60 
61 protected:
62  void setBuffer(const SoundBufferPtr& buffer);
63  void setChannel(uchar channel) { m_channel = channel; }
64 
65  virtual void update();
66  friend class SoundManager;
67  friend class CombinedSoundSource;
68 
71  std::string m_name;
75  float m_fadeTime;
76  float m_fadeGain;
77  float m_gain;
78 };
79 
80 #endif
SoundSource::NoFading
@ NoFading
Definition: soundsource.h:36
SoundSource::m_fadeTime
float m_fadeTime
Definition: soundsource.h:75
SoundSource
Definition: soundsource.h:30
SoundSource::getGain
float getGain()
Definition: soundsource.h:59
SoundSource::~SoundSource
virtual ~SoundSource()
Definition: soundsource.cpp:43
SoundSource::FadeState
FadeState
Definition: soundsource.h:36
SoundSource::FadingOff
@ FadingOff
Definition: soundsource.h:36
SoundSource::isBuffering
virtual bool isBuffering()
Definition: soundsource.cpp:69
SoundSource::m_fadeStartTime
float m_fadeStartTime
Definition: soundsource.h:74
SoundSource::isPlaying
virtual bool isPlaying()
Definition: soundsource.h:45
soundbuffer.h
SoundSource::FadingOn
@ FadingOn
Definition: soundsource.h:36
SoundSource::getChannel
uchar getChannel()
Definition: soundsource.h:58
luaobject.h
SoundSource::setFading
virtual void setFading(FadeState state, float fadetime)
Definition: soundsource.cpp:119
SoundSource::setVelocity
virtual void setVelocity(const Point &velocity)
Definition: soundsource.cpp:114
uint
unsigned int uint
Definition: types.h:31
SoundSource::m_channel
uchar m_channel
Definition: soundsource.h:70
SoundSource::setReferenceDistance
virtual void setReferenceDistance(float distance)
Definition: soundsource.cpp:93
SoundSource::m_buffer
SoundBufferPtr m_buffer
Definition: soundsource.h:72
SoundManager
Definition: soundmanager.h:30
SoundSource::stop
virtual void stop()
Definition: soundsource.cpp:58
SoundSource::play
virtual void play()
Definition: soundsource.cpp:52
SoundSource::m_sourceId
uint m_sourceId
Definition: soundsource.h:69
SoundSource::m_fadeGain
float m_fadeGain
Definition: soundsource.h:76
SoundSource::m_fadeState
FadeState m_fadeState
Definition: soundsource.h:73
SoundSource::setName
void setName(const std::string &name)
Definition: soundsource.h:47
declarations.h
SoundSource::SoundSource
SoundSource(uint sourceId)
Definition: soundsource.h:33
SoundSource::setGain
virtual void setGain(float gain)
Definition: soundsource.cpp:98
SoundSource::setChannel
void setChannel(uchar channel)
Definition: soundsource.h:63
SoundSource::setPitch
virtual void setPitch(float pitch)
Definition: soundsource.cpp:104
SoundSource::setPosition
virtual void setPosition(const Point &pos)
Definition: soundsource.cpp:109
SoundSource::m_gain
float m_gain
Definition: soundsource.h:77
uchar
unsigned char uchar
Definition: types.h:29
SoundSource::setLooping
virtual void setLooping(bool looping)
Definition: soundsource.cpp:83
SoundSource::SoundSource
SoundSource()
Definition: soundsource.cpp:28
SoundSource::setBuffer
void setBuffer(const SoundBufferPtr &buffer)
Definition: soundsource.cpp:76
stdext::shared_object_ptr< SoundBuffer >
SoundSource::update
virtual void update()
Definition: soundsource.cpp:141
TPoint< int >
LuaObject
LuaObject, all script-able classes have it as base.
Definition: luaobject.h:30
SoundSource::setRelative
virtual void setRelative(bool relative)
Definition: soundsource.cpp:88
SoundSource::m_name
std::string m_name
Definition: soundsource.h:71
CombinedSoundSource
Definition: combinedsoundsource.h:28
SoundSource::getName
std::string getName()
Definition: soundsource.h:57