2007-02-20 01:02:23 +00:00
|
|
|
#import "OutputsArrayController.h"
|
|
|
|
|
|
|
|
@implementation OutputsArrayController
|
|
|
|
|
|
|
|
- (void)awakeFromNib
|
|
|
|
{
|
|
|
|
[self removeObjects:[self arrangedObjects]];
|
|
|
|
|
|
|
|
[self setSelectsInsertedObjects:NO];
|
|
|
|
|
|
|
|
UInt32 propsize;
|
2013-10-03 08:00:58 +00:00
|
|
|
AudioObjectPropertyAddress theAddress = {
|
|
|
|
.mSelector = kAudioHardwarePropertyDevices,
|
|
|
|
.mScope = kAudioObjectPropertyScopeGlobal,
|
|
|
|
.mElement = kAudioObjectPropertyElementMaster
|
|
|
|
};
|
|
|
|
verify_noerr(AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &theAddress, 0, NULL, &propsize));
|
|
|
|
int nDevices = propsize / sizeof(AudioDeviceID);
|
2007-02-20 01:02:23 +00:00
|
|
|
AudioDeviceID *devids = malloc(propsize);
|
2013-10-03 08:00:58 +00:00
|
|
|
verify_noerr(AudioObjectGetPropertyData(kAudioObjectSystemObject, &theAddress, 0, NULL, &propsize, devids));
|
2007-02-20 01:02:23 +00:00
|
|
|
int i;
|
2013-10-03 08:00:58 +00:00
|
|
|
|
|
|
|
theAddress.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
|
|
|
|
AudioDeviceID systemDefault;
|
|
|
|
propsize = sizeof(systemDefault);
|
|
|
|
verify_noerr(AudioObjectGetPropertyData(kAudioObjectSystemObject, &theAddress, 0, NULL, &propsize, &systemDefault));
|
2007-02-20 02:08:37 +00:00
|
|
|
|
|
|
|
NSDictionary *defaultDevice = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"outputDevice"];
|
|
|
|
|
2013-10-03 08:00:58 +00:00
|
|
|
theAddress.mScope = kAudioDevicePropertyScopeOutput;
|
|
|
|
|
2007-02-20 01:02:23 +00:00
|
|
|
for (i = 0; i < nDevices; ++i) {
|
2013-10-03 08:00:58 +00:00
|
|
|
CFStringRef name = NULL;
|
|
|
|
propsize = sizeof(name);
|
|
|
|
theAddress.mSelector = kAudioDevicePropertyDeviceNameCFString;
|
|
|
|
verify_noerr(AudioObjectGetPropertyData(devids[i], &theAddress, 0, NULL, &propsize, &name));
|
2007-02-20 01:02:23 +00:00
|
|
|
|
2013-10-09 20:52:39 +00:00
|
|
|
propsize = 0;
|
2013-10-03 08:00:58 +00:00
|
|
|
theAddress.mSelector = kAudioDevicePropertyStreamConfiguration;
|
|
|
|
verify_noerr(AudioObjectGetPropertyDataSize(devids[i], &theAddress, 0, NULL, &propsize));
|
2013-10-09 20:52:39 +00:00
|
|
|
|
|
|
|
if (propsize < sizeof(UInt32)) continue;
|
|
|
|
|
|
|
|
AudioBufferList * bufferList = (AudioBufferList *) malloc(propsize);
|
|
|
|
verify_noerr(AudioObjectGetPropertyData(devids[i], &theAddress, 0, NULL, &propsize, bufferList));
|
|
|
|
UInt32 bufferCount = bufferList->mNumberBuffers;
|
|
|
|
free(bufferList);
|
|
|
|
|
|
|
|
if (!bufferCount) continue;
|
2007-02-20 01:02:23 +00:00
|
|
|
|
2008-06-21 05:04:23 +00:00
|
|
|
NSDictionary *deviceInfo = [NSDictionary dictionaryWithObjectsAndKeys:
|
2013-10-03 08:00:58 +00:00
|
|
|
[NSString stringWithString:(NSString*)name], @"name",
|
2007-02-20 01:02:23 +00:00
|
|
|
[NSNumber numberWithLong:devids[i]], @"deviceID",
|
|
|
|
nil];
|
|
|
|
[self addObject:deviceInfo];
|
2013-10-03 08:00:58 +00:00
|
|
|
|
|
|
|
CFRelease(name);
|
2007-02-20 02:08:37 +00:00
|
|
|
|
|
|
|
if (defaultDevice) {
|
|
|
|
if ([[defaultDevice objectForKey:@"deviceID"] isEqualToNumber:[deviceInfo objectForKey:@"deviceID"]]) {
|
|
|
|
[self setSelectedObjects:[NSArray arrayWithObject:deviceInfo]];
|
|
|
|
}
|
|
|
|
}
|
2013-10-03 08:00:58 +00:00
|
|
|
else {
|
|
|
|
if ( devids[i] == systemDefault ) {
|
|
|
|
[self setSelectedObjects:[NSArray arrayWithObject:deviceInfo]];
|
|
|
|
}
|
|
|
|
}
|
2007-02-20 02:08:37 +00:00
|
|
|
|
2007-02-20 01:02:23 +00:00
|
|
|
[deviceInfo release];
|
|
|
|
}
|
|
|
|
free(devids);
|
|
|
|
|
2007-02-20 02:08:37 +00:00
|
|
|
|
|
|
|
if (!defaultDevice)
|
|
|
|
[self setSelectionIndex:0];
|
2007-02-20 01:02:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|