Skip to content

Commit

Permalink
feat(sound): move sound selection to rofi script triggered by
Browse files Browse the repository at this point in the history
Meta-[M]usic
  • Loading branch information
workflow committed Feb 26, 2024
1 parent dc40002 commit 1b60d59
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 124 deletions.
3 changes: 3 additions & 0 deletions home.nix
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ in
# Rmview (Remarkable II screensharing) config
".config/rmview.json".source = ./dotfiles/rmviewconfig.json;

# Sound Switcher
"bin/sound-switcher" = { source = ./home/scripts/sound-switcher.sh; executable = true; };

# Syncthing
".config/syncthing/config.xml" = lib.mkIf (secrets ? syncthingConfig) {
text = secrets.syncthingConfig;
Expand Down
133 changes: 9 additions & 124 deletions home/fish.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,6 @@
}:
let
functions = {
b = ''
set BOOMBOX "bluez_sink.04_21_44_B6_92_39.a2dp_sink"
echo -e 'power on\nquit' | bluetoothctl;
and sleep 2;
and echo -e 'connect 04:21:44:B6:92:39\nquit' | bluetoothctl;
and sleep 10;
and pactl set-default-sink "$BOOMBOX";
set INPUTS (pactl list sink-inputs short | cut -f 1)
for i in $INPUTS
pactl move-sink-input $i "$BOOMBOX"
end
'';

d = ''
set DOCK "alsa_output.usb-Lenovo_ThinkPad_Thunderbolt_3_Dock_USB_Audio_000000000000-00.analog-stereo"
pactl set-default-sink "$DOCK"
set INPUTS (pactl list sink-inputs short | cut -f 1)
for i in $INPUTS
pactl move-sink-input $i "$DOCK"
end
'';

fish_user_key_bindings = ''
fish_vi_key_bindings
Expand All @@ -49,113 +26,21 @@ let
bind -s -M insert \cs complete
'';

h = ''
set HEADSET "bluez_sink.14_3F_A6_28_DC_51.a2dp_sink"
echo -e 'power on\nquit' | bluetoothctl;
and sleep 2;
and echo -e 'connect 14:3F:A6:28:DC:51\nquit' | bluetoothctl;
and sleep 5;
and pactl set-default-sink "$HEADSET";
set INPUTS (pactl list sink-inputs short | cut -f 1)
for i in $INPUTS
pactl move-sink-input $i "$HEADSET"
end
'';

## Wrap LF to add ability to quit with Q in current directory
##
## Adapted for fish from https://github.com/gokcehan/lf/wiki/Tips#cd-to-current-directory-on-quit
##
lf = ''
set -x LF_CD_FILE /var/tmp/.lfcd-$fish_pid
command lf $argv
if test -s "$LF_CD_FILE"
set DIR (realpath (cat "$LF_CD_FILE"))
if test "$DIR" != "$PWD"
cd "$DIR"
end
rm "$LF_CD_FILE"
end
set -e LF_CD_FILE
'';

lo = ''
set LOCALSPEAKER1 "alsa_output.pci-0000_00_1f.3-platform-sof_sdw.HiFi___ucm0003.hw_sofsoundwire_2__sink"
set LOCALSPEAKER2 "alsa_output.pci-0000_00_1f.3-platform-sof_sdw.HiFi___ucm0005.hw_sofsoundwire_2__sink"
set LOCALSPEAKER3 "alsa_output.pci-0000_00_1f.3-platform-sof_sdw.HiFi___ucm0007.hw_sofsoundwire_2__sink"
set LOCALSPEAKER4 "alsa_output.pci-0000_00_1f.3-platform-sof_sdw.HiFi__hw_sofsoundwire_2__sink"
set LOCALSPEAKER5 "alsa_output.pci-0000_00_1f.3.analog-stereo"
set SINKS (pactl list sinks)
set LOCALMIKE1 "alsa_input.pci-0000_00_1f.3-platform-sof_sdw.HiFi___ucm0003.hw_sofsoundwire_4__source"
set LOCALMIKE2 "alsa_input.pci-0000_00_1f.3-platform-sof_sdw.HiFi___ucm0005.hw_sofsoundwire_4__source"
set LOCALMIKE3 "alsa_input.pci-0000_00_1f.3-platform-sof_sdw.HiFi___ucm0007.hw_sofsoundwire_4__source"
set LOCALMIKE4 "alsa_input.pci-0000_00_1f.3-platform-sof_sdw.HiFi__hw_sofsoundwire_4__source"
set LOCALMIKE5 "alsa_input.usb-C-Media_Electronics_Inc._USB_PnP_Audio_Device-00.mono-fallback"
set LOCALMIKE6 "alsa_input.usb-Generic_Blue_Microphones_LT_221104181411AD020101_111000-00.analog-stereo"
set SOURCES (pactl list sources)
if string match "*$LOCALSPEAKER1*" $SINKS
set LOCALSPEAKER $LOCALSPEAKER1
else if string match "*$LOCALSPEAKER2*" $SINKS
set LOCALSPEAKER $LOCALSPEAKER2
else if string match "*$LOCALSPEAKER3*" $SINKS
set LOCALSPEAKER $LOCALSPEAKER3
else if string match "*$LOCALSPEAKER4*" $SINKS
set LOCALSPEAKER $LOCALSPEAKER4
else if string match "*$LOCALSPEAKER5*" $SINKS
set LOCALSPEAKER $LOCALSPEAKER5
else
echo Local speaker not found
end
if string match "*$LOCALMIKE1*" $SOURCES
set LOCALMIKE $LOCALMIKE1
else if string match "*$LOCALMIKE2*" $SOURCES
set LOCALMIKE $LOCALMIKE2
else if string match "*$LOCALMIKE3*" $SOURCES
set LOCALMIKE $LOCALMIKE3
else if string match "*$LOCALMIKE4*" $SOURCES
set LOCALMIKE $LOCALMIKE4
else if string match "*$LOCALMIKE5*" $SOURCES
set LOCALMIKE $LOCALMIKE5
else if string match "*$LOCALMIKE6*" $SOURCES
set LOCALMIKE $LOCALMIKE6
else
echo Local mike not found
end
pactl set-default-sink $LOCALSPEAKER
set INPUTS (pactl list sink-inputs short | cut -f 1)
for i in $INPUTS
pactl move-sink-input $i $LOCALSPEAKER
end
pactl set-default-source $LOCALMIKE
set OUTPUTS (pactl list source-outputs short | cut -f 1)
for i in $OUTPUTS
pactl move-source-output $i $LOCALMIKE
end
'';

oh = ''
set OPENHEADSET "alsa_output.usb-Apple__Inc._USB-C_to_3.5mm_Headphone_Jack_Adapter_DWH84440324JKLTA7-00.analog-stereo"
set SINKS (pactl list sinks)
set OPENHEADSETMIKE "alsa_input.usb-Apple__Inc._USB-C_to_3.5mm_Headphone_Jack_Adapter_DWH84440324JKLTA7-00.mono-fallback"
set SOURCES (pactl list sources)
pactl set-default-sink $OPENHEADSET
set INPUTS (pactl list sink-inputs short | cut -f 1)
for i in $INPUTS
pactl move-sink-input $i $OPENHEADSET
end
pactl set-default-source $OPENHEADSETMIKE
set OUTPUTS (pactl list source-outputs short | cut -f 1)
for i in $OUTPUTS
pactl move-source-output $i $OPENHEADSETMIKE
set -x LF_CD_FILE /var/tmp/.lfcd-$fish_pid
command lf $argv
if test -s "$LF_CD_FILE"
set DIR (realpath (cat "$LF_CD_FILE"))
if test "$DIR" != "$PWD"
cd "$DIR"
end
rm "$LF_CD_FILE"
end
set -e LF_CD_FILE
'';

pirate = ''
Expand Down
133 changes: 133 additions & 0 deletions home/scripts/sound-switcher.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#!/usr/bin/env bash

set -euo pipefail

chosen="$(echo -e "🔌local\n\
🔊dock\n\
🎧sony\n\
📢boombox\n\
🎧openheadphones(laptop)" | rofi -dmenu -p "Zound:")"

function b {
BOOMBOX="bluez_sink.04_21_44_B6_92_39.a2dp_sink"
echo -e 'power on\nquit' | bluetoothctl
sleep 2
echo -e 'connect 04:21:44:B6:92:39\nquit' | bluetoothctl
sleep 10
pactl set-default-sink "$BOOMBOX"
INPUTS=$(pactl list sink-inputs short | cut -f 1)
for i in $INPUTS; do
pactl move-sink-input "$i" "$BOOMBOX"
done
}

function d {
DOCK="alsa_output.usb-Lenovo_ThinkPad_Thunderbolt_3_Dock_USB_Audio_000000000000-00.analog-stereo"

pactl set-default-sink "$DOCK"
INPUTS=$(pactl list sink-inputs short | cut -f 1)
for i in $INPUTS; do
pactl move-sink-input $i "$DOCK"
done
}

function l {
LOCALSPEAKER1="alsa_output.pci-0000_00_1f.3-platform-sof_sdw.HiFi___ucm0003.hw_sofsoundwire_2__sink"
LOCALSPEAKER2="alsa_output.pci-0000_00_1f.3-platform-sof_sdw.HiFi___ucm0005.hw_sofsoundwire_2__sink"
LOCALSPEAKER3="alsa_output.pci-0000_00_1f.3-platform-sof_sdw.HiFi___ucm0007.hw_sofsoundwire_2__sink"
LOCALSPEAKER4="alsa_output.pci-0000_00_1f.3-platform-sof_sdw.HiFi__hw_sofsoundwire_2__sink"
LOCALSPEAKER5="alsa_output.pci-0000_00_1f.3.analog-stereo"
SINKS=$(pactl list sinks)

LOCALMIKE1="alsa_input.pci-0000_00_1f.3-platform-sof_sdw.HiFi___ucm0003.hw_sofsoundwire_4__source"
LOCALMIKE2="alsa_input.pci-0000_00_1f.3-platform-sof_sdw.HiFi___ucm0005.hw_sofsoundwire_4__source"
LOCALMIKE3="alsa_input.pci-0000_00_1f.3-platform-sof_sdw.HiFi___ucm0007.hw_sofsoundwire_4__source"
LOCALMIKE4="alsa_input.pci-0000_00_1f.3-platform-sof_sdw.HiFi__hw_sofsoundwire_4__source"
LOCALMIKE5="alsa_input.usb-C-Media_Electronics_Inc._USB_PnP_Audio_Device-00.mono-fallback"
LOCALMIKE6="alsa_input.usb-Generic_Blue_Microphones_LT_221104181411AD020101_111000-00.analog-stereo"
SOURCES=$(pactl list sources)

if [[ $SINKS == *"$LOCALSPEAKER1"* ]]; then
LOCALSPEAKER=$LOCALSPEAKER1
elif [[ $SINKS == *"$LOCALSPEAKER2"* ]]; then
LOCALSPEAKER=$LOCALSPEAKER2
elif [[ $SINKS == *"$LOCALSPEAKER3"* ]]; then
LOCALSPEAKER=$LOCALSPEAKER3
elif [[ $SINKS == *"$LOCALSPEAKER4"* ]]; then
LOCALSPEAKER=$LOCALSPEAKER4
elif [[ $SINKS == *"$LOCALSPEAKER5"* ]]; then
LOCALSPEAKER=$LOCALSPEAKER5
else
echo "Local speaker not found"
fi

if [[ $SOURCES == *"$LOCALMIKE1"* ]]; then
LOCALMIKE=$LOCALMIKE1
elif [[ $SOURCES == *"$LOCALMIKE2"* ]]; then
LOCALMIKE=$LOCALMIKE2
elif [[ $SOURCES == *"$LOCALMIKE3"* ]]; then
LOCALMIKE=$LOCALMIKE3
elif [[ $SOURCES == *"$LOCALMIKE4"* ]]; then
LOCALMIKE=$LOCALMIKE4
elif [[ $SOURCES == *"$LOCALMIKE5"* ]]; then
LOCALMIKE=$LOCALMIKE5
elif [[ $SOURCES == *"$LOCALMIKE6"* ]]; then
LOCALMIKE=$LOCALMIKE6
else
echo "Local mike not found"
fi

pactl set-default-sink "$LOCALSPEAKER"
INPUTS=$(pactl list sink-inputs short | cut -f 1)
for i in $INPUTS; do
pactl move-sink-input "$i" "$LOCALSPEAKER"
done

pactl set-default-source "$LOCALMIKE"
OUTPUTS=$(pactl list source-outputs short | cut -f 1)
for i in $OUTPUTS; do
pactl move-source-output "$i" "$LOCALMIKE"
done
}

function s {
HEADSET="bluez_sink.14_3F_A6_28_DC_51.a2dp_sink"
echo -e 'power on\nquit' | bluetoothctl
sleep 2
echo -e 'connect 14:3F:A6:28:DC:51\nquit' | bluetoothctl
sleep 5
pactl set-default-sink "$HEADSET"
INPUTS=$(pactl list sink-inputs short | cut -f 1)
for i in $INPUTS; do
pactl move-sink-input "$i" "$HEADSET"
done
}

function o {
OPENHEADSET="alsa_output.usb-Apple__Inc._USB-C_to_3.5mm_Headphone_Jack_Adapter_DWH84440324JKLTA7-00.analog-stereo"
SINKS=$(pactl list sinks)

OPENHEADSETMIKE="alsa_input.usb-Apple__Inc._USB-C_to_3.5mm_Headphone_Jack_Adapter_DWH84440324JKLTA7-00.mono-fallback"
SOURCES=$(pactl list sources)

pactl set-default-sink $OPENHEADSET
INPUTS=$(pactl list sink-inputs short | cut -f 1)
for i in $INPUTS; do
pactl move-sink-input "$i" $OPENHEADSET
done

pactl set-default-source $OPENHEADSETMIKE
OUTPUTS=$(pactl list source-outputs short | cut -f 1)
for i in $OUTPUTS; do
pactl move-source-output "$i" $OPENHEADSETMIKE
done
}

case "$chosen" in
🔌local) l ;;
🔊dock) d ;;
🎧sony) s ;;
📢boombox) b ;;
"🎧openheadphones(laptop)") o ;;
*) exit 1 ;;
esac
3 changes: 3 additions & 0 deletions home/xsession/i3.nix
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ in
# If there are multiple scratchpad windows, this command cycles through them.
"${mod}+minus" = "scratchpad show";

# Sound Switcher
"${mod}+m" = "exec --no-startup-id sound-switcher";

# Multimedia Key Controls from https://faq.i3wm.org/question/3747/enabling-multimedia-keys/?answer=3759#post-id-3759
# Pulse Audio controls
"XF86AudioRaiseVolume" = "exec --no-startup-id pactl set-sink-volume @DEFAULT_SINK@ +5%"; #increase sound volume
Expand Down

0 comments on commit 1b60d59

Please sign in to comment.