mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-15 04:43:53 +00:00
mixer: remove volume backwards compat, add % interpretation
The current situation is fairly confusing, where an integer is interpreted as a percent until you slap a decimal on it and magically it becomes an absolute value. Let's have a flag day in 14.0 and remove this shim entirely. Setting with percent can still be useful, so allow a trailing '%' to indicate as such. As a side effect, we tighten down the format allowed in the volume a little bit by ensuring there's no trailing garbage after the value once it's separated into left and right components. Reviewed by: christos, hselasky, pauamma_gundo.com (manpages) Relnotes: yes Differential Revision: https://reviews.freebsd.org/D35101
This commit is contained in:
parent
11bd40d04a
commit
4014365e42
|
@ -52,7 +52,7 @@ notify 0 {
|
|||
match "subsystem" "keys";
|
||||
match "type" "volume";
|
||||
match "notify" "down";
|
||||
action "mixer vol.volume=-10";
|
||||
action "mixer vol.volume=-10%";
|
||||
};
|
||||
|
||||
notify 0 {
|
||||
|
@ -60,7 +60,7 @@ notify 0 {
|
|||
match "subsystem" "keys";
|
||||
match "type" "volume";
|
||||
match "notify" "up";
|
||||
action "mixer vol.volume=+10";
|
||||
action "mixer vol.volume=+10%";
|
||||
};
|
||||
|
||||
# Eject key
|
||||
|
|
|
@ -14,14 +14,14 @@ notify 0 {
|
|||
match "system" "ACPI";
|
||||
match "subsystem" "ASUS";
|
||||
match "notify" "0x31";
|
||||
action "mixer vol.volume=-10";
|
||||
action "mixer vol.volume=-10%";
|
||||
};
|
||||
|
||||
notify 0 {
|
||||
match "system" "ACPI";
|
||||
match "subsystem" "ASUS";
|
||||
match "notify" "0x30";
|
||||
action "mixer vol.volume=+10";
|
||||
action "mixer vol.volume=+10%";
|
||||
};
|
||||
|
||||
# The next blocks enable volume hotkeys that can be found on the Asus EeePC
|
||||
|
@ -36,14 +36,14 @@ notify 0 {
|
|||
match "system" "ACPI";
|
||||
match "subsystem" "ASUS-Eee";
|
||||
match "notify" "0x14";
|
||||
action "mixer vol.volume=-10";
|
||||
action "mixer vol.volume=-10%";
|
||||
};
|
||||
|
||||
notify 0 {
|
||||
match "system" "ACPI";
|
||||
match "subsystem" "ASUS-Eee";
|
||||
match "notify" "0x15";
|
||||
action "mixer vol.volume=+10";
|
||||
action "mixer vol.volume=+10%";
|
||||
};
|
||||
|
||||
# Enable user hotkeys that can be found on the Asus EeePC
|
||||
|
|
|
@ -455,7 +455,7 @@ case ${NOTIFY} in
|
|||
fi
|
||||
if [ $LEVEL -eq 1 ]; then
|
||||
sysctl dev.acpi_ibm.0.mic_led=0
|
||||
mixer rec.volume=30
|
||||
mixer rec.volume=30%
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
|
|
|
@ -339,7 +339,7 @@ If you have sudo(8) installed and permissions to use it, type
|
|||
``<ESC>w ! sudo tee %'' to force a write.
|
||||
%
|
||||
You can adjust the volume of various parts of the sound system in your
|
||||
computer by typing 'mixer <type>.volume=<volume>'. To get a list of what
|
||||
computer by typing 'mixer <type>.volume=<volume>%'. To get a list of what
|
||||
you can adjust, just type 'mixer'.
|
||||
%
|
||||
You can automatically download and install binary packages by doing
|
||||
|
|
|
@ -139,11 +139,11 @@ The following configuration file can be used to control a pair
|
|||
of Philips USB speakers with the HID controls on the speakers.
|
||||
.Bd -literal -offset indent
|
||||
# Configuration for various Philips USB speakers
|
||||
Consumer:Volume_Increment 1 0 mixer -f $1 vol.volume=+1
|
||||
Consumer:Volume_Decrement 1 0 mixer -f $1 vol.volume=-1
|
||||
Consumer:Volume_Increment 1 0 mixer -f $1 vol.volume=+1%
|
||||
Consumer:Volume_Decrement 1 0 mixer -f $1 vol.volume=-1%
|
||||
Consumer:Mute 1 0 mixer -f $1 vol.mute=^
|
||||
Consumer:Channel_Top.Microsoft:Base_Up 1 0 mixer -f $1 bass.volume=+1
|
||||
Consumer:Channel_Top.Microsoft:Base_Down 1 0 mixer -f $1 bass.volume=-1
|
||||
Consumer:Channel_Top.Microsoft:Base_Up 1 0 mixer -f $1 bass.volume=+1%
|
||||
Consumer:Channel_Top.Microsoft:Base_Down 1 0 mixer -f $1 bass.volume=-1%
|
||||
.Ed
|
||||
.Pp
|
||||
A sample invocation using this configuration would be
|
||||
|
@ -153,9 +153,9 @@ A sample invocation using this configuration would be
|
|||
The following example controls the mixer volume using a Logitech Wingman.
|
||||
Notice the debounce of 1 for buttons and 5 for the slider.
|
||||
.Bd -literal -offset indent
|
||||
Button:Button_1 1 1 mixer vol.volume=+10
|
||||
Button:Button_2 1 1 mixer vol.volume=-10
|
||||
Generic_Desktop:Z * 5 mixer vol.volume=`echo $V | awk '{print int($$1/255*100)}'`
|
||||
Button:Button_1 1 1 mixer vol.volume=+10%
|
||||
Button:Button_2 1 1 mixer vol.volume=-10%
|
||||
Generic_Desktop:Z * 5 mixer vol.volume=`echo $V | awk '{printf("%.02f", $$1/255)}'`
|
||||
.Ed
|
||||
.Sh SEE ALSO
|
||||
.Xr usbhidctl 1 ,
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd March 20, 2022
|
||||
.Dd April 29, 2022
|
||||
.Dt MIXER 8
|
||||
.Os
|
||||
.Sh NAME
|
||||
|
@ -112,8 +112,8 @@ with one of the available devices):
|
|||
.It Sy Name Ta Sy Value
|
||||
.It Ar dev Cm .volume Ta Xo
|
||||
.Ar vol |
|
||||
.Oo Cm \&+ | Cm \&- Oc Ar lvol
|
||||
.Oo Cm \&: Oo Cm \&+ | Cm \&- Oc Ar rvol Oc
|
||||
.Oo Cm \&+ | Cm \&- Oc Ar lvol Oo % Oc
|
||||
.Oo Cm \&: Oo Cm \&+ | Cm \&- Oc Ar rvol Oo % Oc Oc
|
||||
.Xc
|
||||
.It Ar dev Cm .mute Ta Cm 0 | 1 | ^
|
||||
.It Ar dev Cm .recsrc Ta Cm ^ | + | - | =
|
||||
|
@ -128,16 +128,21 @@ The optional
|
|||
and/or
|
||||
.Ar rvol
|
||||
values have to be specified.
|
||||
The values have to be normalized 32-bit floats, from 0.0 to 1.0 inclusively.
|
||||
If no
|
||||
.Ql \&.
|
||||
character is present, the value is treated like a percentage, for backwards compatibility.
|
||||
The values should typically be decimal numbers between 0 and 1 with at most 2
|
||||
digits after the decimal point.
|
||||
A trailing percent sign indicates that the value should be treated as a
|
||||
percentage of 1.0, rather than an absolute value.
|
||||
Thus, 70% means the same as 0.7.
|
||||
If the left or right volume values are prefixed with
|
||||
.Cm +
|
||||
or
|
||||
.Cm - ,
|
||||
the value following will be used as a relative adjustment, modifying the
|
||||
current settings by the amount specified.
|
||||
Note that relative percentages are still relative to 1.0, not to the current
|
||||
value.
|
||||
If the volume is currently 0.40 and an adjustment of +20% is specified, then
|
||||
thet final volume will be set to 0.60.
|
||||
.Pp
|
||||
Volume can also be set using the shorthand
|
||||
.Ar dev Ns Cm =value .
|
||||
|
|
|
@ -341,7 +341,7 @@ mod_volume(struct mix_dev *d, void *p)
|
|||
mix_ctl_t *cp;
|
||||
mix_volume_t v;
|
||||
const char *val;
|
||||
char lstr[8], rstr[8];
|
||||
char *endp, lstr[8], rstr[8];
|
||||
float lprev, rprev, lrel, rrel;
|
||||
int n;
|
||||
|
||||
|
@ -356,25 +356,32 @@ mod_volume(struct mix_dev *d, void *p)
|
|||
lrel = rrel = 0;
|
||||
if (n > 0) {
|
||||
if (*lstr == '+' || *lstr == '-')
|
||||
lrel = rrel = 1;
|
||||
v.left = strtof(lstr, NULL);
|
||||
lrel = 1;
|
||||
v.left = strtof(lstr, &endp);
|
||||
if (*endp != '\0' && (*endp != '%' || *(endp + 1) != '\0')) {
|
||||
warnx("invalid volume value: %s", lstr);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* be backwards compatible */
|
||||
if (strstr(lstr, ".") == NULL)
|
||||
if (*endp == '%')
|
||||
v.left /= 100.0f;
|
||||
}
|
||||
if (n > 1) {
|
||||
if (*rstr == '+' || *rstr == '-')
|
||||
rrel = 1;
|
||||
v.right = strtof(rstr, NULL);
|
||||
v.right = strtof(rstr, &endp);
|
||||
if (*endp != '\0' && (*endp != '%' || *(endp + 1) != '\0')) {
|
||||
warnx("invalid volume value: %s", rstr);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* be backwards compatible */
|
||||
if (strstr(rstr, ".") == NULL)
|
||||
if (*endp == '%')
|
||||
v.right /= 100.0f;
|
||||
}
|
||||
switch (n) {
|
||||
case 1:
|
||||
v.right = v.left; /* FALLTHROUGH */
|
||||
rrel = lrel;
|
||||
case 2:
|
||||
if (lrel)
|
||||
v.left += m->dev->vol.left;
|
||||
|
|
Loading…
Reference in a new issue