Welcome to mirror list, hosted at ThFree Co, Russian Federation.

PlaybackCategory.h « fx « include « audaspace « extern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7721623359f40469445738c16ccec846c80d17e5 (plain)
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
119
120
121
122
123
124
125
126
127
/*******************************************************************************
* Copyright 2015-2016 Juan Francisco Crespo Galán
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/

#pragma once

/**
* @file PlaybackCategory.h
* @ingroup fx
* The PlaybackCategory class.
*/

#include "devices/IHandle.h"
#include "devices/IDevice.h"
#include "VolumeStorage.h"

#include <unordered_map>
#include <memory>

AUD_NAMESPACE_BEGIN

/**
* This class represents a category of related sounds which are currently playing and allows to control them easily.
*/
class AUD_API PlaybackCategory
{
private:
	/**
	* Next handle ID to be assigned.
	*/
	unsigned int m_currentID;

	/**
	* Vector of handles that belong to the category.
	*/
	std::unordered_map<unsigned int, std::shared_ptr<IHandle>> m_handles;

	/**
	* Device that will play the sounds.
	*/
	std::shared_ptr<IDevice> m_device;

	/**
	* Status of the category.
	*/
	Status m_status;

	/**
	* Volume of all the sounds of the category.
	*/
	std::shared_ptr<VolumeStorage> m_volumeStorage;

	// delete copy constructor and operator=
	PlaybackCategory(const PlaybackCategory&) = delete;
	PlaybackCategory& operator=(const PlaybackCategory&) = delete;

public:
	/**
	* Creates a new PlaybackCategory.
	* \param device A shared pointer to the device which will be used for playback.
	*/
	PlaybackCategory(std::shared_ptr<IDevice> device);
	~PlaybackCategory();

	/**
	* Plays a new sound in the category.
	* \param sound The sound to be played.
	* \return A handle for the playback. If the playback failed, nullptr will be returned.
	*/
	std::shared_ptr<IHandle> play(std::shared_ptr<ISound> sound);

	/**
	* Resumes all the paused sounds of the category.
	*/
	void resume();

	/**
	* Pauses all current played back sounds of the category.
	*/
	void pause();

	/**
	* Retrieves the volume of the category.
	* \return The volume.
	*/
	float getVolume();

	/**
	* Sets the volume for the category.
	* \param volume The volume.
	*/
	void setVolume(float volume);

	/**
	* Stops all the playing back or paused sounds.
	*/
	void stop();

	/**
	* Retrieves the shared volume of the category.
	* \return A shared pointer to the VolumeStorage object that represents the shared volume of the category.
	*/
	std::shared_ptr<VolumeStorage> getSharedVolume();

	/**
	* Cleans the category erasing all the invalid handles.
	* Only needed if individual sounds are stopped with their handles.
	*/
	void cleanHandles();

private:
	static void cleanHandleCallback(void* data);
};

AUD_NAMESPACE_END