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
|
#!/bin/bash
# Ear tuner for guitar and bass. Install tunebass on your $PATH, and
# symlink it to tunegtr.
# this used to be a one-liner:
#play -n synth 2 pluck ${1:-A2} repeat 99999
case "$0" in
*gtr*|*guit*)
notes="E4 B3 G3 D3 A2 E2"
note=6
lastnote=6
;;
*)
notes="G2 D2 A1 E1"
note=4
lastnote=4
;;
esac
prompt="Space: next string, BkSpc: prev string, 1-$lastnote: strings, q: quit, ?: help"
# these seem like they ought to be the arrow keys, but they're actually
# \n and \b... kcud1 and kcub1 are the 'application mode' versions, which
# doesn't do us any good here.
#down="$( tput cud1 )"
#left="$( tput cub1 )"
# these are correct for xterm and derivatives, and for the linux console.
down="$( printf "\x1b\x5bB" )"
left="$( printf "\x1b\x5bD" )"
up="$( tput cuu1 )"
right="$( tput cuf1 )"
pageup="$( tput kpp )"
pagedown="$( tput knp )"
esc="$( printf "\x1b" )"
enter='
'
oldnote=
pid=
echo "$prompt"
while true; do
narg="$( echo $notes | cut -d' ' -f $note )"
if [ "$oldnote" != "$note" ]; then
[ "$pid" != "" ] && kill "$pid"
echo -e -n "\rString: $note Note: $narg"
tput el
play --buffer 1024 -qn synth 2 pluck $narg repeat - &>/dev/null &
pid="$!"
oldnote="$note"
fi
key=
read -rs -N5 -t 0.1 key
if [ "$key" != "" ]; then
case "$key" in
[1-9])
[ "$key" -le "$lastnote" ] && note=$key ;;
a|A|h|H|||$left|$pageup)
note=$(( note + 1 )); [ $note -gt $lastnote ] && note=1 ;;
d|D|l|L|' '|' '|$right|$enter|$pagedown)
note=$(( note - 1 )); [ $note = 0 ] && note=$lastnote ;;
s|S|j|J|$down)
note=$lastnote ;;
w|W|k|K|$up)
note=1 ;;
\?)
echo
cat <<EOF
Use space + backspace, arrow keys, pageup/down, WASD, HJKL, or numbers
1 to $lastnote to pick a string. Tune your strings to the notes you hear.
Press Q or Escape to exit.
EOF
;;
$esc|q|Q) break ;;
esac
fi
done
kill "$pid"
echo
|