-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSoundEvent.cpp
120 lines (105 loc) · 2.18 KB
/
SoundEvent.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "SoundEvent.h"
#include "AudioSystem.h"
#include "fmod_studio.hpp"
SoundEvent::SoundEvent(AudioSystem* system, unsigned int ID) : mSystem(system)
,mID(ID)
{
}
SoundEvent::SoundEvent() : mSystem(nullptr)
,mID(0)
{}
bool SoundEvent::IsValid()
{
return (mSystem && mSystem->GetEventInstance(mID) != nullptr);
}
void SoundEvent::Restart()
{
auto event = mSystem ? mSystem->GetEventInstance(mID) : nullptr;
if (event)
{
event->start();
}
}
void SoundEvent::Stop(bool allowFadeOut)
{
auto event = mSystem ? mSystem->GetEventInstance(mID) : nullptr;
if (event)
{
FMOD_STUDIO_STOP_MODE mode = allowFadeOut ?
FMOD_STUDIO_STOP_ALLOWFADEOUT :
FMOD_STUDIO_STOP_IMMEDIATE;
event->stop(mode);
}
}
void SoundEvent::SetPaused(bool pause)
{
auto event = mSystem ? mSystem->GetEventInstance(mID) : nullptr;
if (event)
{
event->setPaused(pause);
}
}
void SoundEvent::SetVolume(float value)
{
auto event = mSystem ? mSystem->GetEventInstance(mID) : nullptr;
if (event)
{
event->setVolume(value);
}
}
void SoundEvent::SetPitch(float value)
{
auto event = mSystem ? mSystem->GetEventInstance(mID) : nullptr;
if (event)
{
event->setPitch(value);
}
}
void SoundEvent::SetParameter(const std::string& name, float value)
{
auto event = mSystem ? mSystem->GetEventInstance(mID) : nullptr;
if (event)
{
event->setParameterByName(name.c_str(), value);
}
}
bool SoundEvent::GetPaused() const
{
bool retVal = false;
auto event = mSystem ? mSystem->GetEventInstance(mID) : nullptr;
if (event)
{
event->getPaused(&retVal);
}
return retVal;
}
float SoundEvent::GetVolume() const
{
float retVal = 0.0f;
auto event = mSystem ? mSystem->GetEventInstance(mID) : nullptr;
if (event)
{
event->getVolume(&retVal);
}
return retVal;
}
float SoundEvent::GetPitch() const
{
float retVal = 0.0f;
auto event = mSystem ? mSystem->GetEventInstance(mID) : nullptr;
if (event)
{
event->getPitch(&retVal);
}
return retVal;
}
float SoundEvent::GetParameter(const std::string& name)
{
float retVal = 0.0f;
auto event = mSystem ? mSystem->GetEventInstance(mID) : nullptr;
if (event)
{
event->getParameterByName(name.c_str(), &retVal);
}
return retVal;
}