From 8040281d8052ffd8d19fad58f6af4f776ded4324 Mon Sep 17 00:00:00 2001 From: Humdinger Date: Sun, 1 Jan 2023 10:11:10 +0100 Subject: [PATCH] setvolume: detailed usage info, print mute state * Describe parameters in "usage". * Change -m to explicitely mute, instead of toggling mute. * Add -t to toggle muting, -u to unmute. * Add long version options: --mute, --unmute, --togglemute --increase, --decrease * Accept a step size as additional parameter to in/decrease, without it, the step size is 3 dB. * Print muting state when toggling or un/muting. * Update shortcut_settings to use "setvolume -t" to toggle muting. Change-Id: Iacad5bcf4a40a6056c85161ac45379015392420c Reviewed-on: https://review.haiku-os.org/c/haiku/+/5976 Tested-by: Commit checker robot Reviewed-by: Adrien Destugues Reviewed-by: nephele --- data/settings/shortcuts_settings | Bin 4555 -> 4555 bytes src/bin/setvolume.cpp | 39 +++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/data/settings/shortcuts_settings b/data/settings/shortcuts_settings index e0ee2199c66aaed11202d864a744d8e10750ccf6..ceede3580a0d6b2d0c904c3ede8527f43e1d1b32 100644 GIT binary patch delta 25 hcmX@Dd|G)!JtJeu<_5;KEQ}=^6XY2;`?A+@0RVj12%G=_ delta 25 hcmX@Dd|G)!JtJf8<_5;KER4Au6XY2;`?A+@0RVg(2#x>% diff --git a/src/bin/setvolume.cpp b/src/bin/setvolume.cpp index 30271f0511..1a9d7c1b41 100644 --- a/src/bin/setvolume.cpp +++ b/src/bin/setvolume.cpp @@ -71,27 +71,53 @@ main(int argc, char **argv) float volume = 0.0; if (argc > 1) { - if (strcmp(argv[1], "-m") == 0) { + if (strcmp(argv[1], "-m") == 0 || strcmp(argv[1], "--mute") == 0) { + int32 muted = 1; + mute->SetValue(&muted, sizeof(int32), system_time()); + printf("Muted\n"); + return 0; + } else if (strcmp(argv[1], "-u") == 0 || strcmp(argv[1], "--unmute") == 0) { + int32 muted = 0; + mute->SetValue(&muted, sizeof(int32), system_time()); + printf("Unmuted\n"); + return 0; + } else if (strcmp(argv[1], "-t") == 0 || strcmp(argv[1], "--togglemute") == 0) { int32 muted = 0; bigtime_t lastChange = 0; size_t size = sizeof(int32); mute->GetValue(&muted, &size, &lastChange); muted = 1 - muted; mute->SetValue(&muted, sizeof(int32), system_time()); + printf("%s\n", muted ? "Muted" : "Unmuted"); + return 0; } else { - if (strcmp(argv[1], "-i") == 0 || strcmp(argv[1], "-d") == 0) { + if (strcmp(argv[1], "-i") == 0 || strcmp(argv[1], "-d") == 0 + || strcmp(argv[1], "--increase") == 0 || strcmp(argv[1], "--decrease") == 0) { bigtime_t when; size_t size = sizeof(volume); gain->GetValue(&volume, &size, &when); - if (strcmp(argv[1], "-i") == 0) - volume += 3; + size_t step = 3; + if (argc > 2) + step = atoi(argv[2]); + if (strcmp(argv[1], "-i") == 0 || strcmp(argv[1], "--increase") == 0) + volume += step; else - volume -= 3; + volume -= step; } else { char *end; volume = strtod(argv[1], &end); if (end == argv[1]) { - fprintf(stderr, "usage: %s [ | -i | -d | -m ]\n", sProgramName); + fprintf(stderr, + "Usage: %s | [options]\n" + "Sets the system volume to the specified value in dB.\n" + "Alternatively there are these options:\n" + " -m --mute\n" + " -u --unmute\n" + " -t --togglemute\ttoggles muting\n" + " -i --increase x\tincreases volume by x dB\n" + " -d --decrease x\tdecreases volume by x dB\n" + "\t\t\tx defaults to 3 if not supplied\n" , + sProgramName); exit(1); } } @@ -105,7 +131,6 @@ main(int argc, char **argv) gain->SetValue(&volume, sizeof(volume), system_time()); } } - bigtime_t when; size_t size = sizeof(volume); gain->GetValue(&volume, &size, &when);