#!/local/X11/wish -f

# This is an mpeg_play wrapper so users can actually see the anim,
# more than once, select a dithering to use, etc.
#
# Written by Alexei Rodriguez (alexei@cis.ufl.edu) and 
# Bradley C. Spatz (bcs@cis.ufl.edu). 10oct93
#

# set filea to the arg that is passed (file to view).
# Setting quiet to 1 ensures we do not get the default eoj stats
# mpeg_play displays. I have dither set to 15 so that the a correct
# cmd will be built everytime. Otherwise it would default to 0 and
# thus a command line would be built with "-dither" but no option,
# so mpeg_play would assume the file name was the dither type. Wrong.

set filea [lindex $argv 0]
set quiet 1
set dither 15
checkbutton .nob -text "No B Frames"
checkbutton .nop -text "No P Frames"

# This cascade menu may look a bit goofy. It works and I did not
# want to assume everybody had patched the Tk libraries to get 
# "prettier" cascade menus. Our global variable for the radiobuttons
# is dither. Thus, only one button can be selected. No Dither is the
# default.

menubutton .mbutton -relief raised -text "Dithering" -menu .mbutton.menu 
menu .mbutton.menu 
.mbutton.menu add cascade -label "Dithering" -menu .mbutton.menu.more
menu .mbutton.menu.more
.mbutton.menu.more add radiobutton -label "Ordered" -variable dither -value 1
.mbutton.menu.more add radiobutton -label "Fast Ordered" -variable dither -value 2
.mbutton.menu.more add radiobutton -label "Macroblock Ordered" -variable dither -value 3
.mbutton.menu.more add radiobutton -label "Floyd-Steinberg with 4 error values" -variable dither -value 4
.mbutton.menu.more add radiobutton -label "Floyd-Steinberg with 2 error values" -variable dither -value 5
.mbutton.menu.more add radiobutton -label "Fast Floyd-Steinberg with 2 error values" -variable dither -value 6
.mbutton.menu.more add radiobutton -label "Hybrid" -variable dither -value 7
.mbutton.menu.more add radiobutton -label "hybrid with error propagation" -variable dither -value 8
.mbutton.menu.more add radiobutton -label "2x2" -variable dither -value 9
.mbutton.menu.more add radiobutton -label "Grayscale" -variable dither -value 10
.mbutton.menu.more add radiobutton -label "Color 24bit only" -variable dither -value 11
.mbutton.menu.more add radiobutton -label "No display, no dither" -variable dither -value 12
.mbutton.menu.more add radiobutton -label "Monochrome" -variable dither -value 13
.mbutton.menu.more add radiobutton -label "Floyd-Steinberg Simple, monochrome only" -variable dither -value 14
.mbutton.menu.more add radiobutton -label "No dithering" -variable dither -value 15

checkbutton .quiet -text "Quiet"
button  .play -relief raised -text "Play Anim" -command "mpeg $filea"
button  .exit -relief raised -text "Quit" -command exit

pack append . .play {top fillx} .nob {fillx} .nop {fillx} .mbutton {fill} .quiet {fillx} .exit {bottom fillx}

# This procedure, mpeg, will build a list containing the command
# we will exec, the options the user selects, and finally the file
# to be viewed. Note: if mpeg_play is not in your path, you may 
# want to specify it. Also, I have commented out the 'puts stdout '
# line that I was using to debug the script. If you want to see what
# is going to get exec'ed, uncomment the line.

proc mpeg filea {
	global quiet dither nob nop
#       set cmd /local/X11/mpeg_play
	set cmd mpeg_play
	if {$quiet == "1"} {
		lappend cmd "-quiet"
	}
        if {$nob == "1"} {
		lappend cmd "-nob"
	}
	if {$nop == "1"} {
		lappend cmd "-nop"
	}
	if {$dither != "15"} {
		lappend cmd "-dither"
	}
	if {$dither == "1"} {
		lappend cmd "ordered"
	}
	if {$dither == "2"} {
		lappend cmd "ordered2"
	}
	if {$dither == "3"} {
		lappend cmd "mbordered"
	}
	if {$dither == "4"} {
		lappend cmd "fs4"
	}
	if {$dither == "5"} {
		lappend cmd "fs2"
	}
	if {$dither == "6"} {
		lappend cmd "fs2fast"
	}
	if {$dither == "7"} {
		lappend cmd "hybrid"
	}
	if {$dither == "8"} {
		lappend cmd "hybrid2"
	}
	if {$dither == "9"} {
		lappend cmd "2x2"
	}
	if {$dither == "10"} {
		lappend cmd "gray"
	}
	if {$dither == "11"} {
		lappend cmd "color"
	}
	if {$dither == "12"} {
		lappend cmd "none"
	}
	if {$dither == "13"} {
		lappend cmd "mono"
	}
	if {$dither == "14"} {
		lappend cmd "threshold"
	}
	lappend cmd $filea
#	puts stdout $cmd
	eval "exec $cmd"
}
