allow phony durations for sequences

This commit is contained in:
David Rose 2002-09-11 21:58:52 +00:00
parent df9a0176b1
commit 5be2e7041b
3 changed files with 33 additions and 13 deletions

View File

@ -37,6 +37,14 @@ class MetaInterval(CMetaInterval):
interruptible = kw['interruptible']
del kw['interruptible']
# A duration keyword specifies the duration the interval will
# appear to have for the purposes of computing the start time
# for subsequent intervals in a sequence or track.
self.phonyDuration = -1
if kw.has_key('duration'):
self.phonyDuration = kw['duration']
del kw['duration']
if kw:
self.notify.error("Unexpected keyword parameters: %s" % (kw.keys()))
@ -123,23 +131,23 @@ class MetaInterval(CMetaInterval):
# Functions to define sequence, parallel, and track behaviors:
def addSequence(self, list, relTime, relTo):
def addSequence(self, list, relTime, relTo, duration):
# Adds the given list of intervals to the MetaInterval to be
# played one after the other.
self.pushLevel(relTime, relTo)
for ival in list:
self.addInterval(ival, 0.0, PREVIOUS_END)
self.popLevel()
self.popLevel(duration)
def addParallel(self, list, relTime, relTo):
def addParallel(self, list, relTime, relTo, duration):
# Adds the given list of intervals to the MetaInterval to be
# played simultaneously.
self.pushLevel(relTime, relTo)
for ival in list:
self.addInterval(ival, 0.0, TRACK_START)
self.popLevel()
self.popLevel(duration)
def addTrack(self, list, relTime, relTo):
def addTrack(self, list, relTime, relTo, duration):
# Adds a "track list". This is a list of tuples of the form:
#
# ( <delay>, <Interval>,
@ -173,7 +181,7 @@ class MetaInterval(CMetaInterval):
else:
self.notify.error("Not a tuple in Track: %s" % (tuple,))
self.popLevel()
self.popLevel(duration)
def addInterval(self, ival, relTime, relTo):
# Adds the given interval to the MetaInterval.
@ -390,17 +398,17 @@ class MetaInterval(CMetaInterval):
class Sequence(MetaInterval):
def applyIvals(self, meta, relTime, relTo):
meta.addSequence(self.ivals, relTime, relTo)
meta.addSequence(self.ivals, relTime, relTo, self.phonyDuration)
class Parallel(MetaInterval):
def applyIvals(self, meta, relTime, relTo):
meta.addParallel(self.ivals, relTime, relTo)
meta.addParallel(self.ivals, relTime, relTo, self.phonyDuration)
class Track(MetaInterval):
def applyIvals(self, meta, relTime, relTo):
meta.addTrack(self.ivals, relTime, relTo)
meta.addTrack(self.ivals, relTime, relTo, self.phonyDuration)
# Temporary for backward compatibility.
class MultiTrack(MetaInterval):
def applyIvals(self, meta, relTime, relTo):
meta.addParallel(self.ivals, relTime, relTo)
meta.addParallel(self.ivals, relTime, relTo, self.phonyDuration)

View File

@ -200,15 +200,22 @@ add_ext_index(int ext_index, const string &name, double duration,
// Access: Published
// Description: Finishes a level marked by a previous call to
// push_level(), and returns to the previous level.
//
// If the duration is not negative, it represents a
// phony duration to assign to the level, for the
// purposes of sequencing later intervals. Otherwise,
// the level's duration is computed based on the
// intervals within the level.
////////////////////////////////////////////////////////////////////
int CMetaInterval::
pop_level() {
pop_level(double duration) {
nassertr(_event_queue.empty() && !_processing_events, -1);
nassertr(_current_nesting_level > 0, -1);
_defs.push_back(IntervalDef());
IntervalDef &def = _defs.back();
def._type = DT_pop_level;
def._ext_duration = duration;
_current_nesting_level--;
mark_dirty();
@ -1203,9 +1210,14 @@ recompute_level(int n, int level_begin, int &level_end) {
}
if (n < (int)_defs.size()) {
IntervalDef &def = _defs[n];
// If we have a pop record, check it for a phony duration.
if (def._ext_duration >= 0.0) {
level_end = level_begin + double_to_int_time(def._ext_duration);
}
// The final pop "begins" at the level end time, just for clarity
// on output.
IntervalDef &def = _defs[n];
def._actual_begin_time = level_end;
}

View File

@ -55,7 +55,7 @@ PUBLISHED:
int add_ext_index(int ext_index, const string &name,
double duration, bool open_ended,
double rel_time, RelativeStart rel_to);
int pop_level();
int pop_level(double duration = -1.0);
bool set_interval_start_time(const string &name, double rel_time,
RelativeStart rel_to = RS_level_begin);