The first thing I found, is that the in pa the jack-sink/source modules are "only" virtual devices. They do not replace the original sound card, they only add the jack-sink/source. The sound card that is now used by jackdbus is still fully enabled in pa, but blocked by jack. Pa clients connected to it will block and no audio is played. Once the clients are manually set to jack-sink/source, they work and pa will remember the connection
This is the second thing. Pa will reconnect to one of the rememdered sinks or sources, but you will have to do it at least once manually. Or it will use the fallback device, or something you don't expect.
What do I expect?
When the jack modules are loaded the existing clients of the sound card should be moved to the jack-sink/source and moved back when jack is stopped. New pa clients should not try to connect to the blocked audio card.
I have created a script that will do the trick. It uses the pa module module-null-sink and creates a transit device to host the existing clients while the jack modules are loaded or unloaded. The output profile of the audio card is set to off when jack is started, and set to a default when stopped. This way, new clients will not try to connect to the blocked audio card. The pa internal logic for reconnecting clients is bypassed by temporarily unloading module-switch-on-connect.
Have a look at the main functions:
Code: Select all
function on_startup() {
get_jack_card
load_transit
move_clients "sink" $jack_card_sink_id $transit_sink_id
move_clients "source" $jack_card_source_id $transit_source_id
pacmd set-card-profile $jack_card_id off
}
function after_startup() {
get_transit
get_jack_audio
move_clients "sink" $transit_sink_id $jack_audio_sink_id
move_clients "source" $transit_source_id $jack_audio_source_id
unload_transit
}
function on_shutdown() {
load_transit
get_jack_audio
move_clients "sink" $jack_audio_sink_id $transit_sink_id
move_clients "source" $jack_audio_source_id $transit_source_id
}
function after_shutdown() {
get_transit
get_jack_card
pacmd set-card-profile $jack_card_id $jack_card_profile
move_clients "sink" $transit_sink_id $jack_card_sink_id
move_clients "source" $transit_source_id $jack_card_source_id
unload_transit
}
Some variables for the sound card have to be set manually in the script, because I did not find an easy way to map the sound from QjackCTL (can be passed with %i) to the pa card.
The commands to find the values for the variables are in the comments of the script. Use them before starting jack.
The settings to be done:
Code: Select all
# Requirements:
# pulse audio modules module-jackdbus-detect and module-switch-on-connect are loaded:
# pacmd list-modules |egrep 'module-jackdbus-detect|module-switch-on-connect'
# pacmd list-sinks | egrep 'index: |card: '
jack_card_name="<alsa_card.usb-Focusrite_Scarlett_2i2_USB-00>"
# pacmd list-cards | egrep 'index: |name: |active profile: '
# '<' '>' not included
jack_card_profile="output:analog-stereo+input:analog-stereo"
# pacmd list-sinks | egrep 'index: |name: '
jack_card_sink_name="<alsa_output.usb-Focusrite_Scarlett_2i2_USB-00.analog-stereo>"
# pacmd list-sources | egrep 'index: |name: '
jack_card_source_name="<alsa_input.usb-Focusrite_Scarlett_2i2_USB-00.analog-stereo>"
# End requirements
Code: Select all
jack-pulse-switcher.sh {on-startup|after-startup|on-shutdown|after-shutdown}
If you use QjackCtl with jackdbus, and Pulseaudio with the modules module-jackdbus-detect and module-switch-on-connect, you might give it a try.