#!/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 <