Browse Source

allow phony durations for sequences

David Rose 23 years ago
parent
commit
5be2e7041b

+ 18 - 10
direct/src/interval/MetaInterval.py

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

+ 14 - 2
direct/src/interval/cMetaInterval.cxx

@@ -200,15 +200,22 @@ add_ext_index(int ext_index, const string &name, double duration,
 //       Access: Published
 //       Access: Published
 //  Description: Finishes a level marked by a previous call to
 //  Description: Finishes a level marked by a previous call to
 //               push_level(), and returns to the previous level.
 //               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::
 int CMetaInterval::
-pop_level() {
+pop_level(double duration) {
   nassertr(_event_queue.empty() && !_processing_events, -1);
   nassertr(_event_queue.empty() && !_processing_events, -1);
   nassertr(_current_nesting_level > 0, -1);
   nassertr(_current_nesting_level > 0, -1);
 
 
   _defs.push_back(IntervalDef());
   _defs.push_back(IntervalDef());
   IntervalDef &def = _defs.back();
   IntervalDef &def = _defs.back();
   def._type = DT_pop_level;
   def._type = DT_pop_level;
+  def._ext_duration = duration;
   _current_nesting_level--;
   _current_nesting_level--;
   mark_dirty();
   mark_dirty();
 
 
@@ -1203,9 +1210,14 @@ recompute_level(int n, int level_begin, int &level_end) {
   }
   }
 
 
   if (n < (int)_defs.size()) {
   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
     // The final pop "begins" at the level end time, just for clarity
     // on output.
     // on output.
-    IntervalDef &def = _defs[n];
     def._actual_begin_time = level_end;
     def._actual_begin_time = level_end;
   }
   }
 
 

+ 1 - 1
direct/src/interval/cMetaInterval.h

@@ -55,7 +55,7 @@ PUBLISHED:
   int add_ext_index(int ext_index, const string &name,
   int add_ext_index(int ext_index, const string &name,
                     double duration, bool open_ended,
                     double duration, bool open_ended,
                     double rel_time, RelativeStart rel_to);
                     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, 
   bool set_interval_start_time(const string &name, double rel_time, 
                                RelativeStart rel_to = RS_level_begin);
                                RelativeStart rel_to = RS_level_begin);