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