Commit 2e87ed38 authored by Marvin Scholz's avatar Marvin Scholz

macOS: Move NSSound category to its own file

This makes it easier to find the relevant code and
additionally has the benefit that imports can be more fine-grained
in the future, instead of just having one misc.h import,
where it is hard to know, without looking at it, what it is
actually needed for.
parent 37db5187
......@@ -164,6 +164,7 @@
6B3BE4321E621F24008D098A /* VLCHUDToggleButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B3BE4311E621F24008D098A /* VLCHUDToggleButton.m */; };
6B4D50901E79781F004479B5 /* VLCHotkeyChangeWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B4D508F1E79781F004479B5 /* VLCHotkeyChangeWindow.m */; };
6B4D50931E7979CB004479B5 /* VLCSimplePrefsWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B4D50921E7979CB004479B5 /* VLCSimplePrefsWindow.m */; };
6B4D50961E7A7D16004479B5 /* NSSound+VLCAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B4D50951E7A7D16004479B5 /* NSSound+VLCAdditions.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
......@@ -202,6 +203,8 @@
6B4D508F1E79781F004479B5 /* VLCHotkeyChangeWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCHotkeyChangeWindow.m; sourceTree = "<group>"; };
6B4D50911E7979CB004479B5 /* VLCSimplePrefsWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCSimplePrefsWindow.h; sourceTree = "<group>"; };
6B4D50921E7979CB004479B5 /* VLCSimplePrefsWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCSimplePrefsWindow.m; sourceTree = "<group>"; };
6B4D50941E7A7D16004479B5 /* NSSound+VLCAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSSound+VLCAdditions.h"; sourceTree = "<group>"; };
6B4D50951E7A7D16004479B5 /* NSSound+VLCAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSSound+VLCAdditions.m"; sourceTree = "<group>"; };
6B6A499A1DFD9B23009128AC /* VLCDefaultValueSlider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCDefaultValueSlider.h; sourceTree = "<group>"; };
6B6A499B1DFD9B23009128AC /* VLCDefaultValueSlider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCDefaultValueSlider.m; sourceTree = "<group>"; };
6B6A499C1DFD9B23009128AC /* VLCDefaultValueSliderCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCDefaultValueSliderCell.h; sourceTree = "<group>"; };
......@@ -985,6 +988,8 @@
CC017A0C14A4C8AF00C09A4F /* VLCMainWindowTitleView.m */,
8ED6C27F03E2EB1C0059A3A7 /* misc.h */,
8ED6C28003E2EB1C0059A3A7 /* misc.m */,
6B4D50941E7A7D16004479B5 /* NSSound+VLCAdditions.h */,
6B4D50951E7A7D16004479B5 /* NSSound+VLCAdditions.m */,
8ED6C28103E2EB1C0059A3A7 /* VLCOpenWindowController.h */,
8ED6C28203E2EB1C0059A3A7 /* VLCOpenWindowController.m */,
8E55FB7F0459B0FD00FB3317 /* VLCOutput.h */,
......@@ -1935,6 +1940,7 @@
1C3114031E508C8800D4DD76 /* AppleRemote.m in Sources */,
1C3114041E508C8800D4DD76 /* SideBarItem.h in Sources */,
1C3114051E508C8800D4DD76 /* SideBarItem.m in Sources */,
6B4D50961E7A7D16004479B5 /* NSSound+VLCAdditions.m in Sources */,
1C3114061E508C8800D4DD76 /* PXSourceList.h in Sources */,
1C3114071E508C8800D4DD76 /* PXSourceList.m in Sources */,
1C3114081E508C8800D4DD76 /* PXSourceListDataSource.h in Sources */,
......
......@@ -44,6 +44,7 @@ libmacosx_plugin_la_SOURCES = \
VLCMainMenu.h VLCMainMenu.m \
VLCMainWindowTitleView.h VLCMainWindowTitleView.m \
misc.h misc.m \
NSSound+VLCAdditions.h NSSound+VLCAdditions.m \
VLCOpenWindowController.h VLCOpenWindowController.m \
VLCOutput.h VLCOutput.m \
VLCPlaylistView.h VLCPlaylistView.m \
......
/*****************************************************************************
* NSSound+VLCAdditions.h: Category that adds system volume control
*****************************************************************************
* Copyright (C) 2003-2014 VLC authors and VideoLAN
* $Id$
*
* Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
* Felix Paul Kühne <fkuehne at videolan dot org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#import <Cocoa/Cocoa.h>
/* Adds methods 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
/*****************************************************************************
* NSSound+VLCAdditions.m: Category that adds system volume control
*****************************************************************************
* Copyright (C) 2003-2014 VLC authors and VideoLAN
* $Id$
*
* Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
* Felix Paul Kühne <fkuehne at videolan dot org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#import "NSSound+VLCAdditions.h"
#import "VLCMain.h"
#import <CoreAudio/CoreAudio.h>
@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( getIntf(), "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( getIntf(), "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( getIntf(), "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( getIntf(), "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
......@@ -41,6 +41,8 @@
#import "AppleRemote.h"
#import "VLCInputManager.h"
#import "NSSound+VLCAdditions.h"
static int BossCallback(vlc_object_t *p_this, const char *psz_var,
vlc_value_t oldval, vlc_value_t new_val, void *param)
{
......
......@@ -24,22 +24,6 @@
#import <Cocoa/Cocoa.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)
*****************************************************************************/
......
......@@ -29,101 +29,10 @@
#import "VLCMainMenu.h"
#import "VLCControlsBarCommon.h"
#import "VLCCoreInteraction.h"
#import <CoreAudio/CoreAudio.h>
#import <vlc_keys.h>
NSString *const VLCOpenTextFieldWasClicked = @"VLCOpenTextFieldWasClicked";
/*****************************************************************************
* 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( getIntf(), "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( getIntf(), "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( getIntf(), "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( getIntf(), "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