Beispiel #1
0
 public void CancelCurrent()
 {
     if (Nodes.Count > 0)
     {
         TimeNode last = Nodes.Last();
         if (last.Stop == null)
         {
             Nodes.Remove(last);
         }
     }
 }
Beispiel #2
0
 public void Stop(Time stop)
 {
     if (Nodes.Count > 0)
     {
         TimeNode last = Nodes.Last();
         if (last.Stop == null)
         {
             last.Stop = stop;
         }
     }
     Nodes.OrderBy(tn => tn.Start.MSeconds);
 }
Beispiel #3
0
 public TimeNode Join(TimeNode tn)
 {
     if (tn.Stop < Start || tn.Start > Stop)
     {
         return(null);
     }
     else
     {
         return new TimeNode {
                    Start = new Time(Math.Min(Start.MSeconds, tn.Start.MSeconds)),
                    Stop  = new Time(Math.Max(Stop.MSeconds, tn.Stop.MSeconds))
         }
     };
 }
Beispiel #4
0
        public TimeNode Start(Time start, string name = null)
        {
            TimeNode tn;

            if (name == null)
            {
                name = Name;
            }
            Stop(start);
            tn = new TimeNode {
                Name = name, Start = start
            };
            Nodes.Add(tn);
            return(tn);
        }
Beispiel #5
0
        public TimeNode Intersect(TimeNode tn)
        {
            if (tn.Stop == null || tn.Start == null || Start == null || Stop == null)
            {
                return(null);
            }
            if (tn.Stop <= Start || tn.Start >= Stop)
            {
                return(null);
            }
            else
            {
                return new TimeNode {
                           Start = new Time(Math.Max(Start.MSeconds, tn.Start.MSeconds)),
                           Stop  = new Time(Math.Min(Stop.MSeconds, tn.Stop.MSeconds))
                }
            };
        }

        #endregion
    }
Beispiel #6
0
        /// <summary>
        /// Resynchronize events with the periods synced with the video file.
        /// Imported projects or fake analysis projects create events assuming periods
        /// don't have gaps between them.
        /// After adding a file to the project and synchronizing the periods with the
        /// video file, all events must be offseted with the new start time of the period.
        ///
        /// Before sync:
        ///   Period 1: start=00:00:00 Period 2: start=00:30:00
        ///   evt1 00:10:00            evt2 00:32:00
        /// After sync:
        ///   Period 1: start=00:05:00 Period 2: start= 00:39:00
        ///   evt1 00:15:00            evt2 00:41:00
        /// </summary>
        /// <param name="oldPeriods">The periods baseline to sync against.</param>
        public void ResyncEvents(IList <Period> oldPeriods)
        {
            RangeObservableCollection <TimelineEvent> newTimeline = new RangeObservableCollection <TimelineEvent> ();

            if (oldPeriods.Count != Periods.Count)
            {
                throw new IndexOutOfRangeException(
                          "Periods count is different from the project's ones");
            }

            for (int i = 0; i < oldPeriods.Count; i++)
            {
                Period   oldPeriod = oldPeriods [i];
                TimeNode oldTN     = oldPeriod.PeriodNode;
                TimeNode newTN     = Periods [i].PeriodNode;
                Time     diff      = newTN.Start - oldTN.Start;

                /* Find the events in this period */
                var periodEvents = Timeline.Where(e =>
                                                  e.EventTime >= oldTN.Start &&
                                                  e.EventTime <= oldTN.Stop).ToList();

                /* Apply new offset and move the new timeline so that the next
                 * iteration for the following period does not use them anymore */
                periodEvents.ForEach(e => {
                    e.Move(diff);
                    newTimeline.Add(e);
                    Timeline.Remove(e);
                });
                foreach (TimeNode tn in oldPeriod.Nodes)
                {
                    tn.Move(diff);
                }
            }
            Timeline = newTimeline;
        }
Beispiel #7
0
 protected override void CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
 {
     if (Count != 0 && Duration != null)
     {
         if (VisibleRegion == null)
         {
             VisibleRegion = new TimeNode {
                 Start = new Time(0), Stop = new Time(Duration.MSeconds)
             };
         }
         else
         {
             if (VisibleRegion.Start > Duration)
             {
                 VisibleRegion.Start = new Time(0);
             }
             if (VisibleRegion.Stop > Duration)
             {
                 VisibleRegion.Stop = new Time(Duration.MSeconds);
             }
         }
     }
     base.CollectionChanged(sender, e);
 }