-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsource_sink_ctrl.sh
More file actions
executable file
·144 lines (133 loc) · 5.54 KB
/
source_sink_ctrl.sh
File metadata and controls
executable file
·144 lines (133 loc) · 5.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/sh -x
#Speaker | Headset | GoXLR
GOXLR_CHAT_PATTERN="alsa_output.usb-TC-Helicon_GoXLRMini-00.*HiFi__goxlr_chat_GoXLRMini__sink"
GOXLR_CHAT="$(pactl list short sinks | grep "$GOXLR_CHAT_PATTERN" | awk '{print $2}')"
if [ -z "$GOXLR_CHAT" ]; then
GOXLR_CHAT_PATTERN="alsa_output.usb-TC-Helicon_GoXLRMini-00.*6_7.*_sink"
GOXLR_CHAT="$(pactl list short sinks | grep "$GOXLR_CHAT_PATTERN" | awk '{print $2}')"
fi
GOXLR_MUSIC_PATTERN="alsa_output.usb-TC-Helicon_GoXLRMini-00.*HiFi__goxlr_music_GoXLRMini__sink"
GOXLR_MUSIC="$(pactl list short sinks | grep "$GOXLR_MUSIC_PATTERN" | awk '{print $2}')"
if [ -z "$GOXLR_MUSIC" ]; then
GOXLR_MUSIC_PATTERN="alsa_output.usb-TC-Helicon_GoXLRMini-00.*2_3.*_sink"
GOXLR_MUSIC="$(pactl list short sinks | grep "$GOXLR_MUSIC_PATTERN" | awk '{print $2}')"
fi
GOXLR_SYSTEM_PATTERN="alsa_output.usb-TC-Helicon_GoXLRMini-00.*HiFi__goxlr_system_GoXLRMini__sink"
GOXLR_SYSTEM="$(pactl list short sinks | grep "$GOXLR_SYSTEM_PATTERN" | awk '{print $2}')"
if [ -z "$GOXLR_SYSTEM" ]; then
GOXLR_SYSTEM_PATTERN="alsa_output.usb-TC-Helicon_GoXLRMini-00.*0_1.*_sink"
GOXLR_SYSTEM="$(pactl list short sinks | grep "$GOXLR_SYSTEM_PATTERN" | awk '{print $2}')"
fi
CONFIG_DIR="/home/$USER/.config/ssc"
target="${1? Missing HP|headset|XLR}"
mkdir -p "$CONFIG_DIR"
store_pref() {
application="$1"
sink_pref="$2"
sink_name="$(pactl list short sinks | grep ^$sink_pref | awk '{print $2}' )"
echo "$application.$sink_pref.$sink_name"
if [ "$sink_name" = "${GOXLR_CHAT}" ]; then
echo "FOUND $1 for chat"
echo "${GOXLR_CHAT}" > "${CONFIG_DIR}/$application"
elif [ "$sink_name" = "${GOXLR_MUSIC}" ]; then
echo "FOUND $1 for music"
echo "${GOXLR_MUSIC}" > "${CONFIG_DIR}/$application"
elif [ "$sink_name" = "${GOXLR_SYSTEM}" ]; then
echo "FOUND $1 for system"
echo "${GOXLR_SYSTEM}" > "${CONFIG_DIR}/$application"
else
echo "OSEF $1"
fi
}
to_headset() {
sink_pattern="alsa_output.usb-GN_Netcom_A_S_Jabra_EVOLVE_20_00014A7141DE07-00.*analog-stereo"
sink="$(pactl list short sinks | grep "$sink_pattern" | awk '{print $2}')"
sink_id="$(pactl list short sinks | grep $sink | awk '{print $1}')"
source_pattern="alsa_input.usb-GN_Netcom_A_S_Jabra_EVOLVE_20_00014A7141DE07-00.*mono-fallback"
source="$(pactl list short sources | grep $source_pattern | awk '{print $2}')"
pactl_sink_id="$(pactl -fjson list short sinks | \
jq --arg pattern "$sink_pattern" '.[] | select(.name|match($pattern))' | \
jq '.index' )"
if [ -z $pactl_sink_id ]; then
echo "'${sink}' not found"
exit 1
fi
pactl set-default-sink $sink
pactl set-default-source $source
sleep 0.1
pactl -fjson list sink-inputs | jq -c '.[]' | while read -r i; do
name="$(printf "%s" "$i" | jq -r '.["properties"]["application.name"]')"
current_sink="$(printf "%s" "$i" | jq '.["sink"]')"
current_index="$(printf "%s" "$i" | jq '.["index"]')"
echo $name $current_sink $current_index
if [ $current_sink -ne $sink_id ]; then
store_pref $name $current_sink
pactl move-sink-input $current_index $sink
fi
done
}
to_speaker() {
sink_pattern="alsa_output.usb-0b0e_Jabra_SPEAK_510_USB_501AA5DE8501020A00-00.*analog-stereo"
sink="$(pactl list short sinks | grep "$sink_pattern" | awk '{print $2}')"
sink_id="$(pactl list short sinks | grep "$sink" | awk '{print $1}')"
source_pattern="alsa_input.usb-0b0e_Jabra_SPEAK_510_USB_501AA5DE8501020A00-00.*mono-fallback"
source="$(pactl list short sources | grep $source_pattern | awk '{print $2}')"
pactl_sink_id="$(pactl -fjson list short sinks | \
jq --arg pattern "$sink_pattern" '.[] | select(.name|match($pattern))' | \
jq '.index' )"
if [ -z $pactl_sink_id ]; then
echo "'${sink}' not found"
exit 1
fi
pactl set-default-sink $sink
pactl set-default-source $source
sleep 0.1
pactl -fjson list sink-inputs | jq -c '.[]' | while read -r i; do
name="$(printf "%s" "$i" | jq -r '.["properties"]["application.name"]')"
current_sink="$(printf "%s" "$i" | jq '.["sink"]')"
current_index="$(printf "%s" "$i" | jq '.["index"]')"
echo $name $current_sink $current_index
if [ $current_sink -ne $sink_id ]; then
store_pref $name $current_sink
pactl move-sink-input $current_index $sink
fi
done
}
to_XLR() {
sink_pattern="alsa_output.usb-TC-Helicon_GoXLRMini-00.*0_1.*_sink"
sink="$(pactl list short sinks | grep "$sink_pattern" | awk '{print $2}')"
sink_id="$(pactl list short sinks | grep $sink | awk '{print $1}')"
source_pattern="alsa_input.usb-TC-Helicon_GoXLRMini-00.*0_1.*_source"
source="$(pactl list short sources | grep $source_pattern | awk '{print $2}')"
pactl_sink_id="$(pactl -fjson list short sinks | \
jq --arg pattern "$sink_pattern" '.[] | select(.name|match($pattern))' | \
jq '.index' )"
if [ -z $pactl_sink_id ]; then
echo "'${sink}' not found"
exit 1
fi
pactl set-sink-volume $GOXLR_CHAT 100%
pactl set-sink-volume $GOXLR_MUSIC 100%
pactl set-sink-volume $GOXLR_SYSTEM 100%
pactl set-default-sink $sink
pactl set-default-source $source
sleep 0.01
pactl -fjson list sink-inputs | jq -c '.[]' | while read -r i; do
name="$(printf "%s" "$i" | jq -r '.["properties"]["application.name"]')"
current_sink="$(printf "%s" "$i" | jq '.["sink"]')"
current_index="$(printf "%s" "$i" | jq '.["index"]')"
echo $name $current_sink $current_index
if [ -f "$CONFIG_DIR/$name" ]; then
if ! pactl move-sink-input $current_index "$(cat "$CONFIG_DIR/$name")"; then
rm "$CONFIG_DIR/$name"
fi
fi
done
}
if [ "$target" = HP ]; then
to_speaker
elif [ "$target" = headset ]; then
to_headset
elif [ "$target" = XLR ]; then
to_XLR
fi