Skip to content

Commit

Permalink
feat(sound-switcher): no longer a need to manually move inputs/outputs
Browse files Browse the repository at this point in the history
with Pipewire it seems
  • Loading branch information
workflow committed Nov 11, 2024
1 parent 9f2a200 commit d7887c6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 42 deletions.
30 changes: 10 additions & 20 deletions home/scripts/scripts/sound-switcher-boar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ oh() {
local sink="alsa_output.pci-0000_51_00.1.hdmi-stereo.2"
local card_profile="output:hdmi-stereo"

set_default_sink_and_move_inputs "$card_name_pattern" "$sink" "$card_profile"
set_default_sink "$card_name_pattern" "$sink" "$card_profile"

localmike
}
Expand All @@ -23,7 +23,7 @@ creative() {
local sink="alsa_output.pci-0000_51_00.1.hdmi-stereo-extra1"
local card_profile="output:hdmi-stereo-extra1"

set_default_sink_and_move_inputs "$card_name_pattern" "$sink" "$card_profile"
set_default_sink "$card_name_pattern" "$sink" "$card_profile"

localmike
}
Expand All @@ -39,7 +39,7 @@ boombox() {
connect_bluetooth "$bd_address"
fi

set_default_sink_and_move_inputs "$card_name_pattern" "$sink" "$card_profile"
set_default_sink "$card_name_pattern" "$sink" "$card_profile"

localmike
}
Expand All @@ -49,7 +49,7 @@ budslisten() {
local sink="bluez_output.DC_69_E2_9A_6E_30.1"
local card_profile="a2dp-sink-sbc"

set_default_sink_and_move_inputs "$card_name_pattern" "$sink" "$card_profile"
set_default_sink "$card_name_pattern" "$sink" "$card_profile"

localmike
}
Expand All @@ -59,7 +59,7 @@ budstalk() {
local sink="bluez_output.DC_69_E2_9A_6E_30.1"
local card_profile="headset-head-unit-msbc"

set_default_sink_and_move_inputs "$card_name_pattern" "$sink" "$card_profile"
set_default_sink "$card_name_pattern" "$sink" "$card_profile"

budsmike
}
Expand All @@ -76,7 +76,7 @@ sony() {
connect_bluetooth "$bd_address"
fi

set_default_sink_and_move_inputs "$card_name_pattern" "$sink" "$card_profile"
set_default_sink "$card_name_pattern" "$sink" "$card_profile"

localmike
}
Expand All @@ -86,23 +86,23 @@ localmike() {
local source="alsa_input.usb-Generic_Blue_Microphones_LT_221104181411AD020101_111000-00.analog-stereo"
local card_profile="input:analog-stereo"

set_default_source_and_move_outputs "$card_name_pattern" "$source" "$card_profile"
set_default_source "$card_name_pattern" "$source" "$card_profile"
}

budsmike() {
local card_name_pattern="DC_69"
local source="bluez_input.DC:69:E2:9A:6E:30"
local card_profile="headset-head-unit-msbc"

set_default_source_and_move_outputs "$card_name_pattern" "$source" "$card_profile"
set_default_source "$card_name_pattern" "$source" "$card_profile"
}

get_card_id() {
local card_name_pattern="$1"
nu -c "pactl list cards short | lines | parse \"{id}\t{name}\t{_}\" | where \$it.name =~ \"$card_name_pattern\" | get id | get 0" || true
}

