diff options
author | Teddy Wing | 2022-10-25 01:10:21 +0200 |
---|---|---|
committer | Teddy Wing | 2022-10-25 01:10:21 +0200 |
commit | 9e23632b59c24a96f880f5958f28578cd45574c9 (patch) | |
tree | d07c6b5105ccb7e51a69b76a41f3ce436fd8226a | |
parent | ea561f6fb81b4a2570239763b3592d5803d7fa5c (diff) | |
download | SSVLSystemAlertVolume-9e23632b59c24a96f880f5958f28578cd45574c9.tar.bz2 |
Get and set system alert volume
Extract my research code from Mass-menu.
-rw-r--r-- | system_alert_volume.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/system_alert_volume.c b/system_alert_volume.c new file mode 100644 index 0000000..c136a7b --- /dev/null +++ b/system_alert_volume.c @@ -0,0 +1,62 @@ +#include <AudioToolbox/AudioToolbox.h> + +const AudioServicesPropertyID kAudioServicesPropertySystemAlertVolume = 'ssvl'; + +OSStatus system_volume_get(Float32 *volume) { + UInt32 volume_size = sizeof(*volume); + + OSStatus result = AudioServicesGetProperty( + kAudioServicesPropertySystemAlertVolume, + 0, + NULL, + &volume_size, + volume + ); + + // TODO: Sound PrefPane: If result != noErr, return 0.5? + + if (*volume != 0) { + *volume = log(*volume) + 1.0; + } + else { + *volume = 0; + } + + return result; +} + +OSStatus system_volume_set(Float32 volume) { + volume = exp(volume - 1.0); + + return AudioServicesSetProperty( + kAudioServicesPropertySystemAlertVolume, + 0, + NULL, + sizeof(volume), + &volume + ); +} + +int main() { + OSStatus result; + + Float32 volume; + + result = system_volume_get(&volume); + if (result != noErr) { + printf("Error getting system volume: %d\n", result); + return 1; + } + + printf("System volume: %f\n", volume); + + + Float32 new_volume = 0.5; + result = system_volume_set(new_volume); + if (result != noErr) { + printf("Error setting system volume: %d\n", result); + return 1; + } + + printf("Set volume to: %f\n", new_volume); +} |