nicklan / pnmixer

Volume mixer for the system tray
GNU General Public License v3.0
152 stars 32 forks source link

Reload Sound from command line/script #179

Open py5 opened 6 years ago

py5 commented 6 years ago

Hi, pnmixer is great, but it'd be even better if it were possible reload sound from scripts and terminal commands. Many Openbox/Tint2 users use scripts to control it's features, including audio. I, for example, use scripts to switch between headphones (HDMI) and speakers (internal audio), and have to kill and restart PNMixer every time I do that.

hasufell commented 6 years ago

I, for example, use scripts to switch between headphones (HDMI) and speakers (internal audio)

What does that even mean? Switch what?

stratosjack commented 6 years ago

I'm using pactl set-card-profile to switch between two card profiles, pci-builtin and usb-headphones. Every time I call this script, pnmixer's volume up/volume down functionality stops working for the new card. This persists, waiting for 10 secs doesn't help. I need to press on "Reload Sound" to fix it. Although behaves properly when I switch back to the old card.

py5 commented 6 years ago

@hasufell , I mean this, via shell script or command line...

# Set output to HDMI (headphones)
pacmd set-card-profile 0 output:hdmi-stereo+input:analog-stereo

# Set output to Analog (speakers)
pacmd set-card-profile 0 output:analog-stereo+input:analog-stereo

When I switch between those two card profiles, pnmixer doesn't detects the change, and I need reload it manually, or via script with...

killall pnmixer && pnmixer

If there was an option to reload it, for example a "--reload" parameter, or if the change of the audio output was auto-detected, it would be great!

stratosjack commented 6 years ago

^ Your code above seems more than enough for me! This is a PulseAudio compatibility problem, you should probably tag it with "pulseaudio"...

py5 commented 6 years ago

@stratosjack , the point is that I know that pulseudio support "needs to be implemented from scratch and will likely not happen", and the "Reload Sound" menu entry functionality is already implemented and works. That's why I'd just like to have this as an option from CL/script instead of clicking.

hasufell commented 6 years ago

If there was an option to reload it, for example a "--reload" parameter

I don't really know what that means. You want to spawn a second pnmixer instance? Otherwise you are asking for a non-trivial dbus interface.

That's why I'd just like to have this as an option from CL/script instead of clicking.

This is too vague to be implementable. How would it work?

stratosjack commented 6 years ago

@hasufell Forgive my ignorance, I'm not good at C++ or Kernel coding, but my opinion is that audio_should_reload() on soundcard change. But then again, this is a pa event, didn't say it is trivial. I don't think its a feature here, rather more like a pa bug.

hasufell commented 6 years ago

Well, as stated above, there are only two possibilities:

  1. introduce real PulseAudio support (which will indeed require a complete rewrite. I've attempted that feature once and it simply doesn't work with the current architecture)
  2. make this a single-instance app with dbus support to send arbitrary commands to the running app (also non-trivial)

Maybe we could also hijack unix signaly, but they are asynchronous too and need some odd hacks to make work with gtk+ via pipes or something, see http://askra.de/software/gtk-signals/x2992.html if you want to give that a shot. Then you could do something like kill -SIGUSR1 <pnmixer-pid>.