Changeset View
Changeset View
Standalone View
Standalone View
extern/audaspace/src/sequence/SequenceHandle.cpp
- This file was moved from intern/audaspace/intern/AUD_SequencerHandle.cpp.
| /* | /******************************************************************************* | ||||
| * ***** BEGIN GPL LICENSE BLOCK ***** | * Copyright 2009-2016 Jörg Müller | ||||
| * | * | ||||
| * Copyright 2009-2011 Jörg Hermann Müller | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| * you may not use this file except in compliance with the License. | |||||
| * You may obtain a copy of the License at | |||||
| * | * | ||||
| * This file is part of AudaSpace. | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
| * | * | ||||
| * Audaspace is free software; you can redistribute it and/or modify | * Unless required by applicable law or agreed to in writing, software | ||||
| * it under the terms of the GNU General Public License as published by | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
| * the Free Software Foundation; either version 2 of the License, or | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| * (at your option) any later version. | * See the License for the specific language governing permissions and | ||||
| * | * limitations under the License. | ||||
| * AudaSpace is distributed in the hope that it will be useful, | ******************************************************************************/ | ||||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
| * GNU General Public License for more details. | |||||
| * | |||||
| * You should have received a copy of the GNU General Public License | |||||
| * along with Audaspace; if not, write to the Free Software Foundation, | |||||
| * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
| * | |||||
| * ***** END GPL LICENSE BLOCK ***** | |||||
| */ | |||||
| /** \file audaspace/intern/AUD_SequencerHandle.cpp | #include "SequenceHandle.h" | ||||
| * \ingroup audaspaceintern | #include "sequence/SequenceEntry.h" | ||||
| */ | #include "devices/ReadDevice.h" | ||||
| #include "Exception.h" | |||||
| #include <mutex> | |||||
| #include "AUD_SequencerHandle.h" | |||||
| #include "AUD_ReadDevice.h" | |||||
| #include "AUD_MutexLock.h" | |||||
| #define KEEP_TIME 10 | #define KEEP_TIME 10 | ||||
| void AUD_SequencerHandle::start() | AUD_NAMESPACE_BEGIN | ||||
| void SequenceHandle::start() | |||||
| { | { | ||||
| // we already tried to start, aborting | // we already tried to start, aborting | ||||
| if(!m_valid) | if(!m_valid) | ||||
| Context not available. | |||||
| // in case the sound is playing, we need to stop first | // in case the sound is playing, we need to stop first | ||||
| stop(); | stop(); | ||||
| AUD_MutexLock lock(*m_entry); | std::lock_guard<ILockable> lock(*m_entry); | ||||
| // let's try playing | // let's try playing | ||||
| if(m_entry->m_sound.get()) | if(m_entry->m_sound.get()) | ||||
| Context not available. | |||||
| try | try | ||||
| { | { | ||||
| m_handle = m_device.play(m_entry->m_sound, true); | m_handle = m_device.play(m_entry->m_sound, true); | ||||
| m_3dhandle = boost::dynamic_pointer_cast<AUD_I3DHandle>(m_handle); | m_3dhandle = std::dynamic_pointer_cast<I3DHandle>(m_handle); | ||||
| } | } | ||||
| catch(AUD_Exception&) | catch(Exception&) | ||||
| { | { | ||||
| // handle stays invalid in case we get an exception | // handle stays invalid in case we get an exception | ||||
| } | } | ||||
| Context not available. | |||||
| m_valid = m_handle.get(); | m_valid = m_handle.get(); | ||||
| } | } | ||||
| bool AUD_SequencerHandle::updatePosition(float position) | bool SequenceHandle::updatePosition(float position) | ||||
| { | { | ||||
| AUD_MutexLock lock(*m_entry); | std::lock_guard<ILockable> lock(*m_entry); | ||||
| if(m_handle.get()) | if(m_handle.get()) | ||||
| { | { | ||||
| Context not available. | |||||
| return false; | return false; | ||||
| } | } | ||||
| AUD_SequencerHandle::AUD_SequencerHandle(boost::shared_ptr<AUD_SequencerEntry> entry, AUD_ReadDevice& device) : | SequenceHandle::SequenceHandle(std::shared_ptr<SequenceEntry> entry, ReadDevice& device) : | ||||
| m_entry(entry), | m_entry(entry), | ||||
| m_valid(true), | m_valid(true), | ||||
| m_status(0), | m_status(0), | ||||
| Context not available. | |||||
| { | { | ||||
| } | } | ||||
| AUD_SequencerHandle::~AUD_SequencerHandle() | SequenceHandle::~SequenceHandle() | ||||
| { | { | ||||
| stop(); | stop(); | ||||
| } | } | ||||
| int AUD_SequencerHandle::compare(boost::shared_ptr<AUD_SequencerEntry> entry) const | int SequenceHandle::compare(std::shared_ptr<SequenceEntry> entry) const | ||||
| { | { | ||||
| if(m_entry->getID() < entry->getID()) | if(m_entry->getID() < entry->getID()) | ||||
| return -1; | return -1; | ||||
| Context not available. | |||||
| return 1; | return 1; | ||||
| } | } | ||||
| void AUD_SequencerHandle::stop() | void SequenceHandle::stop() | ||||
| { | { | ||||
| if(m_handle.get()) | if(m_handle.get()) | ||||
| m_handle->stop(); | m_handle->stop(); | ||||
| m_handle = boost::shared_ptr<AUD_IHandle>(); | m_handle = nullptr; | ||||
| m_3dhandle = boost::shared_ptr<AUD_I3DHandle>(); | m_3dhandle = nullptr; | ||||
| } | } | ||||
| void AUD_SequencerHandle::update(float position, float frame, float fps) | void SequenceHandle::update(float position, float frame, float fps) | ||||
| { | { | ||||
| if(m_sound_status != m_entry->m_sound_status) | if(m_sound_status != m_entry->m_sound_status) | ||||
| { | { | ||||
| Context not available. | |||||
| } | } | ||||
| } | } | ||||
| AUD_MutexLock lock(*m_entry); | std::lock_guard<ILockable> lock(*m_entry); | ||||
| if(m_pos_status != m_entry->m_pos_status) | if(m_pos_status != m_entry->m_pos_status) | ||||
| { | { | ||||
| m_pos_status = m_entry->m_pos_status; | m_pos_status = m_entry->m_pos_status; | ||||
| Context not available. | |||||
| if(m_status != m_entry->m_status) | if(m_status != m_entry->m_status) | ||||
| { | { | ||||
| m_status = m_entry->m_status; | |||||
| m_3dhandle->setRelative(m_entry->m_relative); | m_3dhandle->setRelative(m_entry->m_relative); | ||||
| m_3dhandle->setVolumeMaximum(m_entry->m_volume_max); | m_3dhandle->setVolumeMaximum(m_entry->m_volume_max); | ||||
| m_3dhandle->setVolumeMinimum(m_entry->m_volume_min); | m_3dhandle->setVolumeMinimum(m_entry->m_volume_min); | ||||
| Context not available. | |||||
| m_3dhandle->setConeAngleOuter(m_entry->m_cone_angle_outer); | m_3dhandle->setConeAngleOuter(m_entry->m_cone_angle_outer); | ||||
| m_3dhandle->setConeAngleInner(m_entry->m_cone_angle_inner); | m_3dhandle->setConeAngleInner(m_entry->m_cone_angle_inner); | ||||
| m_3dhandle->setConeVolumeOuter(m_entry->m_cone_volume_outer); | m_3dhandle->setConeVolumeOuter(m_entry->m_cone_volume_outer); | ||||
| m_status = m_entry->m_status; | |||||
| } | } | ||||
| float value; | float value; | ||||
| Context not available. | |||||
| m_entry->m_pitch.read(frame, &value); | m_entry->m_pitch.read(frame, &value); | ||||
| m_handle->setPitch(value); | m_handle->setPitch(value); | ||||
| m_entry->m_panning.read(frame, &value); | m_entry->m_panning.read(frame, &value); | ||||
| AUD_SoftwareDevice::setPanning(m_handle.get(), value); | SoftwareDevice::setPanning(m_handle.get(), value); | ||||
| AUD_Vector3 v, v2; | Vector3 v, v2; | ||||
| AUD_Quaternion q; | Quaternion q; | ||||
| m_entry->m_orientation.read(frame, q.get()); | m_entry->m_orientation.read(frame, q.get()); | ||||
| m_3dhandle->setSourceOrientation(q); | m_3dhandle->setOrientation(q); | ||||
| m_entry->m_location.read(frame, v.get()); | m_entry->m_location.read(frame, v.get()); | ||||
| m_3dhandle->setSourceLocation(v); | m_3dhandle->setLocation(v); | ||||
| m_entry->m_location.read(frame + 1, v2.get()); | m_entry->m_location.read(frame + 1, v2.get()); | ||||
| v2 -= v; | v2 -= v; | ||||
| m_3dhandle->setSourceVelocity(v2 * fps); | m_3dhandle->setVelocity(v2 * fps); | ||||
| if(m_entry->m_muted) | if(m_entry->m_muted) | ||||
| m_handle->setVolume(0); | m_handle->setVolume(0); | ||||
| } | } | ||||
| bool AUD_SequencerHandle::seek(float position) | bool SequenceHandle::seek(float position) | ||||
| { | { | ||||
| if(!m_valid) | if(!m_valid) | ||||
| // sound not valid, aborting | // sound not valid, aborting | ||||
| Context not available. | |||||
| // no handle, aborting | // no handle, aborting | ||||
| return false; | return false; | ||||
| AUD_MutexLock lock(*m_entry); | std::lock_guard<ILockable> lock(*m_entry); | ||||
| float seekpos = position - m_entry->m_begin; | float seekpos = position - m_entry->m_begin; | ||||
| if(seekpos < 0) | if(seekpos < 0) | ||||
| seekpos = 0; | seekpos = 0; | ||||
| Context not available. | |||||
| return true; | return true; | ||||
| } | } | ||||
| AUD_NAMESPACE_END | |||||
| Context not available. | |||||