1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
# copyright (C) 1997-2005 Jean-Luc Fontaine (mailto:jfontain@free.fr)
# this program is free software: please read the COPYRIGHT file enclosed in this package or use the Help Copyright menu
# $Id: sequencer.tcl,v 1.5 2005/01/02 00:45:07 jfontain Exp $
class sequencer {
proc sequencer {this milliSeconds keyword list script} {
set ($this,period) $milliSeconds
set ($this,keyword) $keyword ;# such as %e for example
set ($this,list) $list
set ($this,script) $script
set ($this,length) [llength $list]
}
proc ~sequencer {this} {
stop $this
}
proc start {this} {
set ($this,index) 0
set ($this,repeater) [new repeater $($this,period) "sequencer::next $this"]
repeater::start $($this,repeater)
}
proc stop {this} {
if {[info exists ($this,repeater)]} {
delete $($this,repeater)
unset ($this,repeater)
}
}
proc next {this} {
regsub -all $($this,keyword) $($this,script) [lindex $($this,list) $($this,index)] command
uplevel #0 $command
if {[incr ($this,index)] >= $($this,length)} {
set ($this,index) 0
}
}
}
|