Esempio n. 1
0
        /* union a segment into the set */
        public static void SkipSegmentsAdd(
            SkipSegmentsRec Segments,
            double dStart,
            double dDuration)
        {
#if DEBUG
            if (dDuration < 0)
            {
                Debug.Assert(false);
                throw new ArgumentException();
            }
#endif

            if (dDuration <= 0)
            {
                return;
            }

            IntervalRec Interval = new IntervalRec();

            Interval.Next = Segments.List;
            Segments.List = Interval;

            Interval.dStart    = dStart;
            Interval.dDuration = dDuration;

#if DEBUG
            ValidateSkipSegments(Segments);
#endif
        }
Esempio n. 2
0
        private static void ValidateSkipSegments(SkipSegmentsRec Segments)
        {
            IntervalRec Interval = Segments.List;

            while (Interval != null)
            {
                if (Interval.dDuration <= 0)
                {
                    // found expired interval
                    Debug.Assert(false);
                    throw new InvalidOperationException();
                }
                Interval = Interval.Next;
            }
        }
Esempio n. 3
0
        /* increment the position counter.  returns True if current cycle should */
        /* be skipped (according to the segment list) */
        public static bool SkipSegmentUpdateOneCycle(
            SkipSegmentsRec Segments,
            double dEnvelopeTicks,
            double dDurationTicks)
        {
            bool CurrentlyInSegment = false;

#if DEBUG
            ValidateSkipSegments(Segments);
#endif

            IntervalRec IntervalTrailer = null;
            IntervalRec Interval        = Segments.List;
            while (Interval != null)
            {
                /* decrement current intervals to expiration */
                if (Interval.dStart <= Segments.dElapsedEnvelopeTicks)
                {
                    CurrentlyInSegment = true;

                    Interval.dDuration -= dDurationTicks;
                    if (Interval.dDuration <= 0)
                    {
                        if (IntervalTrailer == null)
                        {
                            Segments.List = Interval.Next;
                        }
                        else
                        {
                            IntervalTrailer.Next = Interval.Next;
                        }
                        Interval = Interval.Next;

                        continue;
                    }
                }

                IntervalTrailer = Interval;
                Interval        = Interval.Next;
            }

            Segments.dElapsedEnvelopeTicks += dEnvelopeTicks;

#if DEBUG
            ValidateSkipSegments(Segments);
#endif
            return(CurrentlyInSegment);
        }
Esempio n. 4
0
        /* create a new skip segments list */
        public static SkipSegmentsRec NewSkipSegments()
        {
            SkipSegmentsRec Segments = new SkipSegmentsRec();

            return(Segments);
        }