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