Commit dd0b6208 authored by Felix Paul Kühne's avatar Felix Paul Kühne

macosx: added an option to let the Apple Remote control the system volume...

macosx: added an option to let the Apple Remote control the system volume instead of VLC's volume (close #1071)
parent a754b006
......@@ -3767,7 +3767,7 @@ then
VLC_ADD_OBJCFLAGS([macosx minimal_macosx], [-fobjc-exceptions] )
VLC_ADD_PLUGIN([macosx minimal_macosx])
VLC_ADD_LIBS([macosx], [-Wl,-framework,QTKit -Wl,-framework,IOKit -Wl,-framework,AddressBook -Wl,-framework,WebKit])
VLC_ADD_LIBS([macosx], [-Wl,-framework,QTKit -Wl,-framework,IOKit -Wl,-framework,AddressBook -Wl,-framework,WebKit -Wl,-framework,CoreAudio])
if test ! -d ${CONTRIB_DIR}/Sparkle.framework
then
......
......@@ -1003,10 +1003,16 @@ static VLCMain *_o_sharedMainInstance = nil;
}
break;
case kRemoteButtonVolume_Plus:
[[VLCCoreInteraction sharedInstance] volumeUp];
if (config_GetInt( VLCIntf, "macosx-appleremote-sysvol"))
[NSSound increaseSystemVolume];
else
[[VLCCoreInteraction sharedInstance] volumeUp];
break;
case kRemoteButtonVolume_Minus:
[[VLCCoreInteraction sharedInstance] volumeDown];
if (config_GetInt( VLCIntf, "macosx-appleremote-sysvol"))
[NSSound decreaseSystemVolume];
else
[[VLCCoreInteraction sharedInstance] volumeDown];
break;
case kRemoteButtonRight:
[[VLCCoreInteraction sharedInstance] next];
......
......@@ -80,6 +80,9 @@ void WindowClose ( vout_window_t * );
#define USE_APPLE_REMOTE_TEXT N_("Control playback with the Apple Remote")
#define USE_APPLE_REMOTE_LONGTEXT N_("By default, VLC can be remotely controlled with the Apple Remote.")
#define USE_APPLE_REMOTE_VOLUME_TEXT N_("Control system volume with the Apple Remote")
#define USE_APPLE_REMOTE_VOLUME_LONGTEXT N_("By default, VLC will control its own volume with the Apple Remote. However, you can choose to control the global system volume instead.")
#define USE_MEDIAKEYS_TEXT N_("Control playback with media keys")
#define USE_MEDIAKEYS_LONGTEXT N_("By default, VLC can be controlled using the media keys on modern Apple " \
"keyboards.")
......@@ -124,6 +127,7 @@ vlc_module_begin ()
add_bool( "macosx-recentitems", true, RECENT_ITEMS_TEXT, RECENT_ITEMS_LONGTEXT, false )
add_bool( "macosx-fspanel", true, FSPANEL_TEXT, FSPANEL_LONGTEXT, false )
add_bool( "macosx-appleremote", true, USE_APPLE_REMOTE_TEXT, USE_APPLE_REMOTE_LONGTEXT, false )
add_bool( "macosx-appleremote-sysvol", false, USE_APPLE_REMOTE_VOLUME_TEXT, USE_APPLE_REMOTE_VOLUME_LONGTEXT, false )
add_bool( "macosx-mediakeys", true, USE_MEDIAKEYS_TEXT, USE_MEDIAKEYS_LONGTEXT, false )
add_bool( "macosx-interfacestyle", false, INTERFACE_STYLE_TEXT, INTERFACE_STYLE_LONGTEXT, false )
add_bool( "macosx-nativefullscreenmode", false, NATIVE_FULLSCREEN_MODE_ON_LION_TEXT, NATIVE_FULLSCREEN_MODE_ON_LION_LONGTEXT, false )
......
/*****************************************************************************
* misc.h: code not specific to vlc
*****************************************************************************
* Copyright (C) 2003-2011 VLC authors and VideoLAN
* Copyright (C) 2003-2012 VLC authors and VideoLAN
* $Id$
*
* Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
......@@ -25,6 +25,22 @@
#import <Cocoa/Cocoa.h>
#import "CompatibilityFixes.h"
/*****************************************************************************
* NSSound (VLCAdditions)
*
* added code to change the system volume, needed for the apple remote code
* this is simplified code, which won't let you set the exact volume
* (that's what the audio output is for after all), but just the system volume
* in steps of 1/16 (matching the default AR or volume key implementation).
*****************************************************************************/
@interface NSSound (VLCAdditions)
+ (float)systemVolumeForChannel:(int)channel;
+ (bool)setSystemVolume:(float)volume forChannel:(int)channel;
+ (void)increaseSystemVolume;
+ (void)decreaseSystemVolume;
@end
/*****************************************************************************
* NSAnimation (VLCAddition)
*****************************************************************************/
......
/*****************************************************************************
* misc.m: code not specific to vlc
*****************************************************************************
* Copyright (C) 2003-2011 VLC authors and VideoLAN
* Copyright (C) 2003-2012 VLC authors and VideoLAN
* $Id$
*
* Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
......@@ -27,6 +27,100 @@
#import "MainWindow.h"
#import "controls.h"
#import "CoreInteraction.h"
#import <CoreAudio/CoreAudio.h>
/*****************************************************************************
* NSSound (VLCAdditions)
*
* added code to change the system volume, needed for the apple remote code
* this is simplified code, which won't let you set the exact volume
* (that's what the audio output is for after all), but just the system volume
* in steps of 1/16 (matching the default AR or volume key implementation).
*****************************************************************************/
@implementation NSSound (VLCAdditions)
+ (float)systemVolumeForChannel:(int)channel
{
AudioDeviceID i_device;
float f_volume;
OSStatus err;
UInt32 i_size;
i_size = sizeof( i_device );
AudioObjectPropertyAddress deviceAddress = { kAudioHardwarePropertyDefaultOutputDevice, kAudioDevicePropertyScopeOutput, kAudioObjectPropertyElementMaster };
err = AudioObjectGetPropertyData( kAudioObjectSystemObject, &deviceAddress, 0, NULL, &i_size, &i_device );
if (err != noErr)
{
msg_Warn( VLCIntf, "couldn't get main audio output device" );
return .0;
}
AudioObjectPropertyAddress propertyAddress = { kAudioDevicePropertyVolumeScalar, kAudioDevicePropertyScopeOutput, channel };
i_size = sizeof( f_volume );
err = AudioObjectGetPropertyData(i_device, &propertyAddress, 0, NULL, &i_size, &f_volume);
if (err != noErr)
{
msg_Warn( VLCIntf, "couldn't get volume value" );
return .0;
}
return f_volume;
}
+ (bool)setSystemVolume:(float)f_volume forChannel:(int)i_channel
{
/* the following code will fail on S/PDIF devices. there is an easy work-around, but we'd like to match the OS behavior */
AudioDeviceID i_device;
OSStatus err;
UInt32 i_size;
Boolean b_writeable;
i_size = sizeof( i_device );
AudioObjectPropertyAddress deviceAddress = { kAudioHardwarePropertyDefaultOutputDevice, kAudioDevicePropertyScopeOutput, kAudioObjectPropertyElementMaster };
err = AudioObjectGetPropertyData( kAudioObjectSystemObject, &deviceAddress, 0, NULL, &i_size, &i_device );
if (err != noErr)
{
msg_Warn( VLCIntf, "couldn't get main audio output device" );
return NO;
}
AudioObjectPropertyAddress propertyAddress = { kAudioDevicePropertyVolumeScalar, kAudioDevicePropertyScopeOutput, i_channel };
i_size = sizeof( f_volume );
err = AudioObjectIsPropertySettable( i_device, &propertyAddress, &b_writeable );
if (err != noErr || !b_writeable ) {
msg_Warn( VLCIntf, "we can't set the main audio devices' volume" );
return NO;
}
err = AudioObjectSetPropertyData(i_device, &propertyAddress, 0, NULL, i_size, &f_volume);
return YES;
}
+ (void)increaseSystemVolume
{
float f_volume = [NSSound systemVolumeForChannel:1]; // we trust that mono is always available and that all channels got the same volume
f_volume += .0625; // 1/16 to match the OS
bool b_returned = YES;
/* since core audio doesn't provide a reasonable way to see how many channels we got, let's see how long we can do this */
for (NSUInteger x = 1; b_returned ; x++)
b_returned = [NSSound setSystemVolume: f_volume forChannel:x];
}
+ (void)decreaseSystemVolume
{
float f_volume = [NSSound systemVolumeForChannel:1]; // we trust that mono is always available and that all channels got the same volume
f_volume -= .0625; // 1/16 to match the OS
bool b_returned = YES;
/* since core audio doesn't provide a reasonable way to see how many channels we got, let's see how long we can do this */
for (NSUInteger x = 1; b_returned ; x++)
b_returned = [NSSound setSystemVolume: f_volume forChannel:x];
}
@end
/*****************************************************************************
* NSAnimation (VLCAdditions)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment