Audaspace 1.5.0
A high level audio library.
Loading...
Searching...
No Matches
DynamicMusic.h
Go to the documentation of this file.
1/*******************************************************************************
2* Copyright 2015-2016 Juan Francisco Crespo Galán
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15******************************************************************************/
16
17#pragma once
18
25#include "devices/IHandle.h"
26#include "devices/IDevice.h"
27#include "ISound.h"
28
29#include <memory>
30#include <vector>
31#include <thread>
32#include <atomic>
33#include <condition_variable>
34#include <mutex>
35
37
43{
44private:
48 std::vector<std::vector<std::shared_ptr<ISound>>> m_scenes;
49
53 std::atomic_int m_id;
54
58 double m_fadeTime;
59
63 std::shared_ptr<IHandle> m_currentHandle;
64
68 std::shared_ptr<IHandle> m_transitionHandle;
69
73 std::shared_ptr<IDevice> m_device;
74
78 std::atomic_bool m_transitioning;
79
83 std::atomic_bool m_stopThread;
84
88 std::atomic_int m_soundTarget;
89
93 float m_volume;
94
98 std::thread m_fadeThread;
99
100 // delete copy constructor and operator=
101 DynamicMusic(const DynamicMusic&) = delete;
102 DynamicMusic& operator=(const DynamicMusic&) = delete;
103
104public:
109 DynamicMusic(std::shared_ptr<IDevice> device);
110
111 virtual ~DynamicMusic();
112
118 int addScene(std::shared_ptr<ISound> sound);
119
127 bool changeScene(int id);
128
133 int getScene();
134
142 bool addTransition(int init, int end, std::shared_ptr<ISound> sound);
143
148 void setFadeTime(double seconds);
149
154 double getFadeTime();
155
162 bool resume();
163
170 bool pause();
171
180 bool seek(double position);
181
187 double getPosition();
188
193 float getVolume();
194
202 bool setVolume(float volume);
203
216
223 bool stop();
224
225 private:
226 //Callbacks used to schedule transitions after a sound ends.
227 static void transitionCallback(void* player);
228 static void sceneCallback(void* player);
229 //These functions can fade sounds in and out if used with a thread.
230 void crossfadeThread();
231 void fadeInThread();
232 void fadeOutThread();
233};
234
#define AUD_NAMESPACE_END
Closes the audaspace namespace aud.
Definition Audaspace.h:119
#define AUD_NAMESPACE_BEGIN
Opens the audaspace namespace aud.
Definition Audaspace.h:116
#define AUD_API
Used for exporting symbols in the shared library.
Definition Audaspace.h:93
The IDevice interface.
Defines the IHandle interface as well as possible states of the handle.
Status
Status of a playback handle.
Definition IHandle.h:31
The ISound interface.
This class allows to play music depending on a current "scene", scene changes are managed by the clas...
Definition DynamicMusic.h:43
double getFadeTime()
Gets the length of the crossfade transition (default 1 second).
void setFadeTime(double seconds)
Sets the length of the crossfade transition (default 1 second).
Status getStatus()
Returns the status of the current played back sound.
float getVolume()
Retrieves the volume of the scenes.
double getPosition()
Retrieves the current playback position of a sound.
DynamicMusic(std::shared_ptr< IDevice > device)
Creates a new dynamic music manager with the default silent scene (id: 0).
bool pause()
Pauses the current played back sound.
int getScene()
Retrieves the scene currently selected.
bool addTransition(int init, int end, std::shared_ptr< ISound > sound)
Adds a new transition between scenes.
bool changeScene(int id)
Changes to another scene.
bool stop()
Stops any played back or paused sound and sets the dynamic music player to default silent state (scen...
int addScene(std::shared_ptr< ISound > sound)
Adds a new scene to the manager.
bool resume()
Resumes a paused sound.
bool seek(double position)
Seeks in the current played back sound.
bool setVolume(float volume)
Sets the volume for the scenes.