This repository has been archived by the owner on Mar 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from donaldguy/master2main
Replace instances of [mM]aster with [mM]ain, w/ fallbacks; Fixes #42
- Loading branch information
Showing
16 changed files
with
151 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 55 additions & 25 deletions
80
...lic/AudioDevice+VirtualMasterOutput.swift → ...ublic/AudioDevice+VirtualMainOutput.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,131 @@ | ||
// | ||
// AudioDevice+VirtualMasterOutput.swift | ||
// AudioDevice+VirtualMainOutput.swift | ||
// | ||
// Created by Ruben Nine on 20/3/21. | ||
// Renamed from AudioDevice+VirtualMasterOutput.swift on 30/7/21 | ||
// | ||
|
||
import AudioToolbox | ||
import CoreAudio | ||
import Foundation | ||
|
||
// MARK: - 🔊 Virtual Master Output Volume / Balance Functions | ||
// MARK: - 🔊 Virtual Main Output Volume / Balance Functions | ||
|
||
public extension AudioDevice { | ||
/// Whether the master volume can be set for a given scope. | ||
/// Whether the main volume can be set for a given scope. | ||
/// | ||
/// - Parameter scope: A scope. | ||
/// | ||
/// - Returns: `true` when the volume can be set, `false` otherwise. | ||
func canSetVirtualMasterVolume(scope: Scope) -> Bool { | ||
guard validAddress(selector: kAudioHardwareServiceDeviceProperty_VirtualMasterVolume, | ||
func canSetVirtualMainVolume(scope: Scope) -> Bool { | ||
guard validAddress(selector: kAudioHardwareServiceDeviceProperty_VirtualMainVolume, | ||
scope: scope.asPropertyScope) != nil else { return false } | ||
|
||
return true | ||
} | ||
|
||
@available(*, deprecated, renamed: "canSetVirtualMainVolume") | ||
func canSetVirtualMasterVolume(scope: Scope) -> Bool { | ||
return canSetVirtualMainVolume(scope: scope) | ||
} | ||
|
||
/// Sets the virtual master volume for a given scope. | ||
/// Sets the virtual main volume for a given scope. | ||
/// | ||
/// - Parameter volume: The new volume as a scalar value ranging from 0 to 1. | ||
/// - Parameter scope: A scope. | ||
/// | ||
/// - Returns: `true` on success, `false` otherwise. | ||
@discardableResult func setVirtualMasterVolume(_ volume: Float32, scope: Scope) -> Bool { | ||
guard let address = validAddress(selector: kAudioHardwareServiceDeviceProperty_VirtualMasterVolume, | ||
@discardableResult func setVirtualMainVolume(_ volume: Float32, scope: Scope) -> Bool { | ||
guard let address = validAddress(selector: kAudioHardwareServiceDeviceProperty_VirtualMainVolume, | ||
scope: scope.asPropertyScope) else { return false } | ||
|
||
return setProperty(address: address, value: volume) | ||
} | ||
|
||
@available(*, deprecated, renamed: "setVirtualMainVolume") | ||
@discardableResult func setVirtualMasterVolume(_ volume: Float32, scope: Scope) -> Bool { | ||
return setVirtualMainVolume(volume, scope: scope) | ||
} | ||
|
||
/// The virtual master scalar volume for a given scope. | ||
/// The virtual main scalar volume for a given scope. | ||
/// | ||
/// - Parameter scope: A scope. | ||
/// | ||
/// - Returns: *(optional)* A `Float32` value with the scalar volume. | ||
func virtualMasterVolume(scope: Scope) -> Float32? { | ||
guard let address = validAddress(selector: kAudioHardwareServiceDeviceProperty_VirtualMasterVolume, | ||
func virtualMainVolume(scope: Scope) -> Float32? { | ||
guard let address = validAddress(selector: kAudioHardwareServiceDeviceProperty_VirtualMainVolume, | ||
scope: scope.asPropertyScope) else { return nil } | ||
|
||
return getProperty(address: address) | ||
} | ||
|
||
@available(*, deprecated, renamed: "virtualMainVolume") | ||
func virtualMasterVolume(scope: Scope) -> Float32? { | ||
return virtualMainVolume(scope: scope) | ||
} | ||
|
||
/// The virtual master volume in decibels for a given scope. | ||
/// The virtual main volume in decibels for a given scope. | ||
/// | ||
/// - Parameter scope: A scope. | ||
/// | ||
/// - Returns: *(optional)* A `Float32` value with the volume in decibels. | ||
func virtualMasterVolumeInDecibels(scope: Scope) -> Float32? { | ||
func virtualMainVolumeInDecibels(scope: Scope) -> Float32? { | ||
var referenceChannel: UInt32 | ||
|
||
if canSetVolume(channel: kAudioObjectPropertyElementMaster, scope: scope) { | ||
referenceChannel = kAudioObjectPropertyElementMaster | ||
if canSetVolume(channel: kAudioObjectPropertyElementMain, scope: scope) { | ||
referenceChannel = kAudioObjectPropertyElementMain | ||
} else { | ||
guard let channels = preferredChannelsForStereo(scope: scope) else { return nil } | ||
referenceChannel = channels.0 | ||
} | ||
|
||
guard let masterVolume = virtualMasterVolume(scope: scope) else { return nil } | ||
guard let mainVolume = virtualMainVolume(scope: scope) else { return nil } | ||
|
||
return scalarToDecibels(volume: masterVolume, channel: referenceChannel, scope: scope) | ||
return scalarToDecibels(volume: mainVolume, channel: referenceChannel, scope: scope) | ||
} | ||
|
||
@available(*, deprecated, renamed: "virtualMainVolumeInDecibels") | ||
func virtualMasterVolumeInDecibels(scope: Scope) -> Float32? { | ||
return virtualMainVolumeInDecibels(scope: scope) | ||
} | ||
|
||
/// The virtual master balance for a given scope. | ||
/// The virtual main balance for a given scope. | ||
/// | ||
/// The range is from 0 (all power to the left) to 1 (all power to the right) with the value of 0.5 signifying | ||
/// that the channels have equal power. | ||
/// | ||
/// - Parameter scope: A scope. | ||
/// | ||
/// - Returns: *(optional)* A `Float32` value with the stereo balance. | ||
func virtualMasterBalance(scope: Scope) -> Float32? { | ||
guard let address = validAddress(selector: kAudioHardwareServiceDeviceProperty_VirtualMasterBalance, | ||
func virtualMainBalance(scope: Scope) -> Float32? { | ||
guard let address = validAddress(selector: kAudioHardwareServiceDeviceProperty_VirtualMainBalance, | ||
scope: scope.asPropertyScope) else { return nil } | ||
|
||
return getProperty(address: address) | ||
} | ||
|
||
@available(*, deprecated, renamed: "virtualMainBalance") | ||
func virtualMasterBalance(scope: Scope) -> Float32? { | ||
return virtualMainBalance(scope: scope) | ||
} | ||
|
||
/// Sets the new virtual master balance for a given scope. | ||
/// Sets the new virtual main balance for a given scope. | ||
/// | ||
/// The range is from 0 (all power to the left) to 1 (all power to the right) with the value of 0.5 signifying | ||
/// that the channels have equal power. | ||
/// | ||
///setVirtualMainBalance | ||
/// - Parameter value: The new balance. | ||
/// - Parameter scope: A scope. | ||
/// | ||
/// - Returns: `true` on success, `false` otherwise. | ||
@discardableResult func setVirtualMasterBalance(_ value: Float32, scope: Scope) -> Bool { | ||
guard let address = validAddress(selector: kAudioHardwareServiceDeviceProperty_VirtualMasterBalance, | ||
@discardableResult func setVirtualMainBalance(_ value: Float32, scope: Scope) -> Bool { | ||
guard let address = validAddress(selector: kAudioHardwareServiceDeviceProperty_VirtualMainBalance, | ||
scope: scope.asPropertyScope) else { return false } | ||
|
||
return setProperty(address: address, value: value) | ||
} | ||
|
||
@available(*, deprecated, renamed: "setVirtualMainBalance") | ||
@discardableResult func setVirtualMasterBalance(_ value: Float32, scope: Scope) -> Bool { | ||
return setVirtualMainBalance(value, scope: scope) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.