Repository navigation
Description
Hook mode (hook_set_volume, added in #181 for #126) lets sendspin drive an external amplifier, but
only in one direction. When the amplifier's volume changes somewhere else (its own remote, the TV's
remote over HDMI-CEC, a home automation system), sendspin never hears about it, so the server's slider
stays on the old value. As noted in #126, reading the volume is the other half.
HookVolumeController.start_monitoring is empty today ("Hook-based volume control does not support
external monitoring"), while the ALSA and PulseAudio controllers watch for outside changes and report
them through the same callback.
Proposal: an optional second hook, for example --hook-watch-volume <command> /
"hook_watch_volume" in the settings file, used only together with hook_set_volume:
- sendspin starts the command once, when volume monitoring starts, and reads its standard output line
by line; - each line is
<volume 0-100> <on|off>(volume, muted). sendspin passes it to the monitoring
callback, so it is reported to the server as the player's own volume, exactly like an outside ALSA
or PulseAudio change, and stores it as the logical volume (player_volume,player_muted); - lines that do not parse are logged and skipped;
- if the command exits, sendspin starts it again after a growing pause (for example 2, 5, 15, 60 s);
stop_monitoringkills it.
A long-running command was chosen over a polled "get volume" hook because the external side usually
knows when the level changes (it polls the amplifier or gets events), so there is no need to spawn a
process every second, and changes arrive without polling delay.
Why not MPRIS Volume: it is a controller command for the whole group, applied by the server as
a change from the group's average. When the player is grouped, a change made on the amplifier would
move the other players too, and the value the server sends back to the hook can differ from the one
reported, which makes the hook script fight the amplifier's own remote. A player state report changes
only this player.
Use case: a Raspberry Pi feeding an AV receiver over HDMI. The volume hook steps the receiver over
HDMI-CEC; a small service watches the receiver's level and, while the receiver is on the Pi's input,
prints each change made with the TV's remote. With the watch command, Music Assistant's slider for this
player follows the remote, and grouped players are not affected.
Implementation: about 40 lines in hook_volume.py plus the option and setting. I have been
running it as a launcher that adds the methods to HookVolumeController at start (tested with
sendspin 9.1.0 and Music Assistant: reports arrive, nothing is sent back to the volume hook, no echo).
Happy to turn it into a PR if the approach is welcome.
Activity