Add sidplayall.sh
authorColin Patrick Mccabe <cmccabe@alumni.cmu.edu>
Fri, 11 Jan 2013 04:35:06 +0000 (20:35 -0800)
committerColin Patrick Mccabe <cmccabe@alumni.cmu.edu>
Fri, 11 Jan 2013 04:35:06 +0000 (20:35 -0800)
Signed-off-by: Colin McCabe <cmccabe@alumni.cmu.edu>

sidplayall.sh [new file with mode: 0755]

diff --git a/sidplayall.sh b/sidplayall.sh
new file mode 100755 (executable)
index 0000000..09c1488
--- /dev/null
@@ -0,0 +1,60 @@
+#!/bin/bash
+
+usage() 
+{
+    cat <<EOF
+sidplayall.sh: play some sids interactively
+-g [glob]:    The glob to use (default *)
+-h:           show this help message
+EOF
+}
+
+sidplayer_pid=$$
+glob="*"
+while getopts  "g:h" flag; do
+    case $flag in
+    g)  glob=$OPTARG;;
+    h)  usage; exit 0;;
+    *)  echo "getopts error"
+        echo
+        usage
+        exit 1;;
+    esac
+    #echo "$flag" $OPTIND $OPTARG
+done
+
+get_next_action() {
+    line="?"
+    while [ $line == "?" ]; do
+        read line
+        case $line in
+            "") next_file=1;;
+            n) next_file=1;;
+            t) track=$(($track+1));;
+            r) track=$(($track-1));;
+            q) exit 0;;
+            ?) echo "Unknown command.  Commands are:
+Enter or n: next file 
+t: next track
+r: previous track
+q: quit\
+"
+                line="?";;
+        esac
+    done
+}
+
+for sid in $glob.sid; do
+    track=1
+    next_file=0
+    while [ $next_file -eq 0 ]; do
+        next_file=0
+        sidplayer "$sid" $track &
+        sidplayer_pid=$!
+        trap "kill $sidplayer_pid; exit" INT TERM EXIT
+        get_next_action
+        prev_sidplayer_pid=$sidplayer_pid
+        sidplayer_pid=$$
+        kill $prev_sidplayer_pid
+    done
+done