2
0

menu.sh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/bash
  2. # ./menu.sh
  3. #
  4. # David Rowe
  5. # Created August 2009
  6. #
  7. # Presents a menu of sound files, press 1 to play file1, 2 to play file2 etc
  8. #
  9. # The aim is to make comparing files with different processing easier than
  10. # using up-arrow on the command line. Based on cdialog.
  11. #
  12. # usage:
  13. # menu.sh file1.raw file2.raw ........ [-d playbackdevice]
  14. #
  15. # for example:
  16. #
  17. # ../script/menu.sh hts1a.raw hts1a_uq.raw
  18. #
  19. # or:
  20. #
  21. # ../script/menu.sh hts1a.raw hts1a_uq.raw -d /dev/dsp1
  22. #
  23. # Copyright (C) 2007 David Rowe
  24. #
  25. # All rights reserved.
  26. #
  27. # This program is free software; you can redistribute it and/or modify
  28. # it under the terms of the GNU General Public License version 2, as
  29. # published by the Free Software Foundation.
  30. #
  31. # This program is distributed in the hope that it will be useful,
  32. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  33. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  34. # GNU General Public License for more details.
  35. #
  36. # You should have received a copy of the GNU General Public License
  37. # along with this program; if not, see <http://www.gnu.org/licenses/>.
  38. files=0
  39. items="Q-Quit\n"
  40. while [ ! -z "$1" ]
  41. do
  42. case "$1" in
  43. -d) dsp="${1} ${2}"; shift;;
  44. *) files=`expr 1 + $files`;
  45. new_file=$1;
  46. file[$files]=$new_file;
  47. items="${items} ${files}-${new_file}\n";;
  48. esac
  49. shift
  50. done
  51. echo -n -e "\r" $items"- "
  52. while true ; do
  53. echo -n -e "\r -"
  54. stty cbreak # or stty raw. Stty uses file descriptor 0, not /dev/tty.
  55. readchar=`dd bs=1 count=1 2>/dev/null`
  56. stty -cbreak
  57. if [ -n "$readchar" ] ; then
  58. if [ x$readchar == 'xq' -o x$readchar == 'xQ' ] ; then
  59. echo
  60. exit 0
  61. fi
  62. if [ -z ${file[$readchar]} ] ; then
  63. echo -n -e "\nUnknown input\n" $items"- "
  64. continue
  65. fi
  66. if ( play --version ) >/dev/null 2>&1; then
  67. play -r 8000 -s -2 ${file[$readchar]} $dsp 2> /dev/null
  68. elif ( aplay --version ) > /dev/null 2>&1; then
  69. aplay -r 8000 -f S16_LE ${file[$readchar]} 2> /dev/null
  70. elif ( ossplay -f? ) > /dev/null 2>&1; then
  71. ossplay -s8000 -fS16_LE ${file[$readchar]} 2> /dev/null
  72. else
  73. echo "could not find play, aplay or ossplay program"
  74. fi
  75. fi
  76. done
  77. echo