Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * Copyright 2009-2011 Jörg Hermann Müller 00005 * 00006 * This file is part of AudaSpace. 00007 * 00008 * Audaspace is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * AudaSpace is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with Audaspace; if not, write to the Free Software Foundation, 00020 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00021 * 00022 * ***** END GPL LICENSE BLOCK ***** 00023 */ 00024 00030 #include "AUD_SequencerHandle.h" 00031 #include "AUD_ReadDevice.h" 00032 00033 AUD_SequencerHandle::AUD_SequencerHandle(AUD_Reference<AUD_SequencerEntry> entry, AUD_ReadDevice& device) : 00034 m_entry(entry), 00035 m_status(0), 00036 m_pos_status(0), 00037 m_sound_status(0), 00038 m_device(device) 00039 { 00040 if(!entry->m_sound.isNull()) 00041 { 00042 m_handle = device.play(entry->m_sound, true); 00043 m_3dhandle = AUD_Reference<AUD_I3DHandle>(m_handle); 00044 } 00045 } 00046 00047 AUD_SequencerHandle::~AUD_SequencerHandle() 00048 { 00049 stop(); 00050 } 00051 00052 int AUD_SequencerHandle::compare(AUD_Reference<AUD_SequencerEntry> entry) const 00053 { 00054 if(m_entry->getID() < entry->getID()) 00055 return -1; 00056 else if(m_entry->getID() == entry->getID()) 00057 return 0; 00058 return 1; 00059 } 00060 00061 void AUD_SequencerHandle::stop() 00062 { 00063 if(!m_handle.isNull()) 00064 m_handle->stop(); 00065 } 00066 00067 void AUD_SequencerHandle::update(float position, float frame, float fps) 00068 { 00069 if(!m_handle.isNull()) 00070 { 00071 m_entry->lock(); 00072 if(position >= m_entry->m_end && m_entry->m_end >= 0) 00073 m_handle->pause(); 00074 else if(position >= m_entry->m_begin) 00075 m_handle->resume(); 00076 00077 if(m_sound_status != m_entry->m_sound_status) 00078 { 00079 if(!m_handle.isNull()) 00080 m_handle->stop(); 00081 00082 if(!m_entry->m_sound.isNull()) 00083 { 00084 m_handle = m_device.play(m_entry->m_sound, true); 00085 m_3dhandle = AUD_Reference<AUD_I3DHandle>(m_handle); 00086 } 00087 00088 m_sound_status = m_entry->m_sound_status; 00089 m_pos_status--; 00090 m_status--; 00091 } 00092 00093 if(m_pos_status != m_entry->m_pos_status) 00094 { 00095 seek(position); 00096 00097 m_pos_status = m_entry->m_pos_status; 00098 } 00099 00100 if(m_status != m_entry->m_status) 00101 { 00102 m_3dhandle->setRelative(m_entry->m_relative); 00103 m_3dhandle->setVolumeMaximum(m_entry->m_volume_max); 00104 m_3dhandle->setVolumeMinimum(m_entry->m_volume_min); 00105 m_3dhandle->setDistanceMaximum(m_entry->m_distance_max); 00106 m_3dhandle->setDistanceReference(m_entry->m_distance_reference); 00107 m_3dhandle->setAttenuation(m_entry->m_attenuation); 00108 m_3dhandle->setConeAngleOuter(m_entry->m_cone_angle_outer); 00109 m_3dhandle->setConeAngleInner(m_entry->m_cone_angle_inner); 00110 m_3dhandle->setConeVolumeOuter(m_entry->m_cone_volume_outer); 00111 00112 m_status = m_entry->m_status; 00113 } 00114 00115 float value; 00116 00117 m_entry->m_volume.read(frame, &value); 00118 m_handle->setVolume(value); 00119 m_entry->m_pitch.read(frame, &value); 00120 m_handle->setPitch(value); 00121 m_entry->m_panning.read(frame, &value); 00122 AUD_SoftwareDevice::setPanning(m_handle.get(), value); 00123 00124 AUD_Vector3 v, v2; 00125 AUD_Quaternion q; 00126 00127 m_entry->m_orientation.read(frame, q.get()); 00128 m_3dhandle->setSourceOrientation(q); 00129 m_entry->m_location.read(frame, v.get()); 00130 m_3dhandle->setSourceLocation(v); 00131 m_entry->m_location.read(frame + 1, v2.get()); 00132 v2 -= v; 00133 m_3dhandle->setSourceVelocity(v2 * fps); 00134 00135 if(m_entry->m_muted) 00136 m_handle->setVolume(0); 00137 m_entry->unlock(); 00138 } 00139 } 00140 00141 void AUD_SequencerHandle::seek(float position) 00142 { 00143 if(!m_handle.isNull()) 00144 { 00145 m_entry->lock(); 00146 if(position >= m_entry->m_end && m_entry->m_end >= 0) 00147 { 00148 m_handle->pause(); 00149 m_entry->unlock(); 00150 return; 00151 } 00152 00153 float seekpos = position - m_entry->m_begin; 00154 if(seekpos < 0) 00155 seekpos = 0; 00156 seekpos += m_entry->m_skip; 00157 m_handle->seek(seekpos); 00158 if(position < m_entry->m_begin) 00159 m_handle->pause(); 00160 else 00161 m_handle->resume(); 00162 m_entry->unlock(); 00163 } 00164 }