set_default_sink_and_move_inputs() {
set_default_sink() {
local card_name_pattern="$1"
local sink="$2"
local card_profile="$3"
Expand All @@ -112,14 +112,9 @@ set_default_sink_and_move_inputs() {

pactl set-card-profile "$card_id" "$card_profile"
pactl set-default-sink "$sink"
local inputs
inputs=$(pactl list sink-inputs short | cut -f 1)
for i in $inputs; do
pactl move-sink-input "$i" "$sink"
done
}

set_default_source_and_move_outputs() {
set_default_source() {
local card_name_pattern="$1"
local source="$2"
local card_profile="$3"
Expand All @@ -129,11 +124,6 @@ set_default_source_and_move_outputs() {

pactl set-card-profile "$card_id" "$card_profile"
pactl set-default-source "$source"
local outputs
outputs=$(pactl list source-outputs short | cut -f 1)
for i in $outputs; do
pactl move-source-output "$i" "$source"
done
}

connect_bluetooth() {
Expand Down
34 changes: 12 additions & 22 deletions home/scripts/scripts/sound-switcher-flexbox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ localspeaker() {
return 1
fi

set_default_sink_and_move_inputs "$card_name_pattern" "$selected_sink" "$card_profile"
set_default_sink "$card_name_pattern" "$selected_sink" "$card_profile"

localmike
}
Expand All @@ -46,7 +46,7 @@ ohlocalmic() {
local sink="alsa_output.usb-Apple__Inc._USB-C_to_3.5mm_Headphone_Jack_Adapter_DWH84440324JKLTA7-00.analog-stereo"
local card_profile="?"

set_default_sink_and_move_inputs "$card_name_pattern" "$sink" "$card_profile"
set_default_sink "$card_name_pattern" "$sink" "$card_profile"

localmike
}
Expand All @@ -56,7 +56,7 @@ ohohmic() {
local sink="alsa_output.usb-Apple__Inc._USB-C_to_3.5mm_Headphone_Jack_Adapter_DWH84440324JKLTA7-00.analog-stereo"
local card_profile="?"

set_default_sink_and_move_inputs "$card_name_pattern" "$sink" "$card_profile"
set_default_sink "$card_name_pattern" "$sink" "$card_profile"

ohmike
}
Expand All @@ -72,7 +72,7 @@ boombox() {
connect_bluetooth "$bd_address"
fi

set_default_sink_and_move_inputs "$card_name_pattern" "$sink" "$card_profile"
set_default_sink "$card_name_pattern" "$sink" "$card_profile"

localmike
}
Expand All @@ -82,7 +82,7 @@ budslisten() {
local sink="bluez_output.DC_69_E2_9A_6E_30.1"
local card_profile="a2dp-sink-sbc"

set_default_sink_and_move_inputs "$card_name_pattern" "$sink" "$card_profile"
set_default_sink "$card_name_pattern" "$sink" "$card_profile"

localmike
}
Expand All @@ -92,7 +92,7 @@ budstalk() {
local sink="bluez_output.DC_69_E2_9A_6E_30.1"
local card_profile="headset-head-unit-msbc"

set_default_sink_and_move_inputs "$card_name_pattern" "$sink" "$card_profile"
set_default_sink "$card_name_pattern" "$sink" "$card_profile"

budsmike
}
Expand All @@ -109,7 +109,7 @@ sony() {
connect_bluetooth "$bd_address"
fi

set_default_sink_and_move_inputs "$card_name_pattern" "$sink" "$card_profile"
set_default_sink "$card_name_pattern" "$sink" "$card_profile"

localmike
}
Expand Down Expand Up @@ -140,31 +140,31 @@ localmike() {
return 1
fi

set_default_source_and_move_outputs "$card_name_pattern" "$selected_source" "$card_profile"
set_default_source "$card_name_pattern" "$selected_source" "$card_profile"
}

ohmike() {
local card_name_pattern="Apple"
local source="alsa_input.usb-Apple__Inc._USB-C_to_3.5mm_Headphone_Jack_Adapter_DWH84440324JKLTA7-00.mono-fallback"
local card_profile="?"

set_default_source_and_move_outputs "$card_name_pattern" "$source" "$card_profile"
set_default_source "$card_name_pattern" "$source" "$card_profile"
}

budsmike() {
local card_name_pattern="DC_69"
local source="bluez_input.DC:69:E2:9A:6E:30"
local card_profile="headset-head-unit-msbc"

set_default_source_and_move_outputs "$card_name_pattern" "$source" "$card_profile"
set_default_source "$card_name_pattern" "$source" "$card_profile"
}

get_card_id() {
local card_name_pattern="$1"
nu -c "pactl list cards short | lines | parse \"{id}\t{name}\t{_}\" | where \$it.name =~ \"$card_name_pattern\" | get id | get 0" || true
}

set_default_sink_and_move_inputs() {
set_default_sink() {
local card_name_pattern="$1"
local sink="$2"
local card_profile="$3"
Expand All @@ -174,14 +174,9 @@ set_default_sink_and_move_inputs() {

pactl set-card-profile "$card_id" "$card_profile"
pactl set-default-sink "$sink"
local inputs
inputs=$(pactl list sink-inputs short | cut -f 1)
for i in $inputs; do
pactl move-sink-input "$i" "$sink"
done
}

set_default_source_and_move_outputs() {
set_default_source() {
local card_name_pattern="$1"
local source="$2"
local card_profile="$3"
Expand All @@ -191,11 +186,6 @@ set_default_source_and_move_outputs() {

pactl set-card-profile "$card_id" "$card_profile"
pactl set-default-source "$source"
local outputs
outputs=$(pactl list source-outputs short | cut -f 1)
for i in $outputs; do
pactl move-source-output "$i" "$source"
done
}

connect_bluetooth() {
Expand Down

0 comments on commit d7887c6

Please sign in to comment.