Ignore:
Timestamp:
Jan 9, 2011 9:30:53 PM (13 years ago)
Author:
dkearney
Message:

updates for video widgets
two new video dials
video chooser widget for selecting movies
video preview widget is a no frills movie player.
updated c code to more correctly report the last frame of the movie.
new video speed widget which allows for fractional values between 0x and 1.0x
updated piv/pve example application
fixed "release" function in tcl bindings for RpVideo?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/videoscreen.tcl

    r1979 r2023  
    1717
    1818option add *Video.width 300 widgetDefault
    19 option add *Video*cursor crosshair widgetDefault
    2019option add *Video.height 300 widgetDefault
    2120option add *Video.foreground black widgetDefault
    2221option add *Video.controlBackground gray widgetDefault
    23 option add *Video.controlDarkBackground #999999 widgetDefault
    24 option add *Video.plotBackground black widgetDefault
    25 option add *Video.plotForeground white widgetDefault
    26 option add *Video.plotOutline gray widgetDefault
    2722option add *Video.font \
    2823    -*-helvetica-medium-r-normal-*-12-* widgetDefault
     
    3126    inherit itk::Widget
    3227
    33     itk_option define -plotforeground plotForeground Foreground ""
    34     itk_option define -plotbackground plotBackground Background ""
    35     itk_option define -plotoutline plotOutline PlotOutline ""
    3628    itk_option define -width width Width -1
    3729    itk_option define -height height Height -1
     30    itk_option define -fileopen fileopen Fileopen ""
    3831
    3932    constructor { args } {
     
    109102
    110103    array set _settings [subst {
    111         $this-currenttime       0
    112104        $this-framenum          0
    113105        $this-loop              0
     
    122114
    123115
    124 
    125116    # Create flow controls...
    126117
     
    132123        rename -background -controlbackground controlBackground Background
    133124    }
    134 
    135     # pack $itk_component(main) -side top -expand yes -fill both
    136125    bind $itk_component(main) <Configure> [itcl::code $this fixSize]
     126
     127    # hold the video frames in an image on the canvas
     128    set _imh [image create photo]
     129    $itk_component(main) create image 0 0 -anchor nw -image $_imh
    137130
    138131    # setup movie controls
     
    154147    set imagesDir [file join $RapptureGUI::library scripts images]
    155148
     149    # ==== fileopen ====
     150    itk_component add fileopen {
     151        button $itk_component(moviecontrols).fileopen \
     152            -borderwidth 1 -padx 1 -pady 1 \
     153            -image [Rappture::icon upload] \
     154            -command [itcl::code $this loadcb]
     155            #-command [Rappture::filexfer::upload {piv tool} {id label desc} [itcl::code $this Upload]]
     156            #-command [itcl::code $this video seek 0]
     157    } {
     158        usual
     159        ignore -borderwidth
     160        rename -highlightbackground -controlbackground controlBackground \
     161            Background
     162    }
     163    Rappture::Tooltip::for $itk_component(fileopen) \
     164        "Open file"
    156165
    157166    # ==== measuring tool ====
     
    254263        "Play continuously between marked sections"
    255264
    256     # Video Dial
    257265    itk_component add dial {
    258         Rappture::Videodial $itk_component(moviecontrols).dial \
     266        frame $itk_interior.dial
     267    } {
     268        usual
     269        rename -background -controlbackground controlBackground Background
     270    }
     271
     272    # Video Dial Major
     273    itk_component add dialmajor {
     274        Rappture::Videodial1 $itk_component(dial).dialmajor \
    259275            -length 10 -valuewidth 0 -valuepadding 0 -padding 6 \
    260276            -linecolor "" -activelinecolor "" \
    261277            -min 0 -max 1 \
    262             -minortick 1 -majortick 5 \
    263             -variable [itcl::scope _settings($this-currenttime)] \
     278            -variable [itcl::scope _settings($this-framenum)] \
    264279            -dialoutlinecolor black \
    265280            -knobimage [Rappture::icon knob2] -knobposition center@middle
     
    269284        rename -background -controlbackground controlBackground Background
    270285    }
    271     $itk_component(dial) current 0
    272     bind $itk_component(dial) <<Value>> [itcl::code $this video update]
     286    $itk_component(dialmajor) current 0
     287    bind $itk_component(dialmajor) <<Value>> [itcl::code $this video update]
     288
     289    # Video Dial Minor
     290    itk_component add dialminor {
     291        Rappture::Videodial2 $itk_component(dial).dialminor \
     292            -padding 0 \
     293            -min 0 -max 1 \
     294            -minortick 1 -majortick 5 \
     295            -variable [itcl::scope _settings($this-framenum)] \
     296            -dialoutlinecolor black
     297    } {
     298        usual
     299        rename -background -controlbackground controlBackground Background
     300    }
     301    $itk_component(dialminor) current 0
     302    bind $itk_component(dialminor) <<Value>> [itcl::code $this video update]
    273303
    274304    itk_component add framenumlabel {
     
    282312
    283313    # Current Frame Number
    284     #set ffont "arial 9"
    285     #set fwidth [calcLabelWidth $ffont]
    286314    itk_component add framenum {
    287315        label $itk_component(frnumfr).framenum \
     
    293321        rename -background -controlbackground controlBackground Background
    294322    }
    295     #$itk_component(framenum) value 1
    296     #bind $itk_component(framenum) <<Value>> \
    297     #    [itcl::code $this video seek -framenum]
    298323    Rappture::Tooltip::for $itk_component(framenum) \
    299324        "Current frame number"
     
    315340    # Speed
    316341    itk_component add speed {
    317         Rappture::Flowspeed $itk_component(moviecontrols).speed \
    318             -min 1 -max 10 -width 3 -font "arial 9"
     342        Rappture::Videospeed $itk_component(moviecontrols).speed \
     343            -min 0 -max 1 -width 4 -font "arial 9" -factor 2
    319344    } {
    320345        usual
     
    325350        "Change speed of movie"
    326351
    327     $itk_component(speed) value 1
     352    $itk_component(speed) value 0.25
    328353    bind $itk_component(speed) <<Value>> [itcl::code $this video speed]
    329354
    330355
     356    blt::table $itk_component(dial) \
     357        0,0 $itk_component(dialmajor) -fill x \
     358        1,0 $itk_component(dialminor) -fill x
     359
     360
    331361    blt::table $itk_component(moviecontrols) \
    332         0,0 $itk_component(measure) -padx {2 0}  \
    333         0,1 $itk_component(particle) -padx {4 0} \
     362        0,0 $itk_component(fileopen) -padx {2 0}  \
     363        0,1 $itk_component(measure) -padx {4 0}  \
     364        0,2 $itk_component(particle) -padx {4 0} \
    334365        0,5 $itk_component(dial) -fill x -padx {2 4} -rowspan 3 \
    335366        1,0 $itk_component(rewind) -padx {2 0} \
     
    361392itcl::body Rappture::VideoScreen::destructor {} {
    362393    array unset _settings $this-*
     394    if {[info exists _imh]} {
     395        image delete $_imh
     396    }
    363397}
    364398
     
    394428    }
    395429
     430    if {([info exists _movie]) && ("" != ${_movie})} {
     431        ${_movie} release
     432    }
     433
    396434    set _movie [Rappture::Video $type $data]
    397435    file delete $fname
    398436    set _framerate [${_movie} get framerate]
    399     set _mspf [expr round(((1.0/${_framerate})*1000)/pow(2,$_settings($this-speed)-1))]
    400     set _delay [expr {${_mspf} - ${_ofrd}}]
    401     puts stderr "framerate = ${_framerate}"
    402     puts stderr "mspf = ${_mspf}"
    403     puts stderr "ofrd = ${_ofrd}"
    404     puts stderr "delay = ${_delay}"
    405 
    406     ${_movie} seek 0
     437    video speed
     438
     439    video seek 0
     440
     441    # update the dial and framenum widgets
     442    set _settings($this-framenum) 0
     443
    407444
    408445    # setup the image display
    409446
    410     set _imh [image create photo]
    411447    foreach {w h} [query dimensions] break
    412448    if {${_width} == -1} {
     
    416452        set _height $h
    417453    }
    418     $itk_component(main) create image 0 0 -anchor nw -image $_imh
    419454
    420455    set _lastFrame [$_movie get position end]
    421456
    422457    # update the dial with video information
    423     $itk_component(dial) configure -min 0 -max ${_lastFrame}
     458    $itk_component(dialmajor) configure -min 0 -max ${_lastFrame}
     459    $itk_component(dialminor) configure -min 0 -max ${_lastFrame}
    424460
    425461    fixSize
     
    466502    }
    467503
    468     set _width [winfo width $itk_component(main)]
    469     set _height [winfo height $itk_component(main)]
     504#    set _width [winfo width $itk_component(main)]
     505#    set _height [winfo height $itk_component(main)]
     506#
     507#    # get an image with the new size
     508#    ${_imh} put [${_movie} get image ${_width} ${_height}]
     509#
     510#    # fix the dimesions of the canvas
     511#    #$itk_component(main) configure -width ${_width} -height ${_height}
     512#
     513#    $itk_component(main) configure -scrollregion [$itk_component(main) bbox all]
     514
     515######################
    470516
    471517    # get an image with the new size
    472518    ${_imh} put [${_movie} get image ${_width} ${_height}]
    473 
    474     # fix the dimesions of the canvas
    475     #$itk_component(main) configure -width ${_width} -height ${_height}
    476 
    477     $itk_component(main) configure -scrollregion [$itk_component(main) bbox all]
     519    puts stderr "${_width} ${_height}"
     520
     521    # fix the dimesions of the video canvas
     522    $itk_component(main) configure -width ${_width} -height ${_height}
    478523}
    479524
     
    486531        "play" {
    487532            if {$_settings($this-play) == 1} {
    488                 # disable seek while playing
    489                 # bind $itk_component(dial) <<Value>> ""
    490533                eventually play
    491534            } else {
     
    494537                set _pendings(play) 0
    495538                set _settings($this-play) 0
    496                 # enable seek while paused
    497                 # bind $itk_component(dial) <<Value>> [itcl::code $this updateFrame]
    498539            }
    499540        }
     
    507548        "speed" {
    508549            set speed [$itk_component(speed) value]
    509             set _mspf [expr round(((1.0/${_framerate})*1000)/pow(2,$speed-1))]
     550            set _mspf [expr round(((1.0/${_framerate})*1000)/$speed)]
    510551            set _delay [expr {${_mspf} - ${_ofrd}}]
    511552            puts stderr "_mspf = ${_mspf} | $speed | ${_ofrd} | ${_delay}"
    512553        }
    513554        "update" {
    514             #video stop
    515             # eventually seek [expr round($_settings($this-currenttime))]
    516             Seek [expr round($_settings($this-currenttime))]
    517             # Seek $_settings($this-framenum)
    518             #after idle [itcl::code $this video play]
     555            # eventually seek [expr round($_settings($this-framenum))]
     556            Seek [expr round($_settings($this-framenum))]
    519557        }
    520558        default {
     
    555593itcl::body Rappture::VideoScreen::Play {} {
    556594
     595    set cur ${_nextframe}
     596
    557597    # time how long it takes to retrieve the next frame
    558598    set _ofrd [time {
    559         $_movie seek $_nextframe
     599        # use seek instead of next fxn incase the ${_nextframe} is
     600        # not the current frame+1. this happens when we skip frames
     601        # because the underlying c lib is too slow at reading.
     602        $_movie seek $cur
    560603        $_imh put [$_movie get image ${_width} ${_height}]
    561604    } 1]
     
    574617
    575618    # update the dial and framenum widgets
    576     set _settings($this-currenttime) $cur
    577619    set _settings($this-framenum) $cur
    578620
    579     if {[expr $cur%100] == 0} {
    580 #        puts stderr "ofrd = ${_ofrd}"
    581 #        puts stderr "delay = ${_delay}"
    582 #        puts stderr "after: [after info]"
    583 #        puts stderr "id = ${_id}"
    584     }
    585621
    586622    # no play cmds pending
     
    590626    # then loop back to loopstart when cur hits loopend
    591627    if {$_settings($this-loop)} {
    592         if {$cur == [$itk_component(dial) mark position loopend]} {
    593             Seek [$itk_component(dial) mark position loopstart]
     628        if {$cur == [$itk_component(dialminor) mark position loopend]} {
     629            Seek [$itk_component(dialminor) mark position loopstart]
    594630        }
    595631    }
     
    598634    if {$cur < ${_lastFrame}} {
    599635        set _id [after ${_delay} [itcl::code $this eventually play]]
    600     }
    601 
    602 #    event generate $itk_component(hull) <<Frame>>
     636    } else {
     637        video stop
     638    }
     639
     640    event generate $itk_component(hull) <<Frame>>
    603641}
    604642
     
    624662
    625663    # update the dial and framenum widgets
     664    set _settings($this-framenum) [$_movie get position cur]
    626665    event generate $itk_component(main) <<Frame>>
    627     set cur [$_movie get position cur]
    628     set _settings($this-currenttime) $cur
    629     set _settings($this-framenum) $cur
    630666
    631667}
     
    836872            ${_obj} Coords $x $y $x $y
    837873            ${_obj} Show object
    838             $itk_component(dial) mark add arrow current
     874            $itk_component(dialminor) mark add arrow current
    839875        }
    840876        "drag" {
     
    898934            ${_obj} Coords $x $y
    899935            ${_obj} Show object
    900             $itk_component(dial) mark add $name current
     936            $itk_component(dialminor) mark add $name current
    901937            # bind $itk_component(hull) <<Frame>> [itcl::code $itk_component(main).$name UpdateFrame]
    902938
     
    9931029# ----------------------------------------------------------------------
    9941030itcl::body Rappture::VideoScreen::writeText {x y text color tags width} {
    995     # write text up-left
    996     $itk_component(main) create text [expr $x-1] [expr $y-1] \
     1031    $itk_component(main) create text [expr $x-1] [expr $y] \
    9971032        -tags $tags \
    9981033        -justify center \
     
    10011036        -width $width
    10021037
    1003     # write text down-right
    1004     $itk_component(main) create text [expr $x+1] [expr $y+1] \
     1038    $itk_component(main) create text [expr $x+1] [expr $y] \
    10051039        -tags $tags \
    10061040        -justify center \
     
    10081042        -fill black \
    10091043        -width $width
     1044
     1045    $itk_component(main) create text [expr $x] [expr $y-1] \
     1046        -tags $tags \
     1047        -justify center \
     1048        -text $text \
     1049        -fill black \
     1050        -width $width
     1051
     1052    $itk_component(main) create text [expr $x] [expr $y+1] \
     1053        -tags $tags \
     1054        -justify center \
     1055        -text $text \
     1056        -fill black \
     1057        -width $width
     1058
     1059#    # write text up-left
     1060#    $itk_component(main) create text [expr $x-1] [expr $y-1] \
     1061#        -tags $tags \
     1062#        -justify center \
     1063#        -text $text \
     1064#        -fill black \
     1065#        -width $width
     1066#
     1067#    # write text down-right
     1068#    $itk_component(main) create text [expr $x+1] [expr $y+1] \
     1069#        -tags $tags \
     1070#        -justify center \
     1071#        -text $text \
     1072#        -fill black \
     1073#        -width $width
    10101074
    10111075    # write text at x,y
     
    10311095
    10321096    if {($frames != 0) && (${_px2dist} != 0)} {
    1033         set t [expr 1.0*$px/$frames/${_px2dist}*${_framerate}]
     1097        set t [expr 1.0*$px/$frames*${_px2dist}*${_framerate}]
    10341098    } else {
    10351099        set t 0.0
     
    10441108itcl::body Rappture::VideoScreen::toggleloop {} {
    10451109    if {$_settings($this-loop) == 0} {
    1046         $itk_component(dial) mark remove loopstart
    1047         $itk_component(dial) mark remove loopend
     1110        $itk_component(dialminor) mark remove loopstart
     1111        $itk_component(dialminor) mark remove loopend
    10481112    } else {
    10491113        set cur [$_movie get position cur]
     
    10601124        }
    10611125
    1062         $itk_component(dial) mark add loopstart $startframe
    1063         $itk_component(dial) mark add loopend $endframe
     1126        $itk_component(dialminor) mark add loopstart $startframe
     1127        $itk_component(dialminor) mark add loopend $endframe
    10641128    }
    10651129
     
    10741138        error "bad value: \"$itk_option(-width)\": width should be an integer"
    10751139    }
    1076     set ${_width} $itk_option(-width)
     1140    set _width $itk_option(-width)
    10771141    after idle [itcl::code $this fixSize]
    10781142}
     
    10861150        error "bad value: \"$itk_option(-height)\": height should be an integer"
    10871151    }
    1088     set ${_height} $itk_option(-height)
     1152    set _height $itk_option(-height)
    10891153    after idle [itcl::code $this fixSize]
    10901154}
     1155
     1156# ----------------------------------------------------------------------
     1157# OPTION: -fileopen
     1158# ----------------------------------------------------------------------
     1159itcl::configbody Rappture::VideoScreen::fileopen {
     1160    $itk_component(fileopen) configure -command $itk_option(-fileopen)
     1161}
Note: See TracChangeset for help on using the changeset viewer.