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 <no-reply+buildbot@haiku-os.org>
Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>
Reviewed-by: nephele <nep@packageloss.eu>
This commit is contained in:
Humdinger 2023-01-01 10:11:10 +01:00 committed by humdinger
parent f6c51a5dc4
commit 8040281d80
2 changed files with 32 additions and 7 deletions

Binary file not shown.

View File

@ -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 [<volume> | -i | -d | -m ]\n", sProgramName);
fprintf(stderr,
"Usage: %s <volume> | [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);