Skip to content

Commit

Permalink
Merge branch 'release/1.1.2'
Browse files Browse the repository at this point in the history
iain8 committed Jul 16, 2017
2 parents 1d366b3 + c613942 commit 99f1ad2
Showing 12 changed files with 337 additions and 11 deletions.
14 changes: 9 additions & 5 deletions FaderBar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
@@ -50,8 +50,8 @@
AE8715B91E0F0AD300F98C06 /* SystemTask.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SystemTask.swift; sourceTree = "<group>"; };
AE8D0FD61DF600BA00CCC45E /* CoreAudio.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreAudio.framework; path = System/Library/Frameworks/CoreAudio.framework; sourceTree = SDKROOT; };
AE8D0FD81DF601E900CCC45E /* FaderBar-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "FaderBar-Bridging-Header.h"; sourceTree = "<group>"; };
AE8D0FD91DF601EA00CCC45E /* ISSoundAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ISSoundAdditions.h; path = "../../../Downloads/ISSoundAdditions-master/ISSoundAdditions.h"; sourceTree = "<group>"; };
AE8D0FDA1DF601EA00CCC45E /* ISSoundAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ISSoundAdditions.m; path = "../../../Downloads/ISSoundAdditions-master/ISSoundAdditions.m"; sourceTree = "<group>"; };
AE8D0FD91DF601EA00CCC45E /* ISSoundAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ISSoundAdditions.h; path = FaderBar/ISSoundAdditions.h; sourceTree = SOURCE_ROOT; };
AE8D0FDA1DF601EA00CCC45E /* ISSoundAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ISSoundAdditions.m; path = FaderBar/ISSoundAdditions.m; sourceTree = SOURCE_ROOT; };
AEAE7E3A1DF33A5900B0774E /* FaderBar.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FaderBar.app; sourceTree = BUILT_PRODUCTS_DIR; };
AEAE7E3D1DF33A5900B0774E /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
AEAE7E3F1DF33A5900B0774E /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@@ -222,7 +222,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0810;
LastUpgradeCheck = 0810;
LastUpgradeCheck = 0820;
ORGANIZATIONNAME = iain;
TargetAttributes = {
AEAE7E391DF33A5900B0774E = {
@@ -368,11 +368,12 @@
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "-";
COPY_PHASE_STRIP = NO;
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
@@ -396,6 +397,7 @@
SDKROOT = macosx;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
VALID_ARCHS = x86_64;
};
name = Debug;
};
@@ -417,11 +419,12 @@
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "-";
COPY_PHASE_STRIP = NO;
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
@@ -437,6 +440,7 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
VALID_ARCHS = x86_64;
};
name = Release;
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0810"
LastUpgradeVersion = "0820"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
6 changes: 3 additions & 3 deletions FaderBar/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
{
"size" : "16x16",
"idiom" : "mac",
"filename" : "pug32-1.png",
"filename" : "pug32.png",
"scale" : "2x"
},
{
@@ -33,7 +33,7 @@
{
"size" : "128x128",
"idiom" : "mac",
"filename" : "pug256-1.png",
"filename" : "pug256.png",
"scale" : "2x"
},
{
@@ -45,7 +45,7 @@
{
"size" : "256x256",
"idiom" : "mac",
"filename" : "ItunesArtwork-1.png",
"filename" : "ItunesArtwork.png",
"scale" : "2x"
},
{
Binary file not shown.
Binary file modified FaderBar/Assets.xcassets/AppIcon.appiconset/ItunesArtwork.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file modified FaderBar/Assets.xcassets/AppIcon.appiconset/pug256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
58 changes: 58 additions & 0 deletions FaderBar/ISSoundAdditions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// ISSoundAdditions.m (ver 1.2 - 2012.10.27)
//
// Created by Massimo Moiso (2012-09) InerziaSoft
// based on an idea of Antonio Nunes, SintraWorks
//
// Permission is granted free of charge to use this code without restriction
// and without limitation, with the only condition that the copyright
// notice and this permission shall be included in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

/*
GOAL
This is a category of NSSound build using CoreAudio to get and set the volume of the
system sound and some other utility.
It was implemented using the Apple documentation and various unattributed code fragments
found on the net. For this reason, its use is free for all.
USE
To maintain the Cocoa conventions, a property-like syntax was used; the following
methods ("properties") are available:
(float)systemVolume - return the volume of the default sound device
setSystemVolume(float) - set the volume of the default sound device
(AudioDeviceID)defaultOutputDevice - return the default output device
applyMute(boolean) - enable or disable muting, if supported
REQUIREMENTS
At least MacOS X 10.6
Core Audio Framework
*/

