Note the meaning of version numbers
[khatus.git] / x2 / src / awk / exe / parse_pactl_list_sinks.awk
1 /^Sink \#[0-9]+$/ {
2 sub("^#", "", $2)
3 sink = $2
4 next
5 }
6
7 /^\t[A-Z].+:/ {
8 section = $1
9 }
10
11 section == "Properties:" {
12 read_property()
13 }
14
15 /\tState:/ {
16 state[sink] = $2
17 next
18 }
19
20 /\tMute:/ {
21 mute[sink] = $2
22 next
23 }
24
25 # Volume: front-left: 45732 / 70% / -9.38 dB, front-right: 45732 / 70% / -9.38 dB
26 /\tVolume:/ {
27 delete vol_parts
28 delete left_parts
29 delete right_parts
30 sub("^\t+Volume: +", "")
31 split($0, vol_parts, ", +")
32 sub("^front-left: +", "", vol_parts[1])
33 sub("^front-right: +", "", vol_parts[2])
34 split(vol_parts[1], left_parts, " +/ +")
35 split(vol_parts[2], right_parts, " +/ +")
36 vol_left[sink] = left_parts[2]
37 vol_right[sink] = right_parts[2]
38 next
39 }
40
41 END {
42 for (sink in state) {
43 device = properties[sink, "alsa.device"]
44 print("state" Kfs device, state[sink])
45 print("mute" Kfs device, mute[sink])
46 print("vol_left" Kfs device, vol_left[sink])
47 print("vol_right" Kfs device, vol_right[sink])
48 }
49 }
50
51 function read_property() {
52 key = $1
53 # Yes, the sequence (x-1+1) is redundant, but it keeps the variable names
54 # true to their meaning:
55 val_begin = index($0, "\"") + 1 # +1 to exclude first quote
56 val_end = length($0) - 1 # -1 to exclude last quote
57 val_len = (val_end - val_begin) + 1 # +1 to include final character
58 val = substr($0, val_begin, val_len)
59 properties[sink, key] = val
60 }
This page took 0.050312 seconds and 4 git commands to generate.