Fix device selection #40
4 changed files with 66 additions and 20 deletions
|
@ -26,7 +26,8 @@
|
||||||
- (id)initWithController:(OutputNode *)c;
|
- (id)initWithController:(OutputNode *)c;
|
||||||
|
|
||||||
- (BOOL)setup;
|
- (BOOL)setup;
|
||||||
- (BOOL)setOutputDevice:(AudioDeviceID)outputDevice;
|
- (OSStatus)setOutputDeviceByID:(AudioDeviceID)deviceID;
|
||||||
|
- (BOOL)setOutputDeviceWithDeviceDict:(NSDictionary *)deviceDict;
|
||||||
- (void)start;
|
- (void)start;
|
||||||
- (void)pause;
|
- (void)pause;
|
||||||
- (void)resume;
|
- (void)resume;
|
||||||
|
|
|
@ -71,7 +71,8 @@ static OSStatus Sound_Renderer(void *inRefCon, AudioUnitRenderActionFlags *ioAc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (OSStatus)setOutputDeviceByID:(AudioDeviceID)deviceID {
|
- (OSStatus)setOutputDeviceByID:(AudioDeviceID)deviceID
|
||||||
|
{
|
||||||
OSStatus err;
|
OSStatus err;
|
||||||
|
|
||||||
if (deviceID == -1) {
|
if (deviceID == -1) {
|
||||||
|
@ -85,10 +86,13 @@ static OSStatus Sound_Renderer(void *inRefCon, AudioUnitRenderActionFlags *ioAc
|
||||||
err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &theAddress, 0, NULL, &size, &deviceID);
|
err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &theAddress, 0, NULL, &size, &deviceID);
|
||||||
|
|
||||||
if (err != noErr) {
|
if (err != noErr) {
|
||||||
ALog(@"THERE'S NO DEFAULT OUTPUT DEVICE");
|
DLog(@"THERE'S NO DEFAULT OUTPUT DEVICE");
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
outputDeviceID = deviceID;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("DEVICE: %i\n", deviceID);
|
printf("DEVICE: %i\n", deviceID);
|
||||||
|
@ -101,6 +105,12 @@ static OSStatus Sound_Renderer(void *inRefCon, AudioUnitRenderActionFlags *ioAc
|
||||||
&deviceID,
|
&deviceID,
|
||||||
sizeof(AudioDeviceID));
|
sizeof(AudioDeviceID));
|
||||||
|
|
||||||
|
if (err != noErr) {
|
||||||
|
DLog(@"No output device with ID %d could be found.", deviceID);
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,6 +124,7 @@ static OSStatus Sound_Renderer(void *inRefCon, AudioUnitRenderActionFlags *ioAc
|
||||||
if (err != noErr) {
|
if (err != noErr) {
|
||||||
// Try matching by name.
|
// Try matching by name.
|
||||||
NSString *userDeviceName = deviceDict[@"name"];
|
NSString *userDeviceName = deviceDict[@"name"];
|
||||||
|
|
||||||
[self enumerateAudioOutputsUsingBlock:
|
[self enumerateAudioOutputsUsingBlock:
|
||||||
^(NSString *deviceName, AudioDeviceID deviceID, AudioDeviceID systemDefaultID, BOOL *stop) {
|
^(NSString *deviceName, AudioDeviceID deviceID, AudioDeviceID systemDefaultID, BOOL *stop) {
|
||||||
if ([deviceName isEqualToString:userDeviceName]) {
|
if ([deviceName isEqualToString:userDeviceName]) {
|
||||||
|
@ -124,12 +135,14 @@ static OSStatus Sound_Renderer(void *inRefCon, AudioUnitRenderActionFlags *ioAc
|
||||||
// Update `outputDevice`, in case the ID has changed.
|
// Update `outputDevice`, in case the ID has changed.
|
||||||
NSDictionary *deviceInfo = @{
|
NSDictionary *deviceInfo = @{
|
||||||
@"name": deviceName,
|
@"name": deviceName,
|
||||||
@"deviceID": [NSNumber numberWithUnsignedInt:deviceID],
|
@"deviceID": @(deviceID),
|
||||||
};
|
};
|
||||||
[[NSUserDefaults standardUserDefaults] setObject:deviceInfo forKey:@"outputDevice"];
|
[[NSUserDefaults standardUserDefaults] setObject:deviceInfo forKey:@"outputDevice"];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return;
|
DLog(@"Found output device: \"%@\" (%d).", deviceName, deviceID);
|
||||||
|
|
||||||
|
*stop = YES;
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
|
@ -329,6 +329,20 @@
|
||||||
remoteGlobalIDString = 8D5B49AC048680CD000E48DA;
|
remoteGlobalIDString = 8D5B49AC048680CD000E48DA;
|
||||||
remoteInfo = General;
|
remoteInfo = General;
|
||||||
};
|
};
|
||||||
|
3D2C77DC23FABECD00B3FAEC /* PBXContainerItemProxy */ = {
|
||||||
|
isa = PBXContainerItemProxy;
|
||||||
|
containerPortal = 83E6B750181612FD00D4576D /* Sparkle.xcodeproj */;
|
||||||
|
proxyType = 2;
|
||||||
|
remoteGlobalIDString = EA4311EA229D651300A5503D;
|
||||||
|
remoteInfo = bsdiff;
|
||||||
|
};
|
||||||
|
3D2C77DE23FABECD00B3FAEC /* PBXContainerItemProxy */ = {
|
||||||
|
isa = PBXContainerItemProxy;
|
||||||
|
containerPortal = 83E6B750181612FD00D4576D /* Sparkle.xcodeproj */;
|
||||||
|
proxyType = 2;
|
||||||
|
remoteGlobalIDString = EA4311A0229D5FBC00A5503D;
|
||||||
|
remoteInfo = ed25519;
|
||||||
|
};
|
||||||
566D321A0D538550004466A5 /* PBXContainerItemProxy */ = {
|
566D321A0D538550004466A5 /* PBXContainerItemProxy */ = {
|
||||||
isa = PBXContainerItemProxy;
|
isa = PBXContainerItemProxy;
|
||||||
containerPortal = 566D32160D538550004466A5 /* APL.xcodeproj */;
|
containerPortal = 566D32160D538550004466A5 /* APL.xcodeproj */;
|
||||||
|
@ -1758,6 +1772,8 @@
|
||||||
8319A68B1F79E99300C168D6 /* generate_appcast */,
|
8319A68B1F79E99300C168D6 /* generate_appcast */,
|
||||||
835C888622CC1853001B4B3F /* generate_keys */,
|
835C888622CC1853001B4B3F /* generate_keys */,
|
||||||
835C888822CC1853001B4B3F /* sign_update */,
|
835C888822CC1853001B4B3F /* sign_update */,
|
||||||
|
3D2C77DD23FABECD00B3FAEC /* libbsdiff.a */,
|
||||||
|
3D2C77DF23FABECD00B3FAEC /* libed25519.a */,
|
||||||
);
|
);
|
||||||
name = Products;
|
name = Products;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
@ -1943,7 +1959,6 @@
|
||||||
LastUpgradeCheck = 1100;
|
LastUpgradeCheck = 1100;
|
||||||
TargetAttributes = {
|
TargetAttributes = {
|
||||||
8D1107260486CEB800E47090 = {
|
8D1107260486CEB800E47090 = {
|
||||||
DevelopmentTeam = 4S876G9VCD;
|
|
||||||
ProvisioningStyle = Automatic;
|
ProvisioningStyle = Automatic;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -2152,6 +2167,20 @@
|
||||||
remoteRef = 17F5622D0C3BD8FB0019975C /* PBXContainerItemProxy */;
|
remoteRef = 17F5622D0C3BD8FB0019975C /* PBXContainerItemProxy */;
|
||||||
sourceTree = BUILT_PRODUCTS_DIR;
|
sourceTree = BUILT_PRODUCTS_DIR;
|
||||||
};
|
};
|
||||||
|
3D2C77DD23FABECD00B3FAEC /* libbsdiff.a */ = {
|
||||||
|
isa = PBXReferenceProxy;
|
||||||
|
fileType = archive.ar;
|
||||||
|
path = libbsdiff.a;
|
||||||
|
remoteRef = 3D2C77DC23FABECD00B3FAEC /* PBXContainerItemProxy */;
|
||||||
|
sourceTree = BUILT_PRODUCTS_DIR;
|
||||||
|
};
|
||||||
|
3D2C77DF23FABECD00B3FAEC /* libed25519.a */ = {
|
||||||
|
isa = PBXReferenceProxy;
|
||||||
|
fileType = archive.ar;
|
||||||
|
path = libed25519.a;
|
||||||
|
remoteRef = 3D2C77DE23FABECD00B3FAEC /* PBXContainerItemProxy */;
|
||||||
|
sourceTree = BUILT_PRODUCTS_DIR;
|
||||||
|
};
|
||||||
566D321B0D538550004466A5 /* APL.bundle */ = {
|
566D321B0D538550004466A5 /* APL.bundle */ = {
|
||||||
isa = PBXReferenceProxy;
|
isa = PBXReferenceProxy;
|
||||||
fileType = wrapper.cfbundle;
|
fileType = wrapper.cfbundle;
|
||||||
|
|
|
@ -9,18 +9,21 @@
|
||||||
[self setSelectsInsertedObjects:NO];
|
[self setSelectsInsertedObjects:NO];
|
||||||
|
|
||||||
NSDictionary *defaultDevice = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"outputDevice"];
|
NSDictionary *defaultDevice = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"outputDevice"];
|
||||||
|
NSString *defaultDeviceName = defaultDevice[@"name"];
|
||||||
|
NSNumber *defaultDeviceIDNum = defaultDevice[@"deviceID"];
|
||||||
|
AudioDeviceID defaultDeviceID = [defaultDeviceIDNum unsignedIntValue];
|
||||||
|
|
||||||
[self enumerateAudioOutputsUsingBlock:
|
[self enumerateAudioOutputsUsingBlock:
|
||||||
^(NSString *deviceName, AudioDeviceID deviceID, AudioDeviceID systemDefaultID, BOOL *stop) {
|
^(NSString *deviceName, AudioDeviceID deviceID, AudioDeviceID systemDefaultID, BOOL *stop) {
|
||||||
NSDictionary *deviceInfo = @{
|
NSDictionary *deviceInfo = @{
|
||||||
@"name": deviceName,
|
@"name": deviceName,
|
||||||
@"deviceID": [NSNumber numberWithUnsignedInt:deviceID],
|
@"deviceID": @(deviceID),
|
||||||
};
|
};
|
||||||
[self addObject:deviceInfo];
|
[self addObject:deviceInfo];
|
||||||
|
|
||||||
if (defaultDevice) {
|
if (defaultDevice) {
|
||||||
if (([[defaultDevice objectForKey:@"deviceID"] isEqualToNumber:[deviceInfo objectForKey:@"deviceID"]]) ||
|
if ((deviceID == defaultDeviceID) ||
|
||||||
([[defaultDevice objectForKey:@"name"] isEqualToString:[deviceInfo objectForKey:@"name"]])) {
|
([deviceName isEqualToString:defaultDeviceName])) {
|
||||||
[self setSelectedObjects:[NSArray arrayWithObject:deviceInfo]];
|
[self setSelectedObjects:[NSArray arrayWithObject:deviceInfo]];
|
||||||
// Update `outputDevice`, in case the ID has changed.
|
// Update `outputDevice`, in case the ID has changed.
|
||||||
[[NSUserDefaults standardUserDefaults] setObject:deviceInfo forKey:@"outputDevice"];
|
[[NSUserDefaults standardUserDefaults] setObject:deviceInfo forKey:@"outputDevice"];
|
||||||
|
|
Loading…
Reference in a new issue