Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Add convenience method canSetVirtualMainBalance #60

Merged
merged 1 commit into from
Feb 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Sources/SimplyCoreAudio/Public/AudioDevice+VirtualMainOutput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ public extension AudioDevice {
return virtualMainVolumeInDecibels(scope: scope)
}

/// Whether the main balance can be set for a given scope.
///
/// - Parameter scope: A scope.
///
/// - Returns: `true` when the balance can be set, `false` otherwise.
func canSetVirtualMainBalance(scope: Scope) -> Bool {
guard validAddress(selector: kAudioHardwareServiceDeviceProperty_VirtualMainBalance,
scope: scope.asPropertyScope) != nil else { return false }

return true
}

/// 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
Expand Down
3 changes: 3 additions & 0 deletions Tests/SimplyCoreAudioTests/AudioDeviceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ final class AudioDeviceTests: SCATestCase {
func testVirtualMainBalance() throws {
let device = try getNullDevice()

XCTAssertTrue(device.canSetVirtualMainBalance(scope: .output))
XCTAssertTrue(device.canSetVirtualMainBalance(scope: .input))

XCTAssertFalse(device.setVirtualMainBalance(0.0, scope: .output))
XCTAssertNil(device.virtualMainBalance(scope: .output))

Expand Down