2007-02-20 01:02:23 +00:00
|
|
|
#import "OutputsArrayController.h"
|
|
|
|
|
|
|
|
@implementation OutputsArrayController
|
|
|
|
|
|
|
|
- (void)awakeFromNib
|
|
|
|
{
|
|
|
|
[self removeObjects:[self arrangedObjects]];
|
|
|
|
|
|
|
|
[self setSelectsInsertedObjects:NO];
|
|
|
|
|
|
|
|
UInt32 propsize;
|
|
|
|
verify_noerr(AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &propsize, NULL));
|
|
|
|
int nDevices = propsize / sizeof(AudioDeviceID);
|
|
|
|
AudioDeviceID *devids = malloc(propsize);
|
|
|
|
verify_noerr(AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &propsize, devids));
|
|
|
|
int i;
|
2007-02-20 02:08:37 +00:00
|
|
|
|
|
|
|
NSDictionary *defaultDevice = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"outputDevice"];
|
|
|
|
|
2007-02-20 01:02:23 +00:00
|
|
|
for (i = 0; i < nDevices; ++i) {
|
2007-07-07 03:59:57 +00:00
|
|
|
char name[256];
|
|
|
|
UInt32 maxlen = 256;
|
2007-02-20 01:02:23 +00:00
|
|
|
verify_noerr(AudioDeviceGetProperty(devids[i], 0, false, kAudioDevicePropertyDeviceName, &maxlen, name));
|
|
|
|
|
|
|
|
// Ignore devices that have no output channels:
|
|
|
|
// This tells us the size of the buffer required to hold the information about the channels
|
|
|
|
UInt32 propSize;
|
|
|
|
verify_noerr(AudioDeviceGetPropertyInfo(devids[i], 0, false, kAudioDevicePropertyStreamConfiguration, &propSize, NULL));
|
|
|
|
// Knowing the size of the required buffer, we can determine how many channels there are
|
|
|
|
// without actually allocating a buffer and requesting the information.
|
|
|
|
// (we don't care about the exact number of channels, only if there are more than zero or not)
|
|
|
|
if (propSize <= sizeof(UInt32)) continue;
|
|
|
|
|
|
|
|
NSObject *deviceInfo = [NSDictionary dictionaryWithObjectsAndKeys:
|
2007-07-07 03:59:57 +00:00
|
|
|
[NSString stringWithUTF8String:name], @"name",
|
2007-02-20 01:02:23 +00:00
|
|
|
[NSNumber numberWithLong:devids[i]], @"deviceID",
|
|
|
|
nil];
|
|
|
|
[self addObject:deviceInfo];
|
2007-02-20 02:08:37 +00:00
|
|
|
|
|
|
|
if (defaultDevice) {
|
|
|
|
if ([[defaultDevice objectForKey:@"deviceID"] isEqualToNumber:[deviceInfo objectForKey:@"deviceID"]]) {
|
|
|
|
[self setSelectedObjects:[NSArray arrayWithObject:deviceInfo]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|