Blender V2.61 - r43446

AUD_SequencerEntry.cpp

Go to the documentation of this file.
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_SequencerEntry.h"
00031 #include "AUD_SequencerReader.h"
00032 
00033 #include <cmath>
00034 #include <limits>
00035 
00036 AUD_SequencerEntry::AUD_SequencerEntry(AUD_Reference<AUD_IFactory> sound, float begin, float end, float skip, int id) :
00037     m_status(0),
00038     m_pos_status(1),
00039     m_sound_status(0),
00040     m_id(id),
00041     m_sound(sound),
00042     m_begin(begin),
00043     m_end(end),
00044     m_skip(skip),
00045     m_muted(false),
00046     m_relative(true),
00047     m_volume_max(1.0f),
00048     m_volume_min(0),
00049     m_distance_max(std::numeric_limits<float>::max()),
00050     m_distance_reference(1.0f),
00051     m_attenuation(1.0f),
00052     m_cone_angle_outer(360),
00053     m_cone_angle_inner(360),
00054     m_cone_volume_outer(0),
00055     m_location(3),
00056     m_orientation(4)
00057 {
00058     AUD_Quaternion q;
00059     m_orientation.write(q.get());
00060     float f = 1;
00061     m_volume.write(&f);
00062     m_pitch.write(&f);
00063 
00064     pthread_mutexattr_t attr;
00065     pthread_mutexattr_init(&attr);
00066     pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
00067 
00068     pthread_mutex_init(&m_mutex, &attr);
00069 
00070     pthread_mutexattr_destroy(&attr);
00071 }
00072 
00073 AUD_SequencerEntry::~AUD_SequencerEntry()
00074 {
00075     pthread_mutex_destroy(&m_mutex);
00076 }
00077 
00078 void AUD_SequencerEntry::lock()
00079 {
00080     pthread_mutex_lock(&m_mutex);
00081 }
00082 
00083 void AUD_SequencerEntry::unlock()
00084 {
00085     pthread_mutex_unlock(&m_mutex);
00086 }
00087 
00088 void AUD_SequencerEntry::setSound(AUD_Reference<AUD_IFactory> sound)
00089 {
00090     lock();
00091 
00092     if(m_sound.get() != sound.get())
00093     {
00094         m_sound = sound;
00095         m_sound_status++;
00096     }
00097 
00098     unlock();
00099 }
00100 
00101 void AUD_SequencerEntry::move(float begin, float end, float skip)
00102 {
00103     lock();
00104 
00105     if(m_begin != begin || m_skip != skip || m_end != end)
00106     {
00107         m_begin = begin;
00108         m_skip = skip;
00109         m_end = end;
00110         m_pos_status++;
00111     }
00112 
00113     unlock();
00114 }
00115 
00116 void AUD_SequencerEntry::mute(bool mute)
00117 {
00118     lock();
00119 
00120     m_muted = mute;
00121 
00122     unlock();
00123 }
00124 
00125 int AUD_SequencerEntry::getID() const
00126 {
00127     return m_id;
00128 }
00129 
00130 AUD_AnimateableProperty* AUD_SequencerEntry::getAnimProperty(AUD_AnimateablePropertyType type)
00131 {
00132     switch(type)
00133     {
00134     case AUD_AP_VOLUME:
00135         return &m_volume;
00136     case AUD_AP_PITCH:
00137         return &m_pitch;
00138     case AUD_AP_PANNING:
00139         return &m_panning;
00140     case AUD_AP_LOCATION:
00141         return &m_location;
00142     case AUD_AP_ORIENTATION:
00143         return &m_orientation;
00144     default:
00145         return NULL;
00146     }
00147 }
00148 
00149 void AUD_SequencerEntry::updateAll(float volume_max, float volume_min, float distance_max,
00150                                    float distance_reference, float attenuation, float cone_angle_outer,
00151                                    float cone_angle_inner, float cone_volume_outer)
00152 {
00153     lock();
00154 
00155     if(volume_max != m_volume_max)
00156     {
00157         m_volume_max = volume_max;
00158         m_status++;
00159     }
00160 
00161     if(volume_min != m_volume_min)
00162     {
00163         m_volume_min = volume_min;
00164         m_status++;
00165     }
00166 
00167     if(distance_max != m_distance_max)
00168     {
00169         m_distance_max = distance_max;
00170         m_status++;
00171     }
00172 
00173     if(distance_reference != m_distance_reference)
00174     {
00175         m_distance_reference = distance_reference;
00176         m_status++;
00177     }
00178 
00179     if(attenuation != m_attenuation)
00180     {
00181         m_attenuation = attenuation;
00182         m_status++;
00183     }
00184 
00185     if(cone_angle_outer != m_cone_angle_outer)
00186     {
00187         m_cone_angle_outer = cone_angle_outer;
00188         m_status++;
00189     }
00190 
00191     if(cone_angle_inner != m_cone_angle_inner)
00192     {
00193         m_cone_angle_inner = cone_angle_inner;
00194         m_status++;
00195     }
00196 
00197     if(cone_volume_outer != m_cone_volume_outer)
00198     {
00199         m_cone_volume_outer = cone_volume_outer;
00200         m_status++;
00201     }
00202 
00203     unlock();
00204 }
00205 
00206 bool AUD_SequencerEntry::isRelative()
00207 {
00208     return m_relative;
00209 }
00210 
00211 void AUD_SequencerEntry::setRelative(bool relative)
00212 {
00213     lock();
00214 
00215     if(m_relative != relative)
00216     {
00217         m_relative = relative;
00218         m_status++;
00219     }
00220 
00221     unlock();
00222 }
00223 
00224 float AUD_SequencerEntry::getVolumeMaximum()
00225 {
00226     return m_volume_max;
00227 }
00228 
00229 void AUD_SequencerEntry::setVolumeMaximum(float volume)
00230 {
00231     lock();
00232 
00233     m_volume_max = volume;
00234     m_status++;
00235 
00236     unlock();
00237 }
00238 
00239 float AUD_SequencerEntry::getVolumeMinimum()
00240 {
00241     return m_volume_min;
00242 }
00243 
00244 void AUD_SequencerEntry::setVolumeMinimum(float volume)
00245 {
00246     lock();
00247 
00248     m_volume_min = volume;
00249     m_status++;
00250 
00251     unlock();
00252 }
00253 
00254 float AUD_SequencerEntry::getDistanceMaximum()
00255 {
00256     return m_distance_max;
00257 }
00258 
00259 void AUD_SequencerEntry::setDistanceMaximum(float distance)
00260 {
00261     lock();
00262 
00263     m_distance_max = distance;
00264     m_status++;
00265 
00266     unlock();
00267 }
00268 
00269 float AUD_SequencerEntry::getDistanceReference()
00270 {
00271     return m_distance_reference;
00272 }
00273 
00274 void AUD_SequencerEntry::setDistanceReference(float distance)
00275 {
00276     lock();
00277 
00278     m_distance_reference = distance;
00279     m_status++;
00280 
00281     unlock();
00282 }
00283 
00284 float AUD_SequencerEntry::getAttenuation()
00285 {
00286     return m_attenuation;
00287 }
00288 
00289 void AUD_SequencerEntry::setAttenuation(float factor)
00290 {
00291     lock();
00292 
00293     m_attenuation = factor;
00294     m_status++;
00295 
00296     unlock();
00297 }
00298 
00299 float AUD_SequencerEntry::getConeAngleOuter()
00300 {
00301     return m_cone_angle_outer;
00302 }
00303 
00304 void AUD_SequencerEntry::setConeAngleOuter(float angle)
00305 {
00306     lock();
00307 
00308     m_cone_angle_outer = angle;
00309     m_status++;
00310 
00311     unlock();
00312 }
00313 
00314 float AUD_SequencerEntry::getConeAngleInner()
00315 {
00316     return m_cone_angle_inner;
00317 }
00318 
00319 void AUD_SequencerEntry::setConeAngleInner(float angle)
00320 {
00321     lock();
00322 
00323     m_cone_angle_inner = angle;
00324     m_status++;
00325 
00326     unlock();
00327 }
00328 
00329 float AUD_SequencerEntry::getConeVolumeOuter()
00330 {
00331     return m_cone_volume_outer;
00332 }
00333 
00334 void AUD_SequencerEntry::setConeVolumeOuter(float volume)
00335 {
00336     lock();
00337 
00338     m_cone_volume_outer = volume;
00339     m_status++;
00340 
00341     unlock();
00342 }