Animatroller.Framework.Import.BufferImporter.CreateTimeline C# (CSharp) Method

CreateTimeline() public method

public CreateTimeline ( int iterations ) : Timeline
iterations int
return Timeline
        public override Timeline CreateTimeline(int? iterations)
        {
            var timeline = InternalCreateTimeline(iterations);

            foreach (var kvp in this.mappedDevices)
            {
                var channelIdentity = kvp.Key;

                var effectData = effectDataPerChannel[channelIdentity];

                byte? lastValue = null;
                for (int i = 0; i < effectData.Length; i++)
                {
                    if (effectData[i] == lastValue)
                        continue;
                    lastValue = effectData[i];

                    var timelineEvent = new SimpleDimmerEvent(kvp.Value, (double)effectData[i] / 255);
                    timeline.AddMs(i * eventPeriodInMilliseconds, timelineEvent);
                }
            }

            foreach (var kvp in this.mappedRGBDevices)
            {
                var channelIdentity = kvp.Key;

                var effectDataR = effectDataPerChannel[channelIdentity.R];
                var effectDataG = effectDataPerChannel[channelIdentity.G];
                var effectDataB = effectDataPerChannel[channelIdentity.B];

                Color? lastValue = null;
                for (int i = 0; i < effectDataR.Length; i++)
                {
                    var color = Color.FromArgb(effectDataR[i], effectDataG[i], effectDataB[i]);
                    if (color == lastValue)
                        continue;
                    lastValue = color;

                    var timelineEvent = new SimpleColorEvent(kvp.Value, color);
                    timeline.AddMs(i * eventPeriodInMilliseconds, timelineEvent);

                    //log.Debug("Pos {0} set color {1} for device R:{2}/G:{3}/B:{4}", i, color, channelIdentity.R,
                    //    channelIdentity.G, channelIdentity.B);
                }
            }

            return timeline;
        }