tmp
[blender.git] / extern / audaspace / include / fx / PlaybackCategory.h
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
19 /**
20 * @file PlaybackCategory.h
21 * @ingroup fx
22 * The PlaybackCategory class.
23 */
24
25 #include "devices/IHandle.h"
26 #include "devices/IDevice.h"
27 #include "VolumeStorage.h"
28
29 #include <unordered_map>
30 #include <memory>
31
32 AUD_NAMESPACE_BEGIN
33
34 /**
35 * This class represents a category of related sounds which are currently playing and allows to control them easily.
36 */
37 class AUD_API PlaybackCategory
38 {
39 private:
40         /**
41         * Next handle ID to be assigned.
42         */
43         unsigned int m_currentID;
44
45         /**
46         * Vector of handles that belong to the category.
47         */
48         std::unordered_map<unsigned int, std::shared_ptr<IHandle>> m_handles;
49
50         /**
51         * Device that will play the sounds.
52         */
53         std::shared_ptr<IDevice> m_device;
54
55         /**
56         * Status of the category.
57         */
58         Status m_status;
59
60         /**
61         * Volume of all the sounds of the category.
62         */
63         std::shared_ptr<VolumeStorage> m_volumeStorage;
64
65         // delete copy constructor and operator=
66         PlaybackCategory(const PlaybackCategory&) = delete;
67         PlaybackCategory& operator=(const PlaybackCategory&) = delete;
68
69 public:
70         /**
71         * Creates a new PlaybackCategory.
72         * \param device A shared pointer to the device which will be used for playback.
73         */
74         PlaybackCategory(std::shared_ptr<IDevice> device);
75         ~PlaybackCategory();
76
77         /**
78         * Plays a new sound in the category.
79         * \param sound The sound to be played.
80         * \return A handle for the playback. If the playback failed, nullptr will be returned.
81         */
82         std::shared_ptr<IHandle> play(std::shared_ptr<ISound> sound);
83
84         /**
85         * Resumes all the paused sounds of the category.
86         */
87         void resume();
88
89         /**
90         * Pauses all current played back sounds of the category.
91         */
92         void pause();
93
94         /**
95         * Retrieves the volume of the category.
96         * \return The volume.
97         */
98         float getVolume();
99
100         /**
101         * Sets the volume for the category.
102         * \param volume The volume.
103         */
104         void setVolume(float volume);
105
106         /**
107         * Stops all the playing back or paused sounds.
108         */
109         void stop();
110
111         /**
112         * Retrieves the shared volume of the category.
113         * \return A shared pointer to the VolumeStorage object that represents the shared volume of the category.
114         */
115         std::shared_ptr<VolumeStorage> getSharedVolume();
116
117         /**
118         * Cleans the category erasing all the invalid handles.
119         * Only needed if individual sounds are stopped with their handles.
120         */
121         void cleanHandles();
122
123 private:
124         static void cleanHandleCallback(void* data);
125 };
126
127 AUD_NAMESPACE_END