This repository has been archived by the owner on Dec 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzmixer
144 lines (141 loc) · 3.77 KB
/
zmixer
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
#!/usr/bin/env zsh
zmodload zsh/curses
zmix()
{
local mixer
local -a zmix_dev
integer y
integer posy
integer length
#get list of devices
zmix.draw()
{
zcurses addwin main $(( $LINES - 2 )) $(( $COLUMNS - 2 )) 1 1
title="zmixer"
zcurses move main 1 $(( ($COLUMNS - 2 - $#title) / 2 ))
zcurses string main $title
y=4
for dev ($zmix_dev);do
y+=1
zcurses move main $y 5
zcurses string main $dev
zcurses move main $y 15
zcurses string main ":"
# Set the recording device
if [[ "x$dev" = "x$record" ]]; then
zcurses addwin record 1 1 $(( y + 1 )) 4 main
zcurses attr record red/black bold
zcurses string record "*"
fi
level=${${(f)"$(/usr/sbin/mixer -s $dev)"}[(w)2]}
numlevel=${${(s#:#)level}[1]}
zcurses move main $(( y )) 17
line="|"
zcurses string main "[${(r:$length::-:)${(l:$(( numlevel / 2))::=:)line}}] ($level)"
done
if (( posy == 0 ));then
posy=5
fi
zmix.sel $posy
zcurses refresh main
}
zmix.listen()
{
while true;do
if [[ -z $key ]];then
zcurses input main REPLY key
fi
newkey=$key
key=
case $REPLY in
(k) newkey=UP;;
(j) newkey=DOWN;;
(h) newkey=LEFT;;
(l) newkey=RIGHT;;
esac
case $newkey in
(UP)
if (( posy <= 5 )); then
zmix.sel $y
else
zmix.sel $(( posy - 1 ))
fi
;;
(DOWN)
if (( posy >= y )); then
zmix.sel 5
else
zmix.sel $(( posy + 1 ))
fi
;;
(LEFT)
dev=$zmix_dev[$(( posy - 4 ))]
mixer $dev -1 2>&1 >/dev/null
zmix.redraw $dev
;;
(RIGHT)
dev=$zmix_dev[$(( posy - 4 ))]
mixer $dev +1 2>&1 >/dev/null
zmix.redraw $dev
;;
("")
if [[ -z $REPLY ]];then
zcurses delwin main
zcurses clear stdscr redraw
zcurses refresh stdscr
zmix.draw
else
break
fi
;;
esac
done
}
zmix.sel()
{
zcurses move main $posy 0
zcurses string main " "
posy=$1
zcurses move main $posy 0
zcurses string main "->"
zcurses refresh main
}
zmix.redraw()
{
dev=$1
level=${${(f)"$(/usr/sbin/mixer -s $dev)"}[(w)2]}
numlevel=${${(s#:#)level}[1]}
zcurses move main $posy 16
zcurses clear main eol
level=${${(f)"$(/usr/sbin/mixer -s $dev)"}[(w)2]}
numlevel=${${(s#:#)level}[1]}
zcurses move main $posy 17
line="|"
zcurses string main "[${(r:$length::-:)${(l:$(( numlevel / 2))::=:)line}}] ($level)"
zcurses move main $posy 2
zcurses refresh main
}
#Constructor
{
length=50
mixer=(${=${(f)"$(/usr/sbin/mixer -S)"}})
for line ($mixer);do
[[ -n ${line:#*:*:*} ]] && continue
zmix_dev+=${${(s#:#)line}[1]}
done
record=$mixer[$#mixer]
zcurses init
zmix.draw
zmix.listen
} always
{
#cleanup all windows
for win ($zcurses_windows);do
[[ -z ${win:#(main|stdscr)} ]] && continue
zcurses delwin $win
done
zcurses delwin main
zcurses end
}
}
zmix