Animatroller.Framework.Controller.CueList.AdvanceCue C# (CSharp) Method

AdvanceCue() private method

private AdvanceCue ( ) : Cue
return Animatroller.Framework.LogicalDevice.Cue
        private Cue AdvanceCue()
        {
            this.currentCuePos += direction;

            if (this.currentCuePos < 0)
            {
                if (this.cues.Count == 1)
                    // Nothing to go to
                    return null;

                if (!this.iterationsLeft.HasValue || this.iterationsLeft.GetValueOrDefault() > 0)
                {
                    // Start new
                    this.currentCuePos = 1;
                    this.direction = 1;
                    this.cueListTime.Restart();
                }
                else
                    return null;
            }

            if (this.currentCuePos >= this.cues.Count)
            {
                if (this.cues.Count == 1)
                    // Nothing to go to
                    return null;

                // Check for bounce/iteration/loop
                if (this.bounce)
                {
                    this.direction = -1;
                    this.currentCuePos = this.cues.Count - 2;
                }
                else
                {
                    if (this.iterationsLeft.HasValue)
                    {
                        if (this.iterationsLeft.GetValueOrDefault() <= 1)
                            return null;
                    }

                    this.currentCuePos = 0;
                    this.cueListTime.Restart();
                }
            }

            var cue = this.cues[this.currentCuePos];

            return cue;
        }