3D Audio GSoC:
[blender.git] / intern / audaspace / intern / AUD_SequencerFactory.cpp
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * Copyright 2009-2011 Jörg Hermann Müller
7  *
8  * This file is part of AudaSpace.
9  *
10  * Audaspace is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * AudaSpace is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Audaspace; if not, write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file audaspace/intern/AUD_SequencerFactory.cpp
28  *  \ingroup audaspaceintern
29  */
30
31
32 #include "AUD_SequencerFactory.h"
33 #include "AUD_SequencerReader.h"
34 #include "AUD_3DMath.h"
35
36 AUD_SequencerFactory::AUD_SequencerFactory(AUD_Specs specs, float fps, bool muted) :
37         m_specs(specs),
38         m_status(0),
39         m_entry_status(0),
40         m_id(0),
41         m_muted(muted),
42         m_fps(fps),
43         m_speed_of_sound(434),
44         m_doppler_factor(1),
45         m_distance_model(AUD_DISTANCE_MODEL_INVERSE_CLAMPED),
46         m_location(3),
47         m_orientation(4)
48 {
49         AUD_Quaternion q;
50         m_orientation.write(q.get());
51         float f = 1;
52         m_volume.write(&f);
53
54         pthread_mutexattr_t attr;
55         pthread_mutexattr_init(&attr);
56         pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
57
58         pthread_mutex_init(&m_mutex, &attr);
59
60         pthread_mutexattr_destroy(&attr);
61 }
62
63 AUD_SequencerFactory::~AUD_SequencerFactory()
64 {
65         pthread_mutex_destroy(&m_mutex);
66 }
67
68 void AUD_SequencerFactory::lock()
69 {
70         pthread_mutex_lock(&m_mutex);
71 }
72
73 void AUD_SequencerFactory::unlock()
74 {
75         pthread_mutex_unlock(&m_mutex);
76 }
77
78 void AUD_SequencerFactory::setSpecs(AUD_Specs specs)
79 {
80         lock();
81
82         m_specs = specs;
83         m_status++;
84
85         unlock();
86 }
87
88 void AUD_SequencerFactory::setFPS(float fps)
89 {
90         lock();
91
92         m_fps = fps;
93
94         unlock();
95 }
96
97 void AUD_SequencerFactory::mute(bool muted)
98 {
99         lock();
100
101         m_muted = muted;
102
103         unlock();
104 }
105
106 bool AUD_SequencerFactory::getMute() const
107 {
108         return m_muted;
109 }
110
111 float AUD_SequencerFactory::getSpeedOfSound() const
112 {
113         return m_speed_of_sound;
114 }
115
116 void AUD_SequencerFactory::setSpeedOfSound(float speed)
117 {
118         lock();
119
120         m_speed_of_sound = speed;
121         m_status++;
122
123         unlock();
124 }
125
126 float AUD_SequencerFactory::getDopplerFactor() const
127 {
128         return m_doppler_factor;
129 }
130
131 void AUD_SequencerFactory::setDopplerFactor(float factor)
132 {
133         lock();
134
135         m_doppler_factor = factor;
136         m_status++;
137
138         unlock();
139 }
140
141 AUD_DistanceModel AUD_SequencerFactory::getDistanceModel() const
142 {
143         return m_distance_model;
144 }
145
146 void AUD_SequencerFactory::setDistanceModel(AUD_DistanceModel model)
147 {
148         lock();
149
150         m_distance_model = model;
151         m_status++;
152
153         unlock();
154 }
155
156 AUD_AnimateableProperty* AUD_SequencerFactory::getAnimProperty(AUD_AnimateablePropertyType type)
157 {
158         switch(type)
159         {
160         case AUD_AP_VOLUME:
161                 return &m_volume;
162         case AUD_AP_LOCATION:
163                 return &m_location;
164         case AUD_AP_ORIENTATION:
165                 return &m_orientation;
166         default:
167                 return NULL;
168         }
169 }
170
171 AUD_Reference<AUD_SequencerEntry> AUD_SequencerFactory::add(AUD_Reference<AUD_IFactory> sound, float begin, float end, float skip)
172 {
173         lock();
174
175         AUD_Reference<AUD_SequencerEntry> entry = new AUD_SequencerEntry(sound, begin, end, skip, m_id++);
176
177         m_entries.push_front(entry);
178         m_entry_status++;
179
180         unlock();
181
182         return entry;
183 }
184
185 void AUD_SequencerFactory::remove(AUD_Reference<AUD_SequencerEntry> entry)
186 {
187         lock();
188
189         m_entries.remove(entry);
190         m_entry_status++;
191
192         unlock();
193 }
194
195 AUD_Reference<AUD_IReader> AUD_SequencerFactory::createQualityReader()
196 {
197         return new AUD_SequencerReader(this, true);
198 }
199
200 AUD_Reference<AUD_IReader> AUD_SequencerFactory::createReader()
201 {
202         return new AUD_SequencerReader(this);
203 }