AnimateableProperty.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 AnimateableProperty.h
  19. * @ingroup sequence
  20. * Defines the AnimateableProperty class as well as existing property types.
  21. */
  22. #include "util/Buffer.h"
  23. #include "util/ILockable.h"
  24. #include <mutex>
  25. #include <list>
  26. AUD_NAMESPACE_BEGIN
  27. /// Possible animatable properties for Sequencer Factories and Entries.
  28. enum AnimateablePropertyType
  29. {
  30. AP_VOLUME,
  31. AP_PANNING,
  32. AP_PITCH,
  33. AP_LOCATION,
  34. AP_ORIENTATION
  35. };
  36. /**
  37. * This class saves animation data for float properties.
  38. */
  39. class AUD_API AnimateableProperty : private Buffer
  40. {
  41. private:
  42. struct Unknown {
  43. int start;
  44. int end;
  45. Unknown(int start, int end) :
  46. start(start), end(end) {}
  47. };
  48. /// The count of floats for a single property.
  49. const int m_count;
  50. /// Whether the property is animated or not.
  51. bool m_isAnimated;
  52. /// The mutex for locking.
  53. std::recursive_mutex m_mutex;
  54. /// The list of unknown buffer areas.
  55. std::list<Unknown> m_unknown;
  56. // delete copy constructor and operator=
  57. AnimateableProperty(const AnimateableProperty&) = delete;
  58. AnimateableProperty& operator=(const AnimateableProperty&) = delete;
  59. void AUD_LOCAL updateUnknownCache(int start, int end);
  60. public:
  61. /**
  62. * Creates a new animateable property.
  63. * \param count The count of floats for a single property.
  64. */
  65. AnimateableProperty(int count = 1);
  66. /**
  67. * Creates a new animateable property.
  68. * \param count The count of floats for a single property.
  69. * \param value The value that the property should get initialized with.
  70. * All count floats will be initialized to the same value.
  71. */
  72. AnimateableProperty(int count, float value);
  73. /**
  74. * Destroys the animateable property.
  75. */
  76. ~AnimateableProperty();
  77. /**
  78. * Returns the count of floats for a single property.
  79. * \return The count of floats stored per frame.
  80. */
  81. int getCount() const;
  82. /**
  83. * Writes the properties value and marks it non-animated.
  84. * \param data The new value.
  85. */
  86. void write(const float* data);
  87. /**
  88. * Writes the properties value and marks it animated.
  89. * \param data The new value.
  90. * \param position The position in the animation in frames.
  91. * \param count The count of frames to write.
  92. */
  93. void write(const float* data, int position, int count);
  94. /**
  95. * Reads the properties value.
  96. * \param position The position in the animation in frames.
  97. * \param[out] out Where to write the value to.
  98. */
  99. void read(float position, float* out);
  100. /**
  101. * Returns whether the property is animated.
  102. * \return Whether the property is animated.
  103. */
  104. bool isAnimated() const;
  105. };
  106. AUD_NAMESPACE_END