Example #1
0
        /// <summary>
        /// Gets all buckets before a duration, cutting a bucket in half if needed.
        /// Will return empty list if at start. If fraction has specified then get half bucket if durationAt
        /// intersect with exist bucket
        /// </summary>
        /// <param name="durationAt">The duration at.</param>
        /// <returns></returns>
        private PersonalContourBucket[] GetBucketsBeforeDuration(long durationAt)
        {
            List <PersonalContourBucket> retVal = new List <PersonalContourBucket>();
            long currentDuration = 0;
            PersonalContourBucket personalBucket = null;

            if (durationAt != 0)
            {
                foreach (AbstractContourBucket bucket in base.ContourBuckets)
                {
                    personalBucket = bucket as PersonalContourBucket;
                    if (personalBucket != null)
                    {
                        currentDuration = personalBucket.ElapsedDuration;
                        if (currentDuration >= durationAt)
                        {
                            retVal.Add(personalBucket);
                            break;
                        }
                        retVal.Add(personalBucket);
                    }
                }
            }
            return(retVal.ToArray());
        }
Example #2
0
        /// <summary>
        /// Set the duration of the personal contour. This implies either truncating the bucket array or changing the last bucket
        /// to accommodate the new duration. Note that only the last bucket will be modified.  The number of buckets will never increase.
        /// Since the buckets themselves are immutable, the last element will most likely be replaced.
        /// </summary>
        /// <param name="newDuration">The new duration.</param>
        /// <param name="actualDuration">The actual duration.</param>
        /// <returns></returns>
        public override AbstractContour AdjustDuration(long newDuration, long actualDuration)
        {
            PersonalContour newContour = new PersonalContour();

            foreach (AbstractContourBucket bucket in base.ContourBuckets)
            {
                PersonalContourBucket personalBucket = (PersonalContourBucket)bucket;
                newContour.ContourBuckets.Add(personalBucket);
                newDuration -= personalBucket.Duration;
                if (newDuration <= 0)
                {
                    // adding a negative value
                    personalBucket.AdjustDuration(newDuration);
                    newDuration = 0;
                    //AbstractContour result = newContour.makePacked(); // pack so as to get rid of any trailing empty buckets
                }
            }
            // extend last bucket to account for duration
            ((PersonalContourBucket)newContour.ContourBuckets[newContour.ContourBuckets.Count - 1]).AdjustDuration(newDuration);

            this.ContourBuckets.Clear();
            this.ContourBuckets.AddRange(newContour.ContourBuckets);
            return(this);
        }