bashrc/.bashrc.d/sing.bash

167 lines
2.7 KiB
Bash

note2freq(){
local freq
case $1 in
A[1-7])
case $1 in
*1) freq=55;;
*2) freq=110;;
*3) freq=220;;
*4) freq=440;;
*5) freq=880;;
*6) freq=1760;;
*7) freq=3520;;
esac
;;
Bb[1-7]|As[1-7])
case $1 in
*1) freq=58;;
*2) freq=117;;
*3) freq=233;;
*4) freq=466;;
*5) freq=932;;
*6) freq=1865;;
*7) freq=3729;;
esac
;;
B[1-7])
case $1 in
*1) freq=62;;
*2) freq=124;;
*3) freq=247;;
*4) freq=494;;
*5) freq=988;;
*6) freq=1976;;
*7) freq=3951;;
esac
;;
C[1-7])
case $1 in
*1) freq=33;;
*2) freq=65;;
*3) freq=131;;
*4) freq=262;;
*5) freq=523;;
*6) freq=1047;;
*7) freq=2093;;
esac
;;
Cs[1-7]|Db[1-7])
case $1 in
*1) freq=35;;
*2) freq=69;;
*3) freq=139;;
*4) freq=277;;
*5) freq=554;;
*6) freq=1109;;
*7) freq=2217;;
esac
;;
D[1-7])
case $1 in
*1) freq=37;;
*2) freq=73;;
*3) freq=147;;
*4) freq=294;;
*5) freq=587;;
*6) freq=1175;;
*7) freq=2349;;
esac
;;
Ds[1-7]|Eb[1-7])
case $1 in
*1) freq=39;;
*2) freq=73;;
*3) freq=147;;
*4) freq=294;;
*5) freq=587;;
*6) freq=1175;;
*7) freq=2349;;
esac
;;
E[1-7])
case $1 in
*1) freq=41;;
*2) freq=82;;
*3) freq=165;;
*4) freq=330;;
*5) freq=659;;
*6) freq=1319;;
*7) freq=2637;;
esac
;;
F[1-7])
case $1 in
*1) freq=44;;
*2) freq=87;;
*3) freq=175;;
*4) freq=349;;
*5) freq=699;;
*6) freq=1397;;
*7) freq=2794;;
esac
;;
Fs[1-7]|Gb[1-7])
case $1 in
*1) freq=46;;
*2) freq=93;;
*3) freq=185;;
*4) freq=370;;
*5) freq=740;;
*6) freq=1480;;
*7) freq=2960;;
esac
;;
G[1-7])
case $1 in
*1) freq=49;;
*2) freq=98;;
*3) freq=196;;
*4) freq=392;;
*5) freq=784;;
*6) freq=1568;;
*7) freq=3136;;
esac
;;
Gs[1-7]|Ab[1-7])
case $1 in
*1) freq=52;;
*2) freq=104;;
*3) freq=208;;
*4) freq=415;;
*5) freq=831;;
*6) freq=1661;;
*7) freq=3322;;
esac
;;
*)
printf "ERROR: Unknown note: \"%s\"
Valid note syntax: <letter>[accidental]<octave>
Valid values:
<letter> \"A\" through \"G\"
[accidental] \"b\" (flat), or \"s\" (sharp)
Exceptions: \"Bs\", \"Cb\", \"Es\", and \"Fb\" are not valid.
<octave> \"1\" through \"7\"
" "$1"
return
esac
printf "%s" "$freq"
}
sing() {
local beepstring
while [ "${3+defined}" ]; do
if [ "$3" = "-n" ]; then
beepstring="$beepstring -f $(note2freq $1) -l $2 -n"
shift 3
else
echo "Error"
return
fi
done
if [ -z "$3" ]; then
beepstring="$beepstring -f $(note2freq $1) -l $2"
beep $beepstring
fi
}