#import <Cocoa/Cocoa.h>
#import <CoreAudio/CoreAudio.h>
#import <AudioToolbox/AudioServices.h>

@interface NSSound (ISSoundAdditions)

+ (AudioDeviceID)defaultOutputDevice;

+ (float)systemVolume;
+ (void)setSystemVolume:(float)inVolume;

+ (void)increaseSystemVolumeBy:(float)amount;
+ (void)decreaseSystemVolumeBy:(float)amount;

+ (void)applyMute:(Boolean)m;

#define THRESHOLD 0.005 //if the volume should be set under this value, the device will be muted

@end
264 changes: 264 additions & 0 deletions FaderBar/ISSoundAdditions.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
//
// ISSoundAdditions.m (ver 1.2 - 2012.10.27)
//
// Created by Massimo Moiso (2012-09) InerziaSoft
// based on an idea of Antonio Nunes, SintraWorks
//
// Permission is granted free of charge to use this code without restriction
// and without limitation, with the only condition that the copyright
// notice and this permission shall be included in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.


#import "ISSoundAdditions.h"

AudioDeviceID obtainDefaultOutputDevice();

@implementation NSSound (ISSoundAdditions)

//
// Return the ID of the default audio device; this is a C routine
//
// IN: none
// OUT: the ID of the default device or AudioObjectUnknown
//
AudioDeviceID obtainDefaultOutputDevice()
{
AudioDeviceID theAnswer = kAudioObjectUnknown;
UInt32 theSize = sizeof(AudioDeviceID);
AudioObjectPropertyAddress theAddress;

theAddress.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
theAddress.mScope = kAudioObjectPropertyScopeGlobal;
theAddress.mElement = kAudioObjectPropertyElementMaster;

//first be sure that a default device exists
if (! AudioObjectHasProperty(kAudioObjectSystemObject, &theAddress) ) {
NSLog(@"Unable to get default audio device");
return theAnswer;
}
//get the property 'default output device'
OSStatus theError = AudioObjectGetPropertyData(kAudioObjectSystemObject, &theAddress, 0, NULL, &theSize, &theAnswer);
if (theError != noErr) {
NSLog(@"Unable to get output audio device");
return theAnswer;
}
return theAnswer;
}

//
// Return the ID of the default audio device; this is a category class method
// that can be called from outside
//
// IN: none
// OUT: the ID of the default device or AudioObjectUnknown
//
+ (AudioDeviceID)defaultOutputDevice
{
return obtainDefaultOutputDevice();
}


//
// Return the system sound volume as a float in the range [0...1]
//
// IN: none
// OUT: (float) the volume of the default device
//
+ (float)systemVolume
{
AudioDeviceID defaultDevID = kAudioObjectUnknown;
UInt32 theSize = sizeof(Float32);
OSStatus theError;
Float32 theVolume = 0;
AudioObjectPropertyAddress theAddress;

defaultDevID = obtainDefaultOutputDevice();
if (defaultDevID == kAudioObjectUnknown) return 0.0; //device not found: return 0

theAddress.mSelector = kAudioHardwareServiceDeviceProperty_VirtualMasterVolume;
theAddress.mScope = kAudioDevicePropertyScopeOutput;
theAddress.mElement = kAudioObjectPropertyElementMaster;

//be sure that the default device has the volume property
if (! AudioObjectHasProperty(defaultDevID, &theAddress) ) {
NSLog(@"No volume control for device 0x%0x",defaultDevID);
return 0.0;
}

//now read the property and correct it, if outside [0...1]
theError = AudioObjectGetPropertyData(defaultDevID, &theAddress, 0, NULL, &theSize, &theVolume);
if ( theError != noErr ) {
NSLog(@"Unable to read volume for device 0x%0x", defaultDevID);
return 0.0;
}
theVolume = theVolume > 1.0 ? 1.0 : (theVolume < 0.0 ? 0.0 : theVolume);

return theVolume;
}

