-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrofi-jack-connect
executable file
·169 lines (139 loc) · 3.66 KB
/
rofi-jack-connect
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/env bash
#
########################
# rofi-jack-connect
# by Mads Kjeldgaard
#
# Connect or disconnect jack sources using the rofi menu launcher
#
# Usage:
# rofi-jack-connect --help
#
#
########################
rofi_command="rofi -theme gruvbox-dark -hide-scrollbar -i -dmenu "
# Get connections
connect_from=""
connect_to=""
connections=$(jack_lsp)
get_unique_connections(){
# sed removes the trailing numbers
# sort removes unique
unique_connections="$(jack_lsp | sed 's/_[0-9]//g'|sort -u)"
}
# One argument: "multi"
get_connections(){
get_unique_connections
# Return early if the above failed
if [ "$?" == 1 ]; then return 1; fi
# if [[ "$1" == 'multi' ]]; then
# Get connection names
connect_from="$( echo "$connections" | $rofi_command -dmenu -p 'jack_from')"
# Unique is without trailing numbers (for multiple connections)
unique_from="$(echo "$connect_from" | sed -r 's/_?[0-9]//g')"
# If no connection chosen or jack not booted, return 1
if [ -z $connect_from ]; then return 1; fi
connect_to="$( echo "$connections" | $rofi_command -dmenu -p 'jack_to')"
unique_to="$(echo "$connect_to" | sed -r 's/_?[0-9]//g')"
}
make_connection(){
# Exit if nothing is chosen
if [[ $? -ne 0 ]]; then
echo "Error: Could not retrieve connection points."
exit;
fi
if [[ "$1" == "connect" ]];
then
echo "Connecting: $connect_from <-> $connect_to"
jack_connect "$connect_from" "$connect_to"
elif [[ "$1" == "disconnect" ]];
then
echo "Disconnect: $connect_from <-/-> $connect_to"
jack_disconnect "$connect_from" "$connect_to"
else
exit
fi
}
# Connect multiple sources
make_multi_connection(){
counter=0
# -r uses regex extended for optional char
connections=$(jack_lsp| sed -r 's/_?[0-9]//g'|sort -u)
get_connections
for connection_name in $(jack_lsp | grep "$unique_from");
do
let counter+=1;
delim="_"
connect_from="$connection_name"
connect_to="$unique_to$delim$counter"
# echo "$connect_from to $connect_to"
make_connection "$1"
done
}
echo_options(){
echo "
A rofi script for making connections using the jack audio routing kit
If no arguments are supplied, it will toggle between connect and disconnect.
That is, if a connection is already made between the two nodes specified, it will break that connection and vice versa.
Optional arguments:
For single channels
--connect or -c
--disconnect or -d
For all channels in from device
--connect-all or -ca
For all channels in from device
--disconnect-all or -da
Example
rofi-jack-connect --connect # Specifically connect the two chosen connection points
rofi-jack-connect --connect-all # Same as above but with all from device's outputs
rofi-jack-connect --disconnect # Specifically disconnect the two chosen connection points
rofi-jack-connect --disconnect-all # Same as above but with all from device's outputs
rofi-jack-connect # Connect or disconnect depending on status
"
}
# Using parameters
case $1 in
# If no arguments are supplied
"-h")
echo_options
;;
"--help")
echo_options
;;
"")
get_connections
make_connection "connect"
if [[ "$?" == "1" ]]; then
echo "Client already connected. Disconnecting instead"
jack_disconnect $connect_from $connect_to;
fi
;;
"--connect")
get_connections
make_connection "connect"
;;
"-c")
get_connections
make_connection "connect"
;;
"--connect-all")
make_multi_connection "connect"
;;
"-ca")
make_multi_connection "connect"
;;
"--disconnect-all")
make_multi_connection "disconnect"
;;
"-da")
make_multi_connection "disconnect"
;;
"--disconnect")
get_connections
make_connection "disconnect"
;;
"-d")
get_connections
make_connection "disconnect"
;;
esac