(OSX) Support video_monitor_index and audio_device settings

This commit is contained in:
meancoot 2013-09-07 21:29:58 -04:00
parent f926f954a1
commit 081e526bf9
2 changed files with 62 additions and 3 deletions

View File

@ -343,15 +343,23 @@ bool apple_game_view_has_focus(void)
bool apple_set_video_mode(unsigned width, unsigned height, bool fullscreen)
{
__block bool result = true;
#ifdef OSX
dispatch_sync(dispatch_get_main_queue(),
^{
// TODO: Multi-monitor support
// TODO: Sceen mode support
if (fullscreen && !g_has_went_fullscreen)
{
[g_view enterFullScreenMode:[NSScreen mainScreen] withOptions:nil];
if (g_settings.video.monitor_index >= [NSScreen screens].count)
{
apple_display_alert(@"Could not go fullscreen: Monitor index out of range.", nil);
result = false;
return;
}
[g_view enterFullScreenMode:[NSScreen screens][g_settings.video.monitor_index] withOptions:nil];
[NSCursor hide];
}
else if (!fullscreen && g_has_went_fullscreen)
@ -369,7 +377,7 @@ bool apple_set_video_mode(unsigned width, unsigned height, bool fullscreen)
// TODO: Maybe iOS users should be apple to show/hide the status bar here?
return true;
return result;
}
#ifdef IOS

View File

@ -22,6 +22,10 @@
#include "../boolean.h"
#include <pthread.h>
#ifdef OSX
#include <CoreAudio/CoreAudio.h>
#endif
#include <CoreAudio/CoreAudioTypes.h>
#include <AudioUnit/AudioUnit.h>
#include <AudioUnit/AUComponent.h>
@ -93,6 +97,48 @@ static OSStatus audio_write_cb(void *userdata, AudioUnitRenderActionFlags *actio
return noErr;
}
#ifdef OSX
static void choose_output_device(coreaudio_t *dev, const char* device)
{
AudioObjectPropertyAddress propaddr =
{
kAudioHardwarePropertyDevices,
kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMaster
};
UInt32 size = 0;
if (AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &propaddr, 0, 0, &size) != noErr)
return;
UInt32 deviceCount = size / sizeof(AudioDeviceID);
AudioDeviceID *devices = malloc(size);
if (!devices || AudioObjectGetPropertyData(kAudioObjectSystemObject, &propaddr, 0, 0, &size, devices) != noErr)
goto done;
propaddr.mScope = kAudioDevicePropertyScopeOutput;
propaddr.mSelector = kAudioDevicePropertyDeviceName;
size = 1024;
for (unsigned i = 0; i < deviceCount; i ++)
{
char device_name[1024];
device_name[0] = 0;
if (AudioObjectGetPropertyData(devices[i], &propaddr, 0, 0, &size, device_name) == noErr && strcmp(device_name, device) == 0)
{
AudioUnitSetProperty(dev->dev, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &devices[i], sizeof(AudioDeviceID));
goto done;
}
}
done:
free(devices);
}
#endif
static void *coreaudio_init(const char *device, unsigned rate, unsigned latency)
{
(void)device;
@ -121,6 +167,11 @@ static void *coreaudio_init(const char *device, unsigned rate, unsigned latency)
if (AudioComponentInstanceNew(comp, &dev->dev) != noErr)
goto error;
#ifdef OSX
if (device)
choose_output_device(dev, device);
#endif
dev->dev_alive = true;
// Set audio format