PlaybackCategory.h 3.0 KB

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