2 |
* * |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2009 Grigor Iliev * |
* Copyright (C) 2009 - 2013 Grigor Iliev * |
6 |
* * |
* * |
7 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
8 |
* 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 * |
247 |
} |
} |
248 |
|
|
249 |
void CAAudioDeviceListModel::FireDeviceChangedEvent(AudioDeviceID devID) { |
void CAAudioDeviceListModel::FireDeviceChangedEvent(AudioDeviceID devID) { |
250 |
DeviceMutex.Lock(); |
LockGuard lock(DeviceMutex); |
251 |
for(int i = 0; i < GetListenerCount(); i++) { |
for(int i = 0; i < GetListenerCount(); i++) { |
252 |
GetListener(i)->DeviceChanged(devID); |
GetListener(i)->DeviceChanged(devID); |
253 |
} |
} |
|
DeviceMutex.Unlock(); |
|
254 |
} |
} |
255 |
|
|
256 |
void CAAudioDeviceListModel::FireDeviceListChangedEvent() { |
void CAAudioDeviceListModel::FireDeviceListChangedEvent() { |
257 |
DeviceMutex.Lock(); |
LockGuard lock(DeviceMutex); |
258 |
for(int i = 0; i < GetListenerCount(); i++) { |
for(int i = 0; i < GetListenerCount(); i++) { |
259 |
GetListener(i)->DeviceListChanged(); |
GetListener(i)->DeviceListChanged(); |
260 |
} |
} |
|
DeviceMutex.Unlock(); |
|
261 |
} |
} |
262 |
|
|
263 |
void CAAudioDeviceListModel::FireDefaultOutputDeviceChangedEvent(AudioDeviceID newID) { |
void CAAudioDeviceListModel::FireDefaultOutputDeviceChangedEvent(AudioDeviceID newID) { |
264 |
DeviceMutex.Lock(); |
LockGuard lock(DeviceMutex); |
265 |
for(int i = 0; i < GetListenerCount(); i++) { |
for(int i = 0; i < GetListenerCount(); i++) { |
266 |
GetListener(i)->DefaultOutputDeviceChanged(newID); |
GetListener(i)->DefaultOutputDeviceChanged(newID); |
267 |
} |
} |
|
DeviceMutex.Unlock(); |
|
268 |
} |
} |
269 |
|
|
270 |
AudioDeviceID CAAudioDeviceListModel::GetDefaultOutputDeviceID() { |
AudioDeviceID CAAudioDeviceListModel::GetDefaultOutputDeviceID() { |
272 |
} |
} |
273 |
|
|
274 |
UInt32 CAAudioDeviceListModel::GetOutputDeviceCount() { |
UInt32 CAAudioDeviceListModel::GetOutputDeviceCount() { |
275 |
DeviceMutex.Lock(); |
LockGuard lock(DeviceMutex); |
276 |
int size = outDevices.size(); |
return outDevices.size(); |
|
DeviceMutex.Unlock(); |
|
|
return size; |
|
277 |
} |
} |
278 |
|
|
279 |
CAAudioDeviceModel CAAudioDeviceListModel::GetOutputDevice(UInt32 Index) { |
CAAudioDeviceModel CAAudioDeviceListModel::GetOutputDevice(UInt32 Index) { |
280 |
DeviceMutex.Lock(); |
LockGuard lock(DeviceMutex); |
281 |
if(Index < 0 || Index >= GetOutputDeviceCount()) { |
if(Index < 0 || Index >= GetOutputDeviceCount()) { |
|
DeviceMutex.Unlock(); |
|
282 |
throw Exception("Device index out of bounds"); |
throw Exception("Device index out of bounds"); |
283 |
} |
} |
284 |
|
|
285 |
CAAudioDeviceModel dev = outDevices[Index]; |
return outDevices[Index]; |
|
DeviceMutex.Unlock(); |
|
|
return dev; |
|
286 |
} |
} |
287 |
|
|
288 |
CAAudioDeviceModel CAAudioDeviceListModel::GetOutputDeviceByID(AudioDeviceID devID) { |
CAAudioDeviceModel CAAudioDeviceListModel::GetOutputDeviceByID(AudioDeviceID devID) { |
289 |
DeviceMutex.Lock(); |
LockGuard lock(DeviceMutex); |
290 |
for(int i = 0; i < outDevices.size(); i++) { |
for(int i = 0; i < outDevices.size(); i++) { |
291 |
if(outDevices[i].GetID() == devID) { |
if(outDevices[i].GetID() == devID) { |
292 |
CAAudioDeviceModel dev = outDevices[i]; |
CAAudioDeviceModel dev = outDevices[i]; |
|
DeviceMutex.Unlock(); |
|
293 |
return dev; |
return dev; |
294 |
} |
} |
295 |
} |
} |
|
DeviceMutex.Unlock(); |
|
296 |
throw Exception("Unknown audio device ID: " + ToString(devID)); |
throw Exception("Unknown audio device ID: " + ToString(devID)); |
297 |
} |
} |
298 |
|
|
299 |
UInt32 CAAudioDeviceListModel::GetOutputDeviceIndex(AudioDeviceID devID) { |
UInt32 CAAudioDeviceListModel::GetOutputDeviceIndex(AudioDeviceID devID) { |
300 |
DeviceMutex.Lock(); |
LockGuard lock(DeviceMutex); |
301 |
for(UInt32 i = 0; i < outDevices.size(); i++) { |
for(UInt32 i = 0; i < outDevices.size(); i++) { |
302 |
if(outDevices[i].GetID() == devID) { |
if(outDevices[i].GetID() == devID) { |
|
DeviceMutex.Unlock(); |
|
303 |
return i; |
return i; |
304 |
} |
} |
305 |
} |
} |
|
DeviceMutex.Unlock(); |
|
306 |
throw Exception("Unknown audio device ID: " + ToString(devID)); |
throw Exception("Unknown audio device ID: " + ToString(devID)); |
307 |
} |
} |
308 |
|
|
309 |
void CAAudioDeviceListModel::RescanDevices() { |
void CAAudioDeviceListModel::RescanDevices() { |
310 |
DeviceMutex.Lock(); |
LockGuard lock(DeviceMutex); |
311 |
inDevices.clear(); |
inDevices.clear(); |
312 |
outDevices.clear(); |
outDevices.clear(); |
313 |
|
|
322 |
|
|
323 |
if(res) { |
if(res) { |
324 |
std::cerr << "Failed to get device list: " << res << std::endl; |
std::cerr << "Failed to get device list: " << res << std::endl; |
|
DeviceMutex.Unlock(); |
|
325 |
return; |
return; |
326 |
} |
} |
327 |
|
|
328 |
UInt32 deviceNumber = outSize / sizeof(AudioDeviceID); |
UInt32 deviceNumber = outSize / sizeof(AudioDeviceID); |
329 |
if(deviceNumber < 1) { |
if(deviceNumber < 1) { |
330 |
std::cerr << "No audio devices found" << std::endl; |
std::cerr << "No audio devices found" << std::endl; |
|
DeviceMutex.Unlock(); |
|
331 |
return; |
return; |
332 |
} |
} |
333 |
|
|
334 |
if(deviceNumber * sizeof(AudioDeviceID) != outSize) { |
if(deviceNumber * sizeof(AudioDeviceID) != outSize) { |
335 |
std::cerr << "Invalid device size. This is a bug!" << std::endl; |
std::cerr << "Invalid device size. This is a bug!" << std::endl; |
|
DeviceMutex.Unlock(); |
|
336 |
return; |
return; |
337 |
} |
} |
338 |
|
|
345 |
if(res) { |
if(res) { |
346 |
std::cerr << "Failed to get device IDs: " << res << std::endl; |
std::cerr << "Failed to get device IDs: " << res << std::endl; |
347 |
delete [] devs; |
delete [] devs; |
|
DeviceMutex.Unlock(); |
|
348 |
return; |
return; |
349 |
} |
} |
350 |
|
|
414 |
} |
} |
415 |
std::cout << std::endl; |
std::cout << std::endl; |
416 |
}*/ |
}*/ |
|
DeviceMutex.Unlock(); |
|
417 |
} |
} |
418 |
|
|
419 |
void CAAudioDeviceListModel::UpdateDefaultOutputDevice() { |
void CAAudioDeviceListModel::UpdateDefaultOutputDevice() { |