~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Open Mash Cross Reference
mash/tcl/mat/ui-mat.tcl

Component: ~ [ mash ] ~ [ apps ] ~ [ gsm ] ~ [ lib ] ~ [ otcl ] ~ [ srm ] ~ [ tcl8.3 ] ~ [ tclcl ] ~ [ tk8.3 ] ~ [ tutorials ] ~

  1 # ui-mat.tcl --
  2 #
  3 #       FIXME: This file needs a description here.
  4 #
  5 # Copyright (c) 1998-2002 The Regents of the University of California.
  6 # All rights reserved.
  7 #
  8 # Redistribution and use in source and binary forms, with or without
  9 # modification, are permitted provided that the following conditions are met:
 10 #
 11 # A. Redistributions of source code must retain the above copyright notice,
 12 #    this list of conditions and the following disclaimer.
 13 # B. Redistributions in binary form must reproduce the above copyright notice,
 14 #    this list of conditions and the following disclaimer in the documentation
 15 #    and/or other materials provided with the distribution.
 16 # C. Neither the names of the copyright holders nor the names of its
 17 #    contributors may be used to endorse or promote products derived from this
 18 #    software without specific prior written permission.
 19 #
 20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
 21 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 23 # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
 24 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 26 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 27 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 28 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 30 
 31 import Playback Rec
 32 
 33 # The user interface for the mat application.
 34 Class MatUI
 35 
 36 wm withdraw .
 37 
 38 #
 39 MatUI public init {} {
 40         $self next
 41 
 42         $self instvar module_
 43 
 44         set module_ [$self get_option module]
 45         toplevel .top
 46         $self build_ui .top
 47         $self reset
 48 }
 49 
 50 #
 51 MatUI private build_ui { w } {
 52 
 53         # FIXME
 54         set vspec [$self get_option videoSpec]
 55         set aspec [$self get_option audioSpec]
 56         set mbspec [$self get_option mbSpec]
 57 #       eval exec mash ../mash/bin/vic -X loopback=1 $vspec
 58 #       eval exec mash ../mash/bin/vat -X loopback=1 $aspec
 59         $self instvar vpid_ apid_ mbpid_
 60         set vpid_ [eval exec vic -X loopback=1 $vspec &]
 61         set apid_ [eval exec vat -X loopback=1 $aspec &]
 62 # Reset will start mb.
 63 #       set mbpid_ [eval exec mb -sa $mbspec &]
 64 
 65         bind $w <space> "$self advance_slide"
 66 
 67         frame $w.slide -relief sunken
 68         set c $w.slide.c
 69         $self instvar canvas_ image_
 70         set width [$self get_option slideWidth]
 71         set height [$self get_option slideHeight]
 72         canvas $c -height $height -width $width
 73 
 74         set canvas_ $c
 75         set image_ [image create photo -height $height -width $width]
 76         $image_ blank
 77 
 78         $c create image 0 0 -anchor nw -image $image_
 79 
 80         pack $c -fill both
 81         pack $w.slide -expand 1 -fill both
 82 
 83         global curtime
 84         set curtime 00:00:00
 85 
 86         frame $w.slider
 87         scale $w.slider.scale -orient horizontal -from 0 \
 88                 -to [$self get_option ltsEnd] -command "$self goto"
 89         pack $w.slider.scale -expand 1 -fill x
 90         pack $w.slider -expand 1 -fill x
 91 
 92         frame $w.bot -relief ridge -borderwidth 2
 93         $self instvar buttons_
 94         set buttons_(record) \
 95                 [button $w.bot.record -text Record -command "$self record"]
 96         label $w.bot.clock -textvariable curtime
 97         label $w.bot.title -text "MASH Authoring Tool v1.0"
 98         set buttons_(play) \
 99                 [button $w.bot.play -text Play -command "$self play"]
100         set buttons_(pause) \
101                 [button $w.bot.pause -text Pause -command "$self pause"]
102         set buttons_(reset) \
103                 [button $w.bot.reset -text Reset -command "$self reset"]
104         set buttons_(stop) \
105                 [button $w.bot.stop -text Stop -command "$self stop"]
106         set buttons_(quit) \
107                 [button $w.bot.quit -text Quit -command "$self quit"]
108         pack $w.bot.record $w.bot.pause $w.bot.reset $w.bot.play \
109                 $w.bot.stop -side left
110         pack $w.bot.clock -side left -ipadx 10
111         pack $w.bot.title -side left -fill x -expand 1
112         pack $w.bot.quit -side right
113         pack $w.bot -fill x -expand 1
114 
115 
116         $buttons_(record) configure -state normal
117         $buttons_(play) configure -state normal
118         $buttons_(pause) configure -state disabled
119         $buttons_(reset) configure -state disabled
120         $buttons_(stop) configure -state disabled
121 }
122 
123 #
124 MatUI private advance_slide {} {
125         $self instvar image_ slidenum_ zero_ fd_ state_
126 
127         if { $state_ != "rec" } {
128                 return
129         }
130         set dir [$self get_option slideDir]
131 
132         set h [expr $slidenum_/100]
133         set t [expr ($slidenum_ - 100*$h)/10]
134         set u [expr $slidenum_ - 100*$h - 10*$t]
135 
136         set sname img$h$t$u.GIF
137         set f $dir/$sname
138         if ![file exists $f] {
139                 puts stderr "mat: no such file $f"
140                 return
141         }
142         $image_ read $dir/$sname -format gif
143 
144         set prefix [$self get_option urlPrefix]
145         set fname sld$h$t$u.htm
146         puts $fd_ "[$self runtime] $prefix$fname"
147         incr slidenum_
148 }
149 
150 #
151 MatUI private record {} {
152         $self instvar tid_ zero_ state_ buttons_ pause_time_ pause_start_ fd_ \
153                 module_
154 
155 
156         set now [gettimeofday]
157         if { $zero_ < 0 } {
158                 set zero_ $now
159         }
160         if { $pause_start_ > 0 } {
161                 set pause_time_ [expr $pause_time_ + $now - $pause_start_]
162         }
163         $self instvar rec_
164         $rec_ start
165 
166         set archive [$self get_option archive]
167         set fname $archive/$module_/[$self get_option slideOutputFile]
168         set fd_ [open $fname w+]
169 
170         $buttons_(record) configure -state disabled
171         $buttons_(play) configure -state disabled
172 #       $buttons_(pause) configure -state normal
173         $buttons_(reset) configure -state disabled
174         $buttons_(stop) configure -state normal
175 
176         set state_ rec
177         set tid_ [after 1000 "$self advance_time"]
178 }
179 
180 # FIXME This not done right yet
181 MatUI private pause {} {
182         $self instvar tid_ state pause_start_ buttons_
183         if { $running_ } {
184                 if [info exists tid_] {
185                         after cancel $tid_
186                 }
187                 set state_ pause
188                 $buttons_(record) configure -state normal
189                 $buttons_(pause) configure -state disabled
190                 set pause_start_ [gettimeofday]
191         }
192 }
193 
194 #
195 MatUI private reset {} {
196         $self instvar zero_ slidenum_ fd_ state_ buttons_ tid_ pause_time_ \
197                 pause_start_ rec_ play_ module_
198 
199         if [info exists rec_] {
200                 delete $rec_
201         }
202         if [info exists play_] {
203                 delete $play_
204         }
205         set rec_ [new Rec $module_]
206         set playmodule $module_
207         append playmodule catalog
208         set play_ [new Playback $playmodule]
209 
210         # FIXME Need to restart mb since the SRM state is confused.
211         $self instvar mbpid_
212         set mbspec [$self get_option mbSpec]
213         if [info exists mbpid_] {
214             catch " exec kill -9 $mbpid_ "
215         }
216         set mbpid_ [exec mb -sa $mbspec &]
217 
218         set zero_ -1
219         set pause_start_ -1
220         set pause_time_ 0
221         global curtime
222         set curtime [$self format_time 0]
223         set slidenum_ 1
224         if [info exists fd_] {
225                 close $fd_
226         }
227         if [info exists tid_] {
228                 after cancel $tid_
229         }
230         set state_ reset
231         $buttons_(record) configure -state normal
232         $buttons_(pause) configure -state disabled
233         $buttons_(stop) configure -state disabled
234         $buttons_(reset) configure -state disabled
235         $buttons_(play) configure -state normal
236 
237         $self instvar image_
238         $image_ blank
239 }
240 
241 #
242 MatUI private play {} {
243         $self instvar play_ state_ image_ buttons_ zero_ pause_start_ \
244                 pause_time_
245         set state_ play
246         $image_ blank
247 
248         set now [gettimeofday]
249         if { $zero_ < 0 } {
250                 set zero_ $now
251         }
252         if { $pause_start_ > 0 } {
253                 set pause_time_ [expr $pause_time_ + $now - $pause_start_]
254         }
255         set tid_ [after 1000 "$self advance_time"]
256 
257         $buttons_(record) configure -state disabled
258         $buttons_(pause) configure -state disabled
259         $buttons_(stop) configure -state normal
260         $buttons_(reset) configure -state disabled
261         $buttons_(play) configure -state disabled
262 
263         $play_ start $self
264 }
265 
266 #
267 MatUI private stop {} {
268         $self instvar fd_ buttons_ tid_ state_
269         if [info exists fd_] {
270                 flush $fd_
271                 close $fd_
272                 unset fd_
273         }
274         if [info exists tid_] {
275                 after cancel $tid_
276         }
277         $self instvar rec_ play_
278         if { $state_ == "rec" } {
279                 $rec_ stop
280         } elseif { $state_ == "play" } {
281                 $play_ stop
282         }
283         set state_ stop
284         $buttons_(record) configure -state disabled
285         $buttons_(play) configure -state disabled
286         $buttons_(pause) configure -state disabled
287         $buttons_(reset) configure -state normal
288         $buttons_(stop) configure -state disabled
289 }
290 
291 #
292 MatUI private show { url } {
293         # FIXME This all wrong.   This is simply a hack so that we
294         # can playback previously stored presentations.
295         $self instvar image_
296         set u [lindex [split $url :] 1]
297         set name [file rootname [file tail $u]]
298         set t [split $name d]
299         set num [lindex $t 1]
300         $image_ read [file dirname $u]/img$num.GIF -format gif
301 }
302 
303 #
304 MatUI private advance_time {} {
305         global curtime
306         set curtime [$self format_time [$self runtime]]
307 
308         $self instvar tid_
309         set tid_ [after 1000 "$self advance_time"]
310 }
311 
312 #
313 MatUI private runtime {} {
314         $self instvar zero_ pause_time_
315 
316         return [expr int([gettimeofday] - $zero_ - $pause_time_ + 0.5)]
317 }
318 
319 #
320 MatUI private format_time { sec } {
321 
322         set h [expr $sec/3600]
323         set h0 [expr $h/10]
324         set h1 [expr $h%10]
325 
326         set m [expr ($sec - $h*3600)/60]
327         set m0 [expr $m/10]
328         set m1 [expr $m%10]
329 
330         set s [expr $sec - $h*3600 - $m*60]
331         set s0 [expr $s/10]
332         set s1 [expr $s%10]
333 
334         return $h0$h1:$m0$m1:$s0$s1
335 }
336 
337 #
338 MatUI private quit {} {
339         $self instvar vpid_ apid_ mbpid_
340         catch "exec kill -9 $vpid_ $apid_ $mbpid_"
341         $self stop
342         exit 0
343 }
344 
345 #
346 MatUI private goto { t } {
347         $self instvar rec_ play_ state_
348         if { $state_ == "rec" } {
349                 $rec_ goto $t
350         } elseif { $state_ == "play" } {
351                 $play_ goto $t
352         }
353 }
354 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.