|
@@ -19,19 +19,23 @@ class Track(Interval):
|
|
|
# Class methods
|
|
# Class methods
|
|
|
def __init__(self, intervalList, name=None):
|
|
def __init__(self, intervalList, name=None):
|
|
|
"""__init__(intervalList, name)
|
|
"""__init__(intervalList, name)
|
|
|
|
|
+ intervalList: <Interval> |
|
|
|
|
|
+ '[' <delay>,
|
|
|
|
|
+ <Interval>
|
|
|
|
|
+ [ , PREVIOUS_END | PREVIOUS_START | TRACK_START ] ']'
|
|
|
"""
|
|
"""
|
|
|
# Record instance variables
|
|
# Record instance variables
|
|
|
- self.currentInterval = None
|
|
|
|
|
|
|
+ self.currentInterval = None
|
|
|
# Build ilist (need to do this before computing duration)
|
|
# Build ilist (need to do this before computing duration)
|
|
|
- self.__buildIlist(intervalList)
|
|
|
|
|
|
|
+ self.__buildIlist(intervalList)
|
|
|
# Generate unique name if necessary
|
|
# Generate unique name if necessary
|
|
|
- if (name == None):
|
|
|
|
|
- name = 'Track-%d' % Track.trackNum
|
|
|
|
|
- Track.trackNum = Track.trackNum + 1
|
|
|
|
|
|
|
+ if (name == None):
|
|
|
|
|
+ name = 'Track-%d' % Track.trackNum
|
|
|
|
|
+ Track.trackNum = Track.trackNum + 1
|
|
|
# Compute duration
|
|
# Compute duration
|
|
|
- duration = self.__computeDuration()
|
|
|
|
|
|
|
+ duration = self.__computeDuration()
|
|
|
# Initialize superclass
|
|
# Initialize superclass
|
|
|
- Interval.__init__(self, name, duration)
|
|
|
|
|
|
|
+ Interval.__init__(self, name, duration)
|
|
|
# Update stopEventList
|
|
# Update stopEventList
|
|
|
for i in self.ilist:
|
|
for i in self.ilist:
|
|
|
self.stopEventList = self.stopEventList + i[0].stopEventList
|
|
self.stopEventList = self.stopEventList + i[0].stopEventList
|
|
@@ -41,10 +45,10 @@ class Track(Interval):
|
|
|
return self.ilist[item]
|
|
return self.ilist[item]
|
|
|
|
|
|
|
|
# Create a list of this track's intervals, recording time
|
|
# Create a list of this track's intervals, recording time
|
|
|
- # and time type (relative to track start, previous start, previous end
|
|
|
|
|
|
|
+ # and time type (relative to track start, previous start, or previous end)
|
|
|
def __buildIlist(self, intervalList):
|
|
def __buildIlist(self, intervalList):
|
|
|
- self.ilist = []
|
|
|
|
|
- for i in intervalList:
|
|
|
|
|
|
|
+ self.ilist = []
|
|
|
|
|
+ for i in intervalList:
|
|
|
if isinstance(i, Interval):
|
|
if isinstance(i, Interval):
|
|
|
self.ilist.append([i, 0.0, PREVIOUS_END, 0.0, 0.0])
|
|
self.ilist.append([i, 0.0, PREVIOUS_END, 0.0, 0.0])
|
|
|
elif (isinstance(i, types.ListType) or
|
|
elif (isinstance(i, types.ListType) or
|
|
@@ -62,107 +66,107 @@ class Track(Interval):
|
|
|
# Compute duration of the track and precompute start and end time of
|
|
# Compute duration of the track and precompute start and end time of
|
|
|
# each interval
|
|
# each interval
|
|
|
def __computeDuration(self):
|
|
def __computeDuration(self):
|
|
|
- """ __computeDuration()
|
|
|
|
|
- """
|
|
|
|
|
- duration = 0.0
|
|
|
|
|
- prev = None
|
|
|
|
|
|
|
+ """ __computeDuration()
|
|
|
|
|
+ """
|
|
|
|
|
+ duration = 0.0
|
|
|
|
|
+ prev = None
|
|
|
for idata in self.ilist:
|
|
for idata in self.ilist:
|
|
|
ival = idata[IDATA_IVAL]
|
|
ival = idata[IDATA_IVAL]
|
|
|
itime = idata[IDATA_TIME]
|
|
itime = idata[IDATA_TIME]
|
|
|
type = idata[IDATA_TYPE]
|
|
type = idata[IDATA_TYPE]
|
|
|
- assert(itime >= 0.0)
|
|
|
|
|
|
|
+ assert(itime >= 0.0)
|
|
|
# Compute fill time, time between end of last interval and
|
|
# Compute fill time, time between end of last interval and
|
|
|
# start of this one. Depend on interval type
|
|
# start of this one. Depend on interval type
|
|
|
- fillTime = itime
|
|
|
|
|
- if (type == PREVIOUS_END):
|
|
|
|
|
|
|
+ fillTime = itime
|
|
|
|
|
+ if (type == PREVIOUS_END):
|
|
|
pass
|
|
pass
|
|
|
- elif (type == PREVIOUS_START):
|
|
|
|
|
- if (prev != None):
|
|
|
|
|
- fillTime = itime - prev.getDuration()
|
|
|
|
|
- elif (type == TRACK_START):
|
|
|
|
|
- fillTime = itime - duration
|
|
|
|
|
- else:
|
|
|
|
|
- Interval.notify.error(
|
|
|
|
|
- 'Track.__computeDuration(): unknown type: %d' % type)
|
|
|
|
|
|
|
+ elif (type == PREVIOUS_START):
|
|
|
|
|
+ if (prev != None):
|
|
|
|
|
+ fillTime = itime - prev.getDuration()
|
|
|
|
|
+ elif (type == TRACK_START):
|
|
|
|
|
+ fillTime = itime - duration
|
|
|
|
|
+ else:
|
|
|
|
|
+ Interval.notify.error(
|
|
|
|
|
+ 'Track.__computeDuration(): unknown type: %d' % type)
|
|
|
# Check for overlap
|
|
# Check for overlap
|
|
|
- if (fillTime < 0.0):
|
|
|
|
|
- Interval.notify.error(
|
|
|
|
|
- 'Track.__computeDuration(): overlap detected')
|
|
|
|
|
|
|
+ if (fillTime < 0.0):
|
|
|
|
|
+ Interval.notify.error(
|
|
|
|
|
+ 'Track.__computeDuration(): overlap detected')
|
|
|
# Compute start time of interval
|
|
# Compute start time of interval
|
|
|
idata[IDATA_START] = duration + fillTime
|
|
idata[IDATA_START] = duration + fillTime
|
|
|
# Compute end time of interval
|
|
# Compute end time of interval
|
|
|
idata[IDATA_END] = idata[IDATA_START] + ival.getDuration()
|
|
idata[IDATA_END] = idata[IDATA_START] + ival.getDuration()
|
|
|
# Keep track of cumulative duration
|
|
# Keep track of cumulative duration
|
|
|
- duration = idata[IDATA_END]
|
|
|
|
|
- prev = ival
|
|
|
|
|
- return duration
|
|
|
|
|
|
|
+ duration = idata[IDATA_END]
|
|
|
|
|
+ prev = ival
|
|
|
|
|
+ return duration
|
|
|
|
|
|
|
|
def setIntervalStartTime(self, name, itime, type=TRACK_START):
|
|
def setIntervalStartTime(self, name, itime, type=TRACK_START):
|
|
|
- """ setIntervalStartTime(name, itime, type)
|
|
|
|
|
- """
|
|
|
|
|
- found = 0
|
|
|
|
|
|
|
+ """ setIntervalStartTime(name, itime, type)
|
|
|
|
|
+ """
|
|
|
|
|
+ found = 0
|
|
|
# Check for interval in current interval list
|
|
# Check for interval in current interval list
|
|
|
for idata in self.ilist:
|
|
for idata in self.ilist:
|
|
|
# If found, update time and type
|
|
# If found, update time and type
|
|
|
- if (idata[IDATA_IVAL].getName() == name):
|
|
|
|
|
|
|
+ if (idata[IDATA_IVAL].getName() == name):
|
|
|
idata[IDATA_TIME] = itime
|
|
idata[IDATA_TIME] = itime
|
|
|
idata[IDATA_TYPE] = type
|
|
idata[IDATA_TYPE] = type
|
|
|
- found = 1
|
|
|
|
|
- break
|
|
|
|
|
- if (found):
|
|
|
|
|
|
|
+ found = 1
|
|
|
|
|
+ break
|
|
|
|
|
+ if (found):
|
|
|
# And recompute duration
|
|
# And recompute duration
|
|
|
- self.duration = self.__computeDuration()
|
|
|
|
|
- else:
|
|
|
|
|
- Interval.notify.warning(
|
|
|
|
|
- 'Track.setIntervalStartTime(): no Interval named: %s' % name)
|
|
|
|
|
|
|
+ self.duration = self.__computeDuration()
|
|
|
|
|
+ else:
|
|
|
|
|
+ Interval.notify.warning(
|
|
|
|
|
+ 'Track.setIntervalStartTime(): no Interval named: %s' % name)
|
|
|
|
|
|
|
|
def getIntervalStartTime(self, name):
|
|
def getIntervalStartTime(self, name):
|
|
|
- """ getIntervalStartTime(name)
|
|
|
|
|
- """
|
|
|
|
|
|
|
+ """ getIntervalStartTime(name)
|
|
|
|
|
+ """
|
|
|
# Search for interval of given name
|
|
# Search for interval of given name
|
|
|
- for idata in self.ilist:
|
|
|
|
|
- if (idata[IDATA_IVAL].getName() == name):
|
|
|
|
|
- return idata[IDATA_START]
|
|
|
|
|
- Interval.notify.warning(
|
|
|
|
|
- 'Track.getIntervalStartTime(): no Interval named: %s' % name)
|
|
|
|
|
- return None
|
|
|
|
|
|
|
+ for idata in self.ilist:
|
|
|
|
|
+ if (idata[IDATA_IVAL].getName() == name):
|
|
|
|
|
+ return idata[IDATA_START]
|
|
|
|
|
+ Interval.notify.warning(
|
|
|
|
|
+ 'Track.getIntervalStartTime(): no Interval named: %s' % name)
|
|
|
|
|
+ return None
|
|
|
|
|
|
|
|
def __getIntervalStartTime(self, interval):
|
|
def __getIntervalStartTime(self, interval):
|
|
|
- """ __getIntervalStartTime(interval)
|
|
|
|
|
- """
|
|
|
|
|
|
|
+ """ __getIntervalStartTime(interval)
|
|
|
|
|
+ """
|
|
|
# Search for given interval
|
|
# Search for given interval
|
|
|
- for idata in self.ilist:
|
|
|
|
|
- if (idata[IDATA_IVAL] == interval):
|
|
|
|
|
- return idata[IDATA_START]
|
|
|
|
|
- Interval.notify.warning(
|
|
|
|
|
- 'Track.getIntervalStartTime(): Interval not found')
|
|
|
|
|
- return None
|
|
|
|
|
|
|
+ for idata in self.ilist:
|
|
|
|
|
+ if (idata[IDATA_IVAL] == interval):
|
|
|
|
|
+ return idata[IDATA_START]
|
|
|
|
|
+ Interval.notify.warning(
|
|
|
|
|
+ 'Track.getIntervalStartTime(): Interval not found')
|
|
|
|
|
+ return None
|
|
|
|
|
|
|
|
def getIntervalEndTime(self, name):
|
|
def getIntervalEndTime(self, name):
|
|
|
- """ getIntervalEndTime(name)
|
|
|
|
|
- """
|
|
|
|
|
|
|
+ """ getIntervalEndTime(name)
|
|
|
|
|
+ """
|
|
|
# Search for interval of given name
|
|
# Search for interval of given name
|
|
|
- for idata in self.ilist:
|
|
|
|
|
- if (idata[IDATA_IVAL].getName() == name):
|
|
|
|
|
- return idata[IDATA_END]
|
|
|
|
|
- Interval.notify.warning(
|
|
|
|
|
- 'Track.getIntervalEndTime(): no Interval named: %s' % name)
|
|
|
|
|
- return None
|
|
|
|
|
|
|
+ for idata in self.ilist:
|
|
|
|
|
+ if (idata[IDATA_IVAL].getName() == name):
|
|
|
|
|
+ return idata[IDATA_END]
|
|
|
|
|
+ Interval.notify.warning(
|
|
|
|
|
+ 'Track.getIntervalEndTime(): no Interval named: %s' % name)
|
|
|
|
|
+ return None
|
|
|
|
|
|
|
|
def updateFunc(self, t, event = IVAL_NONE):
|
|
def updateFunc(self, t, event = IVAL_NONE):
|
|
|
- """ updateFunc(t, event)
|
|
|
|
|
- Go to time t
|
|
|
|
|
- """
|
|
|
|
|
|
|
+ """ updateFunc(t, event)
|
|
|
|
|
+ Go to time t
|
|
|
|
|
+ """
|
|
|
# Make sure track actually contains some intervals
|
|
# Make sure track actually contains some intervals
|
|
|
if not self.ilist:
|
|
if not self.ilist:
|
|
|
- Interval.notify.warning(
|
|
|
|
|
|
|
+ Interval.notify.warning(
|
|
|
'Track.updateFunc(): track has no intervals')
|
|
'Track.updateFunc(): track has no intervals')
|
|
|
- return
|
|
|
|
|
|
|
+ return
|
|
|
# Deterimine which interval, if any to evaluate
|
|
# Deterimine which interval, if any to evaluate
|
|
|
- if (t < 0):
|
|
|
|
|
|
|
+ if (t < 0):
|
|
|
# Before start of track, do nothing
|
|
# Before start of track, do nothing
|
|
|
- pass
|
|
|
|
|
- else:
|
|
|
|
|
|
|
+ pass
|
|
|
|
|
+ else:
|
|
|
# Initialize local variables
|
|
# Initialize local variables
|
|
|
currentInterval = None
|
|
currentInterval = None
|
|
|
# First entry, re-init instance variables
|
|
# First entry, re-init instance variables
|
|
@@ -179,7 +183,7 @@ class Track(Interval):
|
|
|
# that interval at its final value. If we've crossed over the
|
|
# that interval at its final value. If we've crossed over the
|
|
|
# start of an interval ((prev_t > tStart) and (t < tStart))
|
|
# start of an interval ((prev_t > tStart) and (t < tStart))
|
|
|
# then execute that interval at its start value
|
|
# then execute that interval at its start value
|
|
|
- for ival, itime, itype, tStart, tEnd in self.ilist:
|
|
|
|
|
|
|
+ for ival, itime, itype, tStart, tEnd in self.ilist:
|
|
|
# Compare time with each ival's start/end times
|
|
# Compare time with each ival's start/end times
|
|
|
if (t < tStart):
|
|
if (t < tStart):
|
|
|
if (event == IVAL_DONE):
|
|
if (event == IVAL_DONE):
|
|
@@ -224,12 +228,12 @@ class Track(Interval):
|
|
|
|
|
|
|
|
# Create a printable representation of the track
|
|
# Create a printable representation of the track
|
|
|
def __repr__(self, indent=0):
|
|
def __repr__(self, indent=0):
|
|
|
- """ __repr__(indent)
|
|
|
|
|
- """
|
|
|
|
|
- str = Interval.__repr__(self, indent) + '\n'
|
|
|
|
|
- for idata in self.ilist:
|
|
|
|
|
|
|
+ """ __repr__(indent)
|
|
|
|
|
+ """
|
|
|
|
|
+ str = Interval.__repr__(self, indent) + '\n'
|
|
|
|
|
+ for idata in self.ilist:
|
|
|
# Tack on start and end time for this interval
|
|
# Tack on start and end time for this interval
|
|
|
- str = (str + idata[IDATA_IVAL].__repr__(indent+1) +
|
|
|
|
|
|
|
+ str = (str + idata[IDATA_IVAL].__repr__(indent+1) +
|
|
|
(' start: %0.2f end: %0.2f' %
|
|
(' start: %0.2f end: %0.2f' %
|
|
|
(idata[IDATA_START], idata[IDATA_END])) + '\n'
|
|
(idata[IDATA_START], idata[IDATA_END])) + '\n'
|
|
|
)
|
|
)
|