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 - 2008 Christian Schoenebeck * |
* Copyright (C) 2005 - 2010 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 * |
24 |
#include "AudioOutputDeviceFactory.h" |
#include "AudioOutputDeviceFactory.h" |
25 |
#include "AudioOutputDevice.h" |
#include "AudioOutputDevice.h" |
26 |
#include "../../common/global_private.h" |
#include "../../common/global_private.h" |
27 |
|
#include "../../common/IDGenerator.h" |
28 |
|
|
29 |
namespace LinuxSampler { |
namespace LinuxSampler { |
30 |
|
|
184 |
AudioOutputDevice::AudioOutputDevice(std::map<String,DeviceCreationParameter*> DriverParameters) |
AudioOutputDevice::AudioOutputDevice(std::map<String,DeviceCreationParameter*> DriverParameters) |
185 |
: EnginesReader(Engines) { |
: EnginesReader(Engines) { |
186 |
this->Parameters = DriverParameters; |
this->Parameters = DriverParameters; |
187 |
|
EffectChainIDs = new IDGenerator(); |
188 |
} |
} |
189 |
|
|
190 |
AudioOutputDevice::~AudioOutputDevice() { |
AudioOutputDevice::~AudioOutputDevice() { |
217 |
} |
} |
218 |
vEffectChains.clear(); |
vEffectChains.clear(); |
219 |
} |
} |
220 |
|
|
221 |
|
delete EffectChainIDs; |
222 |
} |
} |
223 |
|
|
224 |
void AudioOutputDevice::Connect(Engine* pEngine) { |
void AudioOutputDevice::Connect(Engine* pEngine) { |
240 |
//pEngine->DisconnectAudioOutputDevice(); |
//pEngine->DisconnectAudioOutputDevice(); |
241 |
} |
} |
242 |
} |
} |
243 |
|
|
244 |
|
void AudioOutputDevice::ReconnectAll() { |
245 |
|
// copy by value, not by reference here ! |
246 |
|
std::set<Engine*> engines = Engines.GetConfigForUpdate(); |
247 |
|
{ |
248 |
|
std::set<Engine*>::iterator iterEngine = engines.begin(); |
249 |
|
std::set<Engine*>::iterator end = engines.end(); |
250 |
|
for (; iterEngine != end; iterEngine++) { |
251 |
|
(*iterEngine)->ReconnectAudioOutputDevice(); |
252 |
|
} |
253 |
|
} |
254 |
|
} |
255 |
|
|
256 |
AudioChannel* AudioOutputDevice::Channel(uint ChannelIndex) { |
AudioChannel* AudioOutputDevice::Channel(uint ChannelIndex) { |
257 |
return (ChannelIndex < Channels.size()) ? Channels[ChannelIndex] : NULL; |
return (ChannelIndex < Channels.size()) ? Channels[ChannelIndex] : NULL; |
273 |
return Parameters; |
return Parameters; |
274 |
} |
} |
275 |
|
|
276 |
EffectChain* AudioOutputDevice::AddMasterEffectChain() { |
EffectChain* AudioOutputDevice::AddSendEffectChain() { |
277 |
EffectChain* pChain = new EffectChain(this); |
EffectChain* pChain = new EffectChain(this, EffectChainIDs->create()); |
278 |
vEffectChains.push_back(pChain); |
vEffectChains.push_back(pChain); |
279 |
return pChain; |
return pChain; |
280 |
} |
} |
281 |
|
|
282 |
void AudioOutputDevice::RemoveMasterEffectChain(uint iChain) throw (Exception) { |
void AudioOutputDevice::RemoveSendEffectChain(uint iChain) throw (Exception) { |
283 |
if (iChain >= vEffectChains.size()) |
if (iChain >= vEffectChains.size()) |
284 |
throw Exception( |
throw Exception( |
285 |
"Could not remove master effect chain " + ToString(iChain) + |
"Could not remove send effect chain " + ToString(iChain) + |
286 |
", index out of bounds" |
", index out of bounds" |
287 |
); |
); |
288 |
std::vector<EffectChain*>::iterator iter = vEffectChains.begin(); |
std::vector<EffectChain*>::iterator iter = vEffectChains.begin(); |
289 |
for (int i = 0; i < iChain; ++i) ++iter; |
for (int i = 0; i < iChain; ++i) ++iter; |
290 |
|
EffectChainIDs->destroy((*iter)->ID()); |
291 |
vEffectChains.erase(iter); |
vEffectChains.erase(iter); |
292 |
} |
} |
293 |
|
|
294 |
EffectChain* AudioOutputDevice::MasterEffectChain(uint iChain) const { |
EffectChain* AudioOutputDevice::SendEffectChain(uint iChain) const { |
295 |
if (iChain >= vEffectChains.size()) return NULL; |
if (iChain >= vEffectChains.size()) return NULL; |
296 |
return vEffectChains[iChain]; |
return vEffectChains[iChain]; |
297 |
} |
} |
298 |
|
|
299 |
uint AudioOutputDevice::MasterEffectChainCount() const { |
EffectChain* AudioOutputDevice::SendEffectChainByID(uint iChainID) const { |
300 |
|
for (int i = 0; i < SendEffectChainCount(); i++) { |
301 |
|
if (SendEffectChain(i)->ID() == iChainID) return SendEffectChain(i); |
302 |
|
} |
303 |
|
|
304 |
|
return NULL; |
305 |
|
} |
306 |
|
|
307 |
|
uint AudioOutputDevice::SendEffectChainCount() const { |
308 |
return vEffectChains.size(); |
return vEffectChains.size(); |
309 |
} |
} |
310 |
|
|
311 |
|
// TODO: to be removed |
312 |
|
EffectChain* AudioOutputDevice::AddMasterEffectChain() { |
313 |
|
return AddSendEffectChain(); |
314 |
|
} |
315 |
|
|
316 |
|
// TODO: to be removed |
317 |
|
void AudioOutputDevice::RemoveMasterEffectChain(uint iChain) throw (Exception) { |
318 |
|
RemoveSendEffectChain(iChain); |
319 |
|
} |
320 |
|
|
321 |
|
// TODO: to be removed |
322 |
|
EffectChain* AudioOutputDevice::MasterEffectChain(uint iChain) const { |
323 |
|
return SendEffectChain(iChain); |
324 |
|
} |
325 |
|
|
326 |
|
// TODO: to be removed |
327 |
|
uint AudioOutputDevice::MasterEffectChainCount() const { |
328 |
|
return SendEffectChainCount(); |
329 |
|
} |
330 |
|
|
331 |
|
float AudioOutputDevice::latency() { |
332 |
|
return float(MaxSamplesPerCycle()) / float(SampleRate()); |
333 |
|
} |
334 |
|
|
335 |
int AudioOutputDevice::RenderAudio(uint Samples) { |
int AudioOutputDevice::RenderAudio(uint Samples) { |
336 |
if (Channels.empty()) return 0; |
if (Channels.empty()) return 0; |
337 |
|
|
340 |
std::vector<AudioChannel*>::iterator iterChannels = Channels.begin(); |
std::vector<AudioChannel*>::iterator iterChannels = Channels.begin(); |
341 |
std::vector<AudioChannel*>::iterator end = Channels.end(); |
std::vector<AudioChannel*>::iterator end = Channels.end(); |
342 |
for (; iterChannels != end; iterChannels++) |
for (; iterChannels != end; iterChannels++) |
343 |
(*iterChannels)->Clear(); // zero out audio buffer |
(*iterChannels)->Clear(Samples); // zero out audio buffer |
344 |
} |
} |
345 |
// do the same for master effects |
// do the same for master effects |
346 |
{ |
{ |
401 |
std::vector<AudioChannel*>::iterator iterChannels = Channels.begin(); |
std::vector<AudioChannel*>::iterator iterChannels = Channels.begin(); |
402 |
std::vector<AudioChannel*>::iterator end = Channels.end(); |
std::vector<AudioChannel*>::iterator end = Channels.end(); |
403 |
for (; iterChannels != end; iterChannels++) |
for (; iterChannels != end; iterChannels++) |
404 |
(*iterChannels)->Clear(); // zero out audio buffer |
(*iterChannels)->Clear(Samples); // zero out audio buffer |
405 |
} |
} |
406 |
|
|
407 |
return 0; |
return 0; |