#!/bin/sh # -*-tcl-*- # matchfiles # prototype # Kazuaki Maeda (maeda@ldc.upenn.edu) # $Id: matchfiles.tcl,v 1.2 2000/08/14 07:09:03 maeda Exp maeda $ # \ exec wish8.3 "$0" ${1+"$@"} # configurable variables set player s16play set listFont {helvetica 16 bold} #set listFont {fixed 16 bold} set suffix ".d" # arguments set wordfile [lindex $argv 0] set prefix [lindex $argv 1] set usage "Usage: matchfiles wordfile prefix" if {$argc != 2} { puts $usage exit 1 } proc setFileName {num} { global prefix suffix return $prefix$num$suffix } # main set currentFileNum 1 set xwavespid 0 set totalWords 0 puts "Input word-list is $wordfile" frame .wordlist listbox .wordlist.entries -relief raised -borderwidth 2\ -yscrollcommand ".wordlist.scroll set" -width 100 -font $listFont #-font $listFont -width 100 set count 1 set f [open $wordfile] while {[gets $f line] >= 0} { set word_list($count) [lindex [split $line ";"] 0] set line2 [join [list $count $line] ";"] regsub -all {\t} $line2 " " line2 set speech_list($count) [lindex [split $line ";"] 1] .wordlist.entries insert end $line2 puts $line2 incr count } close $f set totalWords [expr $count - 1] scrollbar .wordlist.scroll -command ".wordlist.entries yview" pack .wordlist.entries -side left -expand yes -fill both pack .wordlist.scroll -side left -fill y pack .wordlist -expand yes -fill both frame .speechlist button .speechlist.play -text "Play" -command {exec $player $currentFile} entry .speechlist.file -width 30 -relief sunken -textvariable currentFile button .speechlist.next -text "Next" -command {incr currentFileNum; \ set currentFile [setFileName $currentFileNum];exec $player $currentFile} button .speechlist.prev -text "Prev" -command {incr currentFileNum -1;\ set currentFile [setFileName $currentFileNum];exec $player $currentFile} button .speechlist.fwd -text "Fwd" -command {incr currentFileNum;\ set currentFile [setFileName $currentFileNum]} button .speechlist.rwd -text "Rwd" -command {incr currentFileNum -1;\ set currentFile [setFileName $currentFileNum]} button .speechlist.rm -text "Remove" -command remove pack .speechlist.play .speechlist.next .speechlist.prev .speechlist.file \ .speechlist.fwd .speechlist.rwd .speechlist.rm \ -side left -ipadx 10 -ipady 10 pack .speechlist -side top -expand yes -fill both frame .control button .control.save -text "Save" -command save button .control.quit -text "Quit" -command quit pack .control.save .control.quit -side left pack .control -side bottom set currentFile [setFileName 1] #bind .wordlist.entries { # if {[winfo exists %W]} { # tkListboxBeginSelect %W [%W index @%x,%y] # } # tkCancelRepeat # %W activate @%x,%y # } bind .wordlist.entries { set sel [selection get] set lineNum [lindex [split $sel ";"] 0] #puts $lineNum set speech_list($lineNum) $currentFile %W delete [expr $lineNum - 1] set line2 $word_list($lineNum) regsub -all {\t} $line2 " " line2 %W insert [expr $lineNum - 1] \ [join [list $lineNum $line2 $currentFile] ";"] } bind .wordlist.entries { set sel [selection get] set lineNum [lindex [split $sel ";"] 0] puts $word_list($lineNum) set playfile $speech_list($lineNum) puts $speech_list($lineNum) if {[file exists $playfile]} { exec $player $playfile & } } proc save {} { global word_list speech_list wordfile totalWords set f [open $wordfile w] for {set i 1} {$i <= $totalWords} {incr i} { puts $f [join [list $word_list($i) $speech_list($i)] ";"] } puts "Saving the list as $wordfile " close $f } proc remove {} { global word_list speech_list wordfile totalWords set sel [selection get] set lineNum [lindex [split $sel ";"] 0] set selFile [lindex [split $sel ";"] 2] if {$selFile != ""} { set speech_list($lineNum) "" .wordlist.entries delete [expr $lineNum - 1] set line2 $word_list($lineNum) regsub -all {\t} $line2 " " line2 .wordlist.entries insert [expr $lineNum - 1] \ [join [list $lineNum $line2 ""] ";"] } } proc quit {} { global xwavespid if {$xwavespid > 0} { exec send_xwaves waves kill puts "killing xwaves $xwavespid ..." exec kill $xwavespid } exit }