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 #include "Audaspace.h" 20 21 #include <memory> 22 23 AUD_NAMESPACE_BEGIN 24 25 class ReadDevice; 26 class IHandle; 27 class I3DHandle; 28 class SequenceEntry; 29 30 /** 31 * Represents a playing sequenced entry. 32 */ 33 class SequenceHandle 34 { 35 private: 36 /// The entry this handle belongs to. 37 std::shared_ptr<SequenceEntry> m_entry; 38 39 /// The handle in the read device. 40 std::shared_ptr<IHandle> m_handle; 41 42 /// The 3D handle in the read device. 43 std::shared_ptr<I3DHandle> m_3dhandle; 44 45 /// Whether the sound is playable. 46 bool m_valid; 47 48 /// The last read status from the entry. 49 int m_status; 50 51 /// The last position status from the entry. 52 int m_pos_status; 53 54 /// The last sound status from the entry. 55 int m_sound_status; 56 57 /// The read device this handle is played on. 58 ReadDevice& m_device; 59 60 // delete copy constructor and operator= 61 SequenceHandle(const SequenceHandle&) = delete; 62 SequenceHandle& operator=(const SequenceHandle&) = delete; 63 64 /** 65 * Starts playing back the handle. 66 */ 67 void start(); 68 69 /** 70 * Updates the handle state depending on position. 71 * \param position Current playback position in seconds. 72 * \return Whether the handle is valid. 73 */ 74 bool updatePosition(double position); 75 76 public: 77 /** 78 * Creates a new sequenced handle. 79 * \param entry The entry this handle plays. 80 * \param device The read device to play on. 81 */ 82 SequenceHandle(std::shared_ptr<SequenceEntry> entry, ReadDevice& device); 83 84 /** 85 * Destroys the handle. 86 */ 87 ~SequenceHandle(); 88 89 /** 90 * Compares whether this handle is playing the same entry as supplied. 91 * \param entry The entry to compare to. 92 * \return Whether the entries ID is smaller, equal or bigger. 93 */ 94 int compare(std::shared_ptr<SequenceEntry> entry) const; 95 96 /** 97 * Stops playing back the handle. 98 */ 99 void stop(); 100 101 /** 102 * Updates the handle for playback. 103 * \param position The current time during playback. 104 * \param frame The current frame during playback. 105 * \param fps The animation frames per second. 106 */ 107 void update(double position, float frame, float fps); 108 109 /** 110 * Seeks the handle to a specific time position. 111 * \param position The time to seek to. 112 * \return Whether the handle is valid. 113 */ 114 bool seek(double position); 115 }; 116 117 AUD_NAMESPACE_END 118