//
// Set the volume of the default device
//
// IN: (float)the new volume
// OUT: none
//
+ (void)setSystemVolume:(float)theVolume
{
float newValue = theVolume;
AudioObjectPropertyAddress theAddress;
AudioDeviceID defaultDevID;
OSStatus theError = noErr;
UInt32 muted;
Boolean canSetVol = YES, muteValue;
Boolean hasMute = YES, canMute = YES;

defaultDevID = obtainDefaultOutputDevice();
if (defaultDevID == kAudioObjectUnknown) { //device not found: return without trying to set
NSLog(@"Device unknown");
return;
}

//check if the new value is in the correct range - normalize it if not
newValue = theVolume > 1.0 ? 1.0 : (theVolume < 0.0 ? 0.0 : theVolume);
if (newValue != theVolume) {
NSLog(@"Tentative volume (%5.2f) was out of range; reset to %5.2f", theVolume, newValue);
}

theAddress.mElement = kAudioObjectPropertyElementMaster;
theAddress.mScope = kAudioDevicePropertyScopeOutput;

//set the selector to mute or not by checking if under threshold and check if a mute command is available
if ( (muteValue = (newValue < THRESHOLD)) )
{
theAddress.mSelector = kAudioDevicePropertyMute;
hasMute = AudioObjectHasProperty(defaultDevID, &theAddress);
if (hasMute)
{
theError = AudioObjectIsPropertySettable(defaultDevID, &theAddress, &canMute);
if (theError != noErr || !canMute)
{
canMute = NO;
NSLog(@"Should mute device 0x%0x but did not success",defaultDevID);
}
}
else canMute = NO;
}
else
{
theAddress.mSelector = kAudioHardwareServiceDeviceProperty_VirtualMasterVolume;
}

// **** now manage the volume following the what we found ****

//be sure the device has a volume command
if (! AudioObjectHasProperty(defaultDevID, &theAddress))
{
NSLog(@"The device 0x%0x does not have a volume to set", defaultDevID);
return;
}

//be sure the device can set the volume
theError = AudioObjectIsPropertySettable(defaultDevID, &theAddress, &canSetVol);
if ( theError!=noErr || !canSetVol )
{
NSLog(@"The volume of device 0x%0x cannot be set", defaultDevID);
return;
}

//if under the threshold then mute it, only if possible - done/exit
if (muteValue && hasMute && canMute)
{
muted = 1;
theError = AudioObjectSetPropertyData(defaultDevID, &theAddress, 0, NULL, sizeof(muted), &muted);
if (theError != noErr)
{
NSLog(@"The device 0x%0x was not muted",defaultDevID);
return;
}
}
else //else set it
{
theError = AudioObjectSetPropertyData(defaultDevID, &theAddress, 0, NULL, sizeof(newValue), &newValue);
if (theError != noErr)
{
NSLog(@"The device 0x%0x was unable to set volume", defaultDevID);
}
//if device is able to handle muting, maybe it was muted, so unlock it
if (hasMute && canMute)
{
theAddress.mSelector = kAudioDevicePropertyMute;
muted = 0;
theError = AudioObjectSetPropertyData(defaultDevID, &theAddress, 0, NULL, sizeof(muted), &muted);
}
}
if (theError != noErr) {
NSLog(@"Unable to set volume for device 0x%0x", defaultDevID);
}
}


//
// Increase the volume of the system device by a certain value
//
// IN: (float) amount of volume to increase
// OUT: none
//
+ (void)increaseSystemVolumeBy:(float)amount {
[self setSystemVolume:self.systemVolume+amount];
}

//
// Decrease the volume of the system device by a certain value
//
// IN: (float) amount of volume to decrease
// OUT: none
//
+ (void)decreaseSystemVolumeBy:(float)amount {
[self setSystemVolume:self.systemVolume-amount];
}

//
// IN: (Boolean) if true the device is muted, false it is unmated
// OUT: none
//
+ (void)applyMute:(Boolean)m
{
AudioDeviceID defaultDevID = kAudioObjectUnknown;
AudioObjectPropertyAddress theAddress;
Boolean hasMute, canMute = YES;
OSStatus theError = noErr;
UInt32 muted = 0;

defaultDevID = obtainDefaultOutputDevice();
if (defaultDevID == kAudioObjectUnknown) { //device not found
NSLog(@"Device unknown");
return;
}

theAddress.mElement = kAudioObjectPropertyElementMaster;
theAddress.mScope = kAudioDevicePropertyScopeOutput;
theAddress.mSelector = kAudioDevicePropertyMute;
muted = m ? 1 : 0;

hasMute = AudioObjectHasProperty(defaultDevID, &theAddress);

if (hasMute)
{
theError = AudioObjectIsPropertySettable(defaultDevID, &theAddress, &canMute);
if (theError == noErr && canMute)
{
theError = AudioObjectSetPropertyData(defaultDevID, &theAddress, 0, NULL, sizeof(muted), &muted);
if (theError != noErr) NSLog(@"Cannot change mute status of device 0x%0x", defaultDevID);
}
}
}

@end
4 changes: 2 additions & 2 deletions FaderBar/Info.plist
Original file line number Diff line number Diff line change
@@ -17,15 +17,15 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.1.1</string>
<string>1.1.2</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>LSUIElement</key>
<true/>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2016 iain. All rights reserved.</string>
<string>Copyright © 2017 iain8. All rights reserved.</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>

0 comments on commit 99f1ad2

Please sign in to comment.