easyeffects icon indicating copy to clipboard operation
easyeffects copied to clipboard

Enable applications from command line when "Process all output streams" disabled?

Open masterjg opened this issue 1 year ago • 15 comments

Quick question: How can someone setup from command line/script which applications should be enabled for processing when "Process all output streams" is disabled?

With dconf I was able to disable the processing of all output streams:

cat << EOF | dconf load /com/github/wwmm/easyeffects/
[/]
process-all-outputs=false
EOF

But not sure how to enable ONLY Spotify for EasyEffects

masterjg avatar Jan 08 '23 13:01 masterjg

What the Enable checkbox does is moving the stream to our virtual device. In the case of apps like Spotify the device is node.name = "easyeffects_sink". So you can just use a PipeWire or Pulseaudio command line utility to move the stream to easyeffects_sink.

wwmm avatar Jan 08 '23 13:01 wwmm

Is it possible to set default sink for specific client? If I understood correctly then I have to move stream when the music is already playing in spotify... Would it be possible to do without starting the playback?

nohup spotify >/dev/null 2>&1 &
until SPOTIFY_CLIENT_ID=$(pactl list short clients | grep -oP "^\d+(?=\tPipeWire\tspotify$)"); do
	sleep 1
done
EASY_EFFECTS_SINK_ID=$(pactl list short sinks | grep -oP "^\d+(?=\teasyeffects_sink)")
echo $SPOTIFY_CLIENT_ID $EASY_EFFECTS_SINK_ID ### CAN I DO SOMETHING HERE?
sudo pkill -x spotify

masterjg avatar Jan 08 '23 16:01 masterjg

Is it possible to set default sink for specific client? If I understood correctly then I have to move stream when the music is already playing in spotify... Would it be possible to do without starting the playback?

Some applications like Discord, VLC, etc have a menu where the user can specify a preferred device. So at least the app developers can do this. But I am not sure if this can be set by third party programs. Maybe the app itself has to be the one requesting a particular device.

wwmm avatar Jan 08 '23 16:01 wwmm

Would it be possible to do without starting the playback?

Like Pulseaudio PipeWire remembers the app last used device. So if you always start EasyEffects before starting the app there is a chance PipeWire will do it by itself.

wwmm avatar Jan 08 '23 16:01 wwmm

Hmm... Looks like Spotify does not have such an option... Any other ideas on how to presetup Spotify to work with easyeffects via non interactive script? There has to be someplace where pactl stores things... Maybe it would be possible to manually move the stream and then sniff where that data is stored?

masterjg avatar Jan 08 '23 20:01 masterjg

PipeWire and WirePlumber (if your system uses it as pipewire session manager) store streams and device states inside ~/.local/state/. But usually Pipewire/WirePlumber remembers the association between devices and streams on its own. It should not needed to force this through scripts.

wwmm avatar Jan 08 '23 21:01 wwmm

PipeWire and WirePlumber (if your system uses it as pipewire session manager) store streams and device states inside ~/.local/state/. But usually Pipewire/WirePlumber remembers the association between devices and streams on its own. It should not needed to force this through scripts.

Hm... In ~/.local/state I have only one file:

bash-5.2$ ls -Ral ~/.local/state
/home/marius/.local/state:
total 4
drwx------. 1 marius marius 22 Jan  8 10:57 .
drwx------. 1 marius marius 20 Jan  8 10:57 ..
drwx------. 1 marius marius 28 Jan 15 17:04 wireplumber

/home/marius/.local/state/wireplumber:
total 8
drwx------. 1 marius marius   28 Jan 15 17:04 .
drwx------. 1 marius marius   22 Jan  8 10:57 ..
-rw-r--r--. 1 marius marius 1067 Jan 15 17:04 restore-stream

When comparing the difference between contents of file when I Enable/Disable processing via EasyEffects I get single line difference only:

Output/Audio:media.role:Music:target=easyeffects_sink

However if I manually add this line and restart EasyEffects - Spotify is still not enabled...

masterjg avatar Jan 15 '23 15:01 masterjg

Update: Looks like I got it semi-working not sure what is going on, but sometimes after adding Output/Audio:media.role:Music:target=easyeffects_sink line all I have to do is restart pipewire:

systemctl --user restart pipewire pipewire-pulse

and afterwards restart of Spotify+EasyEffects.

Sometimes I also have to restart OS as EasyEffects do not start up after pipewire restart:

bash-5.2$ easyeffects
Failed to register: Timeout was reached

masterjg avatar Jan 15 '23 15:01 masterjg

Looks like the only sure way is to reboot the system.

For the future readers - just edit the file ~/.local/state/wireplumber/restore-stream and reboot the system. This should allow scripted enable of Spotify

