-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
3.1.2 fixes some stupid error with pre 10.15 prefs
- Loading branch information
Showing
26 changed files
with
840 additions
and
177 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
17 changes: 17 additions & 0 deletions
17
Aerial/Source/Models/Hardware/ISSoundAdditions/Sound.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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// SoundOutputManager.swift | ||
// | ||
// | ||
// Created by Alessio Moiso on 08.03.22. | ||
// | ||
|
||
/// Entry point to access and modify the system sound settings, such | ||
/// muting/unmuting and changing the volume. | ||
/// | ||
/// # Overview | ||
/// This class cannot be instantiated, but you can interact with its `output` property directly. | ||
/// You can use the shared instance to change the output volume as well as | ||
/// mute and unmute. | ||
public enum Sound { | ||
static let output = SoundOutputManager() | ||
} |
50 changes: 50 additions & 0 deletions
50
Aerial/Source/Models/Hardware/ISSoundAdditions/SoundOutputManager+Goodies.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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Alessio Moiso on 09.03.22. | ||
// | ||
|
||
public extension Sound.SoundOutputManager { | ||
/// Increase the volume of the default output device | ||
/// by the given amount. | ||
/// | ||
/// Errors will be ignored. | ||
/// | ||
/// The values range between 0 and 1. If the increase results | ||
/// in a value outside of the bounds, it will be normalized to the closest | ||
/// value in the bounds. | ||
func increaseVolume(by value: Float, autoMuteUnmute: Bool = false, muteThreshold: Float = 0.005) { | ||
setVolume(volume+value, autoMuteUnmute: autoMuteUnmute, muteThreshold: muteThreshold) | ||
} | ||
|
||
/// Decrease the volume of the default output device | ||
/// by the given amount. | ||
/// | ||
/// Errors will be ignored. | ||
/// | ||
/// The values range between 0 and 1. If the decrease results | ||
/// in a value outside of the bounds, it will be normalized to the closest | ||
/// value in the bounds. | ||
func decreaseVolume(by value: Float, autoMuteUnmute: Bool = false, muteThreshold: Float = 0.005) { | ||
setVolume(volume-value, autoMuteUnmute: autoMuteUnmute, muteThreshold: muteThreshold) | ||
} | ||
|
||
/// Set the volume of the default output device and, | ||
/// if lower or higher then `muteThreshold` also toggles the mute property. | ||
/// | ||
/// - warning: This function will unmute a muted device, if the volume is greater | ||
/// then `muteThreshold`. Please, make sure that the user is aware of this and always | ||
/// respect the Do Not Disturb modes and other system settings. | ||
/// | ||
/// - parameters: | ||
/// - newValue: The volume. | ||
/// - autoMuteUnmute: If `true`, will use the `muteThreshold` to determine whether the device | ||
/// should also be muted or unmuted. | ||
/// - muteThreshold: Defines the threshold that should cause an automatic mute for all values below it. | ||
func setVolume(_ newValue: Float, autoMuteUnmute: Bool, muteThreshold: Float = 0.005) { | ||
volume = newValue | ||
guard autoMuteUnmute else { return } | ||
isMuted = newValue <= muteThreshold | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
Aerial/Source/Models/Hardware/ISSoundAdditions/SoundOutputManager+Properties.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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// SoundOutputManager+Properties.swift | ||
// | ||
// | ||
// Created by Alessio Moiso on 09.03.22. | ||
// | ||
import CoreAudio | ||
|
||
public extension Sound.SoundOutputManager { | ||
/// Get the system default output device. | ||
/// | ||
/// You can use this value to interact with the device directly via | ||
/// other system calls. | ||
/// | ||
/// This value will return `nil` if there is currently no device selected in | ||
/// System Preferences > Sound > Output. | ||
var defaultOutputDevice: AudioDeviceID? { | ||
try? retrieveDefaultOutputDevice() | ||
} | ||
|
||
/// Get or set the volume of the default output device. | ||
/// | ||
/// Errors will be ignored. If you need to handle errors, | ||
/// use `readVolume` and `setVolume`. | ||
/// | ||
/// The values range between 0 and 1. | ||
var volume: Float { | ||
get { | ||
(try? readVolume()) ?? 0 | ||
} | ||
set { | ||
do { | ||
try setVolume(newValue) | ||
} catch { } | ||
} | ||
} | ||
|
||
/// Get or set whether the system default output device is muted or not. | ||
/// | ||
/// Errors will be ignored. If you need to handle errors, | ||
/// use `readMute` and `mute`. Devices that do not support muting | ||
/// will always return `false`. | ||
var isMuted: Bool { | ||
get { | ||
(try? readMute()) ?? false | ||
} | ||
set { | ||
do { | ||
try mute(newValue) | ||
} catch { } | ||
} | ||
} | ||
} |
Oops, something went wrong.