3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005 Christian Schoenebeck * |
* Copyright (C) 2005 - 2007 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
23 |
|
|
24 |
#include "AudioOutputDeviceFactory.h" |
#include "AudioOutputDeviceFactory.h" |
25 |
#include "AudioOutputDevice.h" |
#include "AudioOutputDevice.h" |
26 |
|
#include "../../common/global_private.h" |
27 |
|
|
28 |
namespace LinuxSampler { |
namespace LinuxSampler { |
29 |
|
|
57 |
return true; |
return true; |
58 |
} |
} |
59 |
|
|
60 |
void AudioOutputDevice::ParameterActive::OnSetValue(bool b) throw (LinuxSamplerException) { |
void AudioOutputDevice::ParameterActive::OnSetValue(bool b) throw (Exception) { |
61 |
if (b) ((AudioOutputDevice*)pDevice)->Play(); |
if (b) ((AudioOutputDevice*)pDevice)->Play(); |
62 |
else ((AudioOutputDevice*)pDevice)->Stop(); |
else ((AudioOutputDevice*)pDevice)->Stop(); |
63 |
} |
} |
110 |
return std::vector<int>(); |
return std::vector<int>(); |
111 |
} |
} |
112 |
|
|
113 |
void AudioOutputDevice::ParameterSampleRate::OnSetValue(int i) throw (LinuxSamplerException) { |
int AudioOutputDevice::ParameterSampleRate::ValueAsInt() { |
114 |
|
return (pDevice) ? (int) ((AudioOutputDevice*)pDevice)->SampleRate() |
115 |
|
: DeviceCreationParameterInt::ValueAsInt(); |
116 |
|
} |
117 |
|
|
118 |
|
void AudioOutputDevice::ParameterSampleRate::OnSetValue(int i) throw (Exception) { |
119 |
/* cannot happen, as parameter is fix */ |
/* cannot happen, as parameter is fix */ |
120 |
} |
} |
121 |
|
|
156 |
} |
} |
157 |
|
|
158 |
optional<int> AudioOutputDevice::ParameterChannels::RangeMinAsInt(std::map<String,String> Parameters) { |
optional<int> AudioOutputDevice::ParameterChannels::RangeMinAsInt(std::map<String,String> Parameters) { |
159 |
return optional<int>::nothing; |
return 1; |
160 |
} |
} |
161 |
|
|
162 |
optional<int> AudioOutputDevice::ParameterChannels::RangeMaxAsInt(std::map<String,String> Parameters) { |
optional<int> AudioOutputDevice::ParameterChannels::RangeMaxAsInt(std::map<String,String> Parameters) { |
167 |
return std::vector<int>(); |
return std::vector<int>(); |
168 |
} |
} |
169 |
|
|
170 |
void AudioOutputDevice::ParameterChannels::OnSetValue(int i) throw (LinuxSamplerException) { |
void AudioOutputDevice::ParameterChannels::OnSetValue(int i) throw (Exception) { |
171 |
((AudioOutputDevice*)pDevice)->AcquireChannels(i); |
((AudioOutputDevice*)pDevice)->AcquireChannels(i); |
172 |
} |
} |
173 |
|
|
180 |
// *************** AudioOutputDevice *************** |
// *************** AudioOutputDevice *************** |
181 |
// * |
// * |
182 |
|
|
183 |
AudioOutputDevice::AudioOutputDevice(std::map<String,DeviceCreationParameter*> DriverParameters) { |
AudioOutputDevice::AudioOutputDevice(std::map<String,DeviceCreationParameter*> DriverParameters) |
184 |
|
: EnginesReader(Engines) { |
185 |
this->Parameters = DriverParameters; |
this->Parameters = DriverParameters; |
186 |
} |
} |
187 |
|
|
190 |
{ |
{ |
191 |
std::vector<AudioChannel*>::iterator iter = Channels.begin(); |
std::vector<AudioChannel*>::iterator iter = Channels.begin(); |
192 |
while (iter != Channels.end()) { |
while (iter != Channels.end()) { |
|
Channels.erase(iter); |
|
193 |
delete *iter; |
delete *iter; |
194 |
iter++; |
iter++; |
195 |
} |
} |
196 |
|
Channels.clear(); |
197 |
} |
} |
198 |
|
|
199 |
// delete all device parameters |
// delete all device parameters |
200 |
{ |
{ |
201 |
std::map<String,DeviceCreationParameter*>::iterator iter = Parameters.begin(); |
std::map<String,DeviceCreationParameter*>::iterator iter = Parameters.begin(); |
202 |
while (iter != Parameters.end()) { |
while (iter != Parameters.end()) { |
|
Parameters.erase(iter); |
|
203 |
delete iter->second; |
delete iter->second; |
204 |
iter++; |
iter++; |
205 |
} |
} |
206 |
|
Parameters.clear(); |
207 |
} |
} |
208 |
} |
} |
209 |
|
|
210 |
void AudioOutputDevice::Connect(Engine* pEngine) { |
void AudioOutputDevice::Connect(Engine* pEngine) { |
211 |
if (Engines.find(pEngine) == Engines.end()) { |
std::set<Engine*>& engines = Engines.GetConfigForUpdate(); |
212 |
Engines.insert(pEngine); |
if (engines.find(pEngine) == engines.end()) { |
213 |
|
engines.insert(pEngine); |
214 |
|
Engines.SwitchConfig().insert(pEngine); |
215 |
// make sure the engine knows about the connection |
// make sure the engine knows about the connection |
216 |
//pEngine->Connect(this); |
//pEngine->Connect(this); |
217 |
} |
} |
218 |
} |
} |
219 |
|
|
220 |
void AudioOutputDevice::Disconnect(Engine* pEngine) { |
void AudioOutputDevice::Disconnect(Engine* pEngine) { |
221 |
if (Engines.find(pEngine) != Engines.end()) { // if clause to prevent disconnect loop |
std::set<Engine*>& engines = Engines.GetConfigForUpdate(); |
222 |
Engines.erase(pEngine); |
if (engines.find(pEngine) != engines.end()) { // if clause to prevent disconnect loop |
223 |
|
engines.erase(pEngine); |
224 |
|
Engines.SwitchConfig().erase(pEngine); |
225 |
// make sure the engine knows about the disconnection |
// make sure the engine knows about the disconnection |
226 |
//pEngine->DisconnectAudioOutputDevice(); |
//pEngine->DisconnectAudioOutputDevice(); |
227 |
} |
} |
239 |
} |
} |
240 |
} |
} |
241 |
|
|
242 |
|
uint AudioOutputDevice::ChannelCount() { |
243 |
|
return Channels.size(); |
244 |
|
} |
245 |
|
|
246 |
std::map<String,DeviceCreationParameter*> AudioOutputDevice::DeviceParameters() { |
std::map<String,DeviceCreationParameter*> AudioOutputDevice::DeviceParameters() { |
247 |
return Parameters; |
return Parameters; |
248 |
} |
} |
261 |
int result = 0; |
int result = 0; |
262 |
|
|
263 |
// let all connected engines render audio for the current audio fragment cycle |
// let all connected engines render audio for the current audio fragment cycle |
264 |
|
const std::set<Engine*>& engines = EnginesReader.Lock(); |
265 |
#if CONFIG_RT_EXCEPTIONS |
#if CONFIG_RT_EXCEPTIONS |
266 |
try |
try |
267 |
#endif // CONFIG_RT_EXCEPTIONS |
#endif // CONFIG_RT_EXCEPTIONS |
268 |
{ |
{ |
269 |
std::set<Engine*>::iterator iterEngine = Engines.begin(); |
std::set<Engine*>::iterator iterEngine = engines.begin(); |
270 |
std::set<Engine*>::iterator end = Engines.end(); |
std::set<Engine*>::iterator end = engines.end(); |
271 |
for (; iterEngine != end; iterEngine++) { |
for (; iterEngine != end; iterEngine++) { |
272 |
int res = (*iterEngine)->RenderAudio(Samples); |
int res = (*iterEngine)->RenderAudio(Samples); |
273 |
if (res != 0) result = res; |
if (res != 0) result = res; |
280 |
} |
} |
281 |
#endif // CONFIG_RT_EXCEPTIONS |
#endif // CONFIG_RT_EXCEPTIONS |
282 |
|
|
283 |
|
EnginesReader.Unlock(); |
284 |
return result; |
return result; |
285 |
} |
} |
286 |
|
|