olavfosse / eradio

The simple radio player for GNU Emacs
GNU General Public License v3.0
62 stars 6 forks source link

Raise/lower volume #9

Open bryal opened 4 years ago

bryal commented 4 years ago

It would be nice to be able to raise and lower the volume directly in Emacs, not having to open Pavucontrols or equivalent to manually change the volume of the process. Not sure if it would be easy to come up with a solution portable between all the backends though, but for MPV it can be done with the --input-ipc-server flag and ncat. Example:

$ mpv --input-ipc-server=/tmp/eradiosocket ...
$ echo 'add volume -10' | ncat -U /tmp/eradiosocket

I suppose the functions would look something like

(defun eradio-lower-volume ()
  (interactive)
  (message (shell-command-to-string "echo 'add volume -10' | ncat -U /tmp/eradiosocket")))

except they would do something different depending on the backend.

An alternative solution which would probably work for most situations could be to ask the user for volume when executing eradio-play and pass that along as a command line argument when starting the player process. For MPV, there's the --volume flag. This solution would not allow changing the volume without restarting the player, but that's not all that bothersome, so it would still be very useful.

olavfosse commented 4 years ago

Implementing this in a media player and operating system agnostic way sounds tricky. Instead we could add media player specific commands for changing the volume prefixed with the media player, starting with eradio-mpv-xyz. This obviously implies changing the mpv command to make the socket.

Alternatively we could do this on an audio system level and interface with pactl(1), SNDIOCTL(1) etc. I don't know how to go about this on MacOS though.

PRs are welcome.

Cool programming language btw, very based license :-)

bryal commented 4 years ago

I've implemented a version of this functionality in a very ad-hoc fork in my own emacs conf, but I don't know if the functionality is quite merge-ready. For example, I realized that MPV doesn't remember the volume when resuming after a stop, or changing the channel, so I added a variable eradio-volume which I change along with sending set volume commands to MPV, so when the process is restarted the previous volume is passed along with --volume. Maybe it's good enough, but the solution just feels a bit inelegant to me.

Cool programming language btw, very based license :-)

Thanks! Indeed, I feel it's the one license ;)