[vlc-commits] macOS: Move NSSound category to its own file
Marvin Scholz
git at videolan.org
Thu Mar 16 09:15:39 CET 2017
vlc | branch: master | Marvin Scholz <epirat07 at gmail.com> | Thu Mar 16 09:15:16 2017 +0100| [2e87ed387f435833768b134da36c340ce9efda61] | committer: 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.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2e87ed387f435833768b134da36c340ce9efda61
---
.../package/macosx/VLC.xcodeproj/project.pbxproj | 6 ++
modules/gui/macosx/Makefile.am | 1 +
modules/gui/macosx/NSSound+VLCAdditions.h | 40 ++++++++
modules/gui/macosx/NSSound+VLCAdditions.m | 109 +++++++++++++++++++++
modules/gui/macosx/VLCCoreInteraction.m | 2 +
modules/gui/macosx/misc.h | 16 ---
modules/gui/macosx/misc.m | 91 -----------------
7 files changed, 158 insertions(+), 107 deletions(-)
diff --git a/extras/package/macosx/VLC.xcodeproj/project.pbxproj b/extras/package/macosx/VLC.xcodeproj/project.pbxproj
index dbbf882..55e1fdb 100644
--- a/extras/package/macosx/VLC.xcodeproj/project.pbxproj
+++ b/extras/package/macosx/VLC.xcodeproj/project.pbxproj
@@ -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 */,
diff --git a/modules/gui/macosx/Makefile.am b/modules/gui/macosx/Makefile.am
index be1148d..f4b4eec 100644
--- a/modules/gui/macosx/Makefile.am
+++ b/modules/gui/macosx/Makefile.am
@@ -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 \
diff --git a/modules/gui/macosx/NSSound+VLCAdditions.h b/modules/gui/macosx/NSSound+VLCAdditions.h
new file mode 100644
index 0000000..290b343
--- /dev/null
+++ b/modules/gui/macosx/NSSound+VLCAdditions.h
@@ -0,0 +1,40 @@
+/*****************************************************************************
+ * NSSound+VLCAdditions.h: Category that adds system volume control
+ *****************************************************************************
+ * Copyright (C) 2003-2014 VLC authors and VideoLAN
+ * $Id$
+ *
+ * Authors: Jon Lech Johansen <jon-vl at 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).
+ */
+ at interface NSSound (VLCAdditions)
+
++ (float)systemVolumeForChannel:(int)channel;
++ (bool)setSystemVolume:(float)volume forChannel:(int)channel;
++ (void)increaseSystemVolume;
++ (void)decreaseSystemVolume;
+
+ at end
diff --git a/modules/gui/macosx/NSSound+VLCAdditions.m b/modules/gui/macosx/NSSound+VLCAdditions.m
new file mode 100644
index 0000000..bd81bb7
--- /dev/null
+++ b/modules/gui/macosx/NSSound+VLCAdditions.m
@@ -0,0 +1,109 @@
+/*****************************************************************************
+ * NSSound+VLCAdditions.m: Category that adds system volume control
+ *****************************************************************************
+ * Copyright (C) 2003-2014 VLC authors and VideoLAN
+ * $Id$
+ *
+ * Authors: Jon Lech Johansen <jon-vl at 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>
+
+ at 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];
+}
+
+ at end
diff --git a/modules/gui/macosx/VLCCoreInteraction.m b/modules/gui/macosx/VLCCoreInteraction.m
index 7727539..6081e0a 100644
--- a/modules/gui/macosx/VLCCoreInteraction.m
+++ b/modules/gui/macosx/VLCCoreInteraction.m
@@ -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)
{
diff --git a/modules/gui/macosx/misc.h b/modules/gui/macosx/misc.h
index 2f7060a..848c8eb 100644
--- a/modules/gui/macosx/misc.h
+++ b/modules/gui/macosx/misc.h
@@ -25,22 +25,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).
- *****************************************************************************/
-
- at interface NSSound (VLCAdditions)
-+ (float)systemVolumeForChannel:(int)channel;
-+ (bool)setSystemVolume:(float)volume forChannel:(int)channel;
-+ (void)increaseSystemVolume;
-+ (void)decreaseSystemVolume;
- at end
-
-/*****************************************************************************
* NSAnimation (VLCAddition)
*****************************************************************************/
diff --git a/modules/gui/macosx/misc.m b/modules/gui/macosx/misc.m
index f6084c8..0db3b96 100644
--- a/modules/gui/macosx/misc.m
+++ b/modules/gui/macosx/misc.m
@@ -29,102 +29,11 @@
#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).
- *****************************************************************************/
-
- at 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];
-}
-
- at end
-
-/*****************************************************************************
* NSAnimation (VLCAdditions)
*
* Missing extension to NSAnimation
More information about the vlc-commits
mailing list