aboutsummaryrefslogtreecommitdiffstats
path: root/SSVLSystemAlertVolume.c
diff options
context:
space:
mode:
authorTeddy Wing2022-10-25 01:33:03 +0200
committerTeddy Wing2022-10-25 01:33:03 +0200
commit72f2271a0a02b857e4654bd742dcedbfdd1a2d10 (patch)
tree1eaa97afd32035f14b77a41561d536332bb51fd1 /SSVLSystemAlertVolume.c
parentcdf455726b34de60604f3ad7f94ca255b50e358d (diff)
downloadSSVLSystemAlertVolume-72f2271a0a02b857e4654bd742dcedbfdd1a2d10.tar.bz2
Rename "system_alert_volume.c" to "SSVLSystemAlertVolume.c"
Align with the new identifier naming.
Diffstat (limited to 'SSVLSystemAlertVolume.c')
-rw-r--r--SSVLSystemAlertVolume.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/SSVLSystemAlertVolume.c b/SSVLSystemAlertVolume.c
new file mode 100644
index 0000000..a795568
--- /dev/null
+++ b/SSVLSystemAlertVolume.c
@@ -0,0 +1,62 @@
+#include <AudioToolbox/AudioToolbox.h>
+
+const AudioServicesPropertyID SSVLAudioServicesPropertySystemAlertVolume = 'ssvl';
+
+OSStatus SSVLGetSystemVolume(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 SSVLSetSystemVolume(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);
+}