SequenceData.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*******************************************************************************
  2. * Copyright 2009-2016 Jörg Müller
  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 SequenceData.h
  19. * @ingroup sequence
  20. * The SequenceData class.
  21. */
  22. #include "respec/Specification.h"
  23. #include "sequence/AnimateableProperty.h"
  24. #include "devices/I3DDevice.h"
  25. #include "util/ILockable.h"
  26. #include <list>
  27. #include <memory>
  28. #include <mutex>
  29. AUD_NAMESPACE_BEGIN
  30. class SequenceEntry;
  31. class ISound;
  32. /**
  33. * This class represents sequenced entries to play a sound scene.
  34. */
  35. class AUD_API SequenceData : public ILockable
  36. {
  37. friend class SequenceReader;
  38. private:
  39. /// The target specification.
  40. Specs m_specs;
  41. /// The status of the sequence. Changes every time a non-animated parameter changes.
  42. int m_status;
  43. /// The entry status. Changes every time an entry is removed or added.
  44. int m_entry_status;
  45. /// The next unused ID for the entries.
  46. int m_id;
  47. /// The sequenced entries.
  48. std::list<std::shared_ptr<SequenceEntry> > m_entries;
  49. /// Whether the whole scene is muted.
  50. bool m_muted;
  51. /// The FPS of the scene.
  52. float m_fps;
  53. /// Speed of Sound.
  54. float m_speed_of_sound;
  55. /// Doppler factor.
  56. float m_doppler_factor;
  57. /// Distance model.
  58. DistanceModel m_distance_model;
  59. /// The animated volume.
  60. AnimateableProperty m_volume;
  61. /// The animated listener location.
  62. AnimateableProperty m_location;
  63. /// The animated listener orientation.
  64. AnimateableProperty m_orientation;
  65. /// The mutex for locking.
  66. std::recursive_mutex m_mutex;
  67. // delete copy constructor and operator=
  68. SequenceData(const SequenceData&) = delete;
  69. SequenceData& operator=(const SequenceData&) = delete;
  70. public:
  71. /**
  72. * Creates a new sound scene.
  73. * \param specs The output audio data specification.
  74. * \param fps The FPS of the scene.
  75. * \param muted Whether the whole scene is muted.
  76. */
  77. SequenceData(Specs specs, float fps, bool muted);
  78. virtual ~SequenceData();
  79. /**
  80. * Locks the sequence.
  81. */
  82. virtual void lock();
  83. /**
  84. * Unlocks the previously locked sequence.
  85. */
  86. virtual void unlock();
  87. /**
  88. * Retrieves the audio output specification.
  89. * \return The specification.
  90. */
  91. Specs getSpecs();
  92. /**
  93. * Sets the audio output specification.
  94. * \param specs The new specification.
  95. */
  96. void setSpecs(Specs specs);
  97. /**
  98. * Retrieves the scene's FPS.
  99. * \return The scene's FPS.
  100. */
  101. float getFPS() const;
  102. /**
  103. * Sets the scene's FPS.
  104. * \param fps The new FPS.
  105. */
  106. void setFPS(float fps);
  107. /**
  108. * Sets the muting state of the scene.
  109. * \param muted Whether the scene is muted.
  110. */
  111. void mute(bool muted);
  112. /**
  113. * Retrieves the muting state of the scene.
  114. * \return Whether the scene is muted.
  115. */
  116. bool isMuted() const;
  117. /**
  118. * Retrieves the speed of sound.
  119. * This value is needed for doppler effect calculation.
  120. * \return The speed of sound.
  121. */
  122. float getSpeedOfSound() const;
  123. /**
  124. * Sets the speed of sound.
  125. * This value is needed for doppler effect calculation.
  126. * \param speed The new speed of sound.
  127. */
  128. void setSpeedOfSound(float speed);
  129. /**
  130. * Retrieves the doppler factor.
  131. * This value is a scaling factor for the velocity vectors of sources and
  132. * listener which is used while calculating the doppler effect.
  133. * \return The doppler factor.
  134. */
  135. float getDopplerFactor() const;
  136. /**
  137. * Sets the doppler factor.
  138. * This value is a scaling factor for the velocity vectors of sources and
  139. * listener which is used while calculating the doppler effect.
  140. * \param factor The new doppler factor.
  141. */
  142. void setDopplerFactor(float factor);
  143. /**
  144. * Retrieves the distance model.
  145. * \return The distance model.
  146. */
  147. DistanceModel getDistanceModel() const;
  148. /**
  149. * Sets the distance model.
  150. * \param model distance model.
  151. */
  152. void setDistanceModel(DistanceModel model);
  153. /**
  154. * Retrieves one of the animated properties of the sequence.
  155. * \param type Which animated property to retrieve.
  156. * \return A pointer to the animated property, valid as long as the
  157. * sequence is.
  158. */
  159. AnimateableProperty* getAnimProperty(AnimateablePropertyType type);
  160. /**
  161. * Adds a new entry to the scene.
  162. * \param sound The sound this entry should play.
  163. * \param begin The start time.
  164. * \param end The end time or a negative value if determined by the sound.
  165. * \param skip How much seconds should be skipped at the beginning.
  166. * \return The entry added.
  167. */
  168. std::shared_ptr<SequenceEntry> add(std::shared_ptr<ISound> sound, float begin, float end, float skip);
  169. /**
  170. * Removes an entry from the scene.
  171. * \param entry The entry to remove.
  172. */
  173. void remove(std::shared_ptr<SequenceEntry> entry);
  174. };
  175. AUD_NAMESPACE_END