Output: Add System Default Output option, rather than adjusting the listing to display the current system default only the first time

CQTexperiment
Christopher Snowhill 2021-12-05 22:49:56 -08:00
parent 554dde4e91
commit ed8a5763ab
2 changed files with 8 additions and 8 deletions

View File

@ -83,7 +83,6 @@ static OSStatus Sound_Renderer(void *inRefCon, AudioUnitRenderActionFlags *ioAc
OSStatus err; OSStatus err;
if (deviceID == -1) { if (deviceID == -1) {
DLog(@"DEVICE IS -1");
UInt32 size = sizeof(AudioDeviceID); UInt32 size = sizeof(AudioDeviceID);
AudioObjectPropertyAddress theAddress = { AudioObjectPropertyAddress theAddress = {
.mSelector = kAudioHardwarePropertyDefaultOutputDevice, .mSelector = kAudioHardwarePropertyDefaultOutputDevice,

View File

@ -10,6 +10,12 @@
[self setSelectsInsertedObjects:NO]; [self setSelectsInsertedObjects:NO];
NSDictionary *defaultDeviceInfo = @{
@"name": @"System Default Device",
@"deviceID": @(-1),
};
[self addObject:defaultDeviceInfo];
NSDictionary *defaultDevice = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"outputDevice"]; NSDictionary *defaultDevice = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"outputDevice"];
NSString *defaultDeviceName = defaultDevice[@"name"]; NSString *defaultDeviceName = defaultDevice[@"name"];
NSNumber *defaultDeviceIDNum = defaultDevice[@"deviceID"]; NSNumber *defaultDeviceIDNum = defaultDevice[@"deviceID"];
@ -23,7 +29,7 @@
}; };
[self addObject:deviceInfo]; [self addObject:deviceInfo];
if (defaultDevice) { if (defaultDevice && defaultDeviceID != -1) {
if ((deviceID == defaultDeviceID) || if ((deviceID == defaultDeviceID) ||
([deviceName isEqualToString:defaultDeviceName])) { ([deviceName isEqualToString:defaultDeviceName])) {
[self setSelectedObjects:[NSArray arrayWithObject:deviceInfo]]; [self setSelectedObjects:[NSArray arrayWithObject:deviceInfo]];
@ -31,14 +37,9 @@
[[NSUserDefaults standardUserDefaults] setObject:deviceInfo forKey:@"outputDevice"]; [[NSUserDefaults standardUserDefaults] setObject:deviceInfo forKey:@"outputDevice"];
} }
} }
else {
if (deviceID == systemDefaultID) {
[self setSelectedObjects:[NSArray arrayWithObject:deviceInfo]];
}
}
}]; }];
if (!defaultDevice) { if (!defaultDevice || defaultDeviceID == -1) {
[self setSelectionIndex:0]; [self setSelectionIndex:0];
} }
} }