bash-5.2$ cat ~/.local/state/wireplumber/restore-stream 
[restore-stream]
Audio/Sink:application.id:com.github.wwmm.easyeffects:channelMap=FL;FR;
Audio/Sink:application.id:com.github.wwmm.easyeffects:channelVolumes=1.0;1.0;
Audio/Sink:application.id:com.github.wwmm.easyeffects:mute=false
Audio/Sink:application.id:com.github.wwmm.easyeffects:volume=1.0
Audio/Source/Virtual:application.id:com.github.wwmm.easyeffects:channelMap=FL;FR;
Audio/Source/Virtual:application.id:com.github.wwmm.easyeffects:channelVolumes=1.0;1.0;
Audio/Source/Virtual:application.id:com.github.wwmm.easyeffects:mute=false
Audio/Source/Virtual:application.id:com.github.wwmm.easyeffects:volume=1.0
Output/Audio:media.role:Music:channelMap=FL;FR;
Output/Audio:media.role:Music:channelVolumes=1.0;1.0;
Output/Audio:media.role:Music:mute=false
Output/Audio:media.role:Music:target=easyeffects_sink
Output/Audio:media.role:Music:volume=1.0
Output/Audio:media.role:Notification:channelMap=FL;FR;
Output/Audio:media.role:Notification:channelVolumes=1.0;1.0;
Output/Audio:media.role:Notification:mute=false
Output/Audio:media.role:Notification:volume=1.0

masterjg avatar Jan 15 '23 16:01 masterjg

Reopening... looks like my solution still doesn't work... So how do I script it so that after OS install I could have enabled processing only on Spotify app? Currently only first part where I disable the processing of all outputs works, but nothing so far allows me to preselect Spotify app to be enabled in the list of EasyEffects.

image

cat << EOF | dconf load /com/github/wwmm/easyeffects/
[/]
process-all-outputs=false
EOF

cat << EOF > ~/.local/state/wireplumber/restore-stream
[restore-stream]
Audio/Sink:application.id:com.github.wwmm.easyeffects:channelMap=FL;FR;
Audio/Sink:application.id:com.github.wwmm.easyeffects:channelVolumes=1.0;1.0;
Audio/Sink:application.id:com.github.wwmm.easyeffects:mute=false
Audio/Sink:application.id:com.github.wwmm.easyeffects:volume=1.0
Audio/Sink:node.name:auto_null:channelMap=FL;FR;
Audio/Sink:node.name:auto_null:channelVolumes=1.0;1.0;
Audio/Sink:node.name:auto_null:mute=false
Audio/Sink:node.name:auto_null:volume=1.0
Audio/Source/Virtual:application.id:com.github.wwmm.easyeffects:channelMap=FL;FR;
Audio/Source/Virtual:application.id:com.github.wwmm.easyeffects:channelVolumes=1.0;1.0;
Audio/Source/Virtual:application.id:com.github.wwmm.easyeffects:mute=false
Audio/Source/Virtual:application.id:com.github.wwmm.easyeffects:volume=1.0
Output/Audio:media.role:Music:channelMap=FL;FR;
Output/Audio:media.role:Music:channelVolumes=1.0;1.0;
Output/Audio:media.role:Music:mute=false
Output/Audio:media.role:Music:target=easyeffects_sink
Output/Audio:media.role:Music:volume=1.0
Output/Audio:media.role:Notification:channelMap=FL;FR;
Output/Audio:media.role:Notification:channelVolumes=1.0;1.0;
Output/Audio:media.role:Notification:mute=false
Output/Audio:media.role:Notification:volume=1.0
EOF

masterjg avatar Jan 29 '23 20:01 masterjg

but nothing so far allows me to preselect Spotify app to be enabled in the list of EasyEffects.

The only way to add effects only to spotify is making sure it is the only stream playing to our virtual sink. As relying on PipeWire/WirePlumber device restoration does not seem to be working the only way will be writing a script that uses command line tools to move Spotify to our virtual sink. I do not think there is other way.

wwmm avatar Jan 29 '23 21:01 wwmm

Unless I am misunderstanding your use-case, this should be entirely possible using pacmd and pw-cli, for pulseaudio and pipewire respectively.

violetmage avatar Feb 27 '23 22:02 violetmage

Some issue. I can not fix my sound ...

EndrII avatar Jun 30 '23 18:06 EndrII

Some issue. I can not fix my sound

I did not understand. What is being discussed here isn't really an issue but an alternative way of doing things through the command line.

wwmm avatar Jun 30 '23 19:06 wwmm

I did not understand. What is being discussed here isn't really an issue but an alternative way of doing things through the command line.

I think this is PipeWire issue

EndrII avatar Jun 30 '23 19:06 EndrII