Пример #1
0
        private void SetChannelEvents(IEnumerable <Channel> seqChannels, IEnumerable channelsInfoNode)
        {
            var row     = 0;
            var twinkle = new Twinkle();

            foreach (
                var firstNode in
                from x in
                seqChannels.Select(c => c.Name).Select(
                    name => (from XmlNode ch in channelsInfoNode where null != ch.Attributes && ch.Attributes["name"].Value == name select ch))
                select null != x ? x.First() : null
                into firstNode
                let attributes = firstNode.Attributes
                                 where attributes != null
                                 where null != firstNode && null != attributes
                                 let channelColor = int.Parse(attributes["color"].Value)
                                                    select firstNode)
            {
                // ReSharper disable once PossibleNullReferenceException
                var isDMX        = firstNode.Attributes["deviceType"].Value.Equals("DMX");
                var channelColor = int.Parse(firstNode.Attributes["color"].Value);
                foreach (XmlNode y in firstNode.ChildNodes)
                {
                    if (null == y.Attributes)
                    {
                        continue;
                    }

                    var effectType = y.Attributes["type"].Value.ToLower();

                    var intensity = GetIntAttributeOrDefault(y, "intensity", 0).ToValue();

                    var eventStart = GetIntAttributeOrDefault(y, "startCentisecond", 0);
                    var eventEnd   = GetIntAttributeOrDefault(y, "endCentisecond", 0);
                    var eventCount = eventEnd - eventStart;

                    var intensityStart      = GetIntAttributeOrDefault(y, "startIntensity", 0).ToValue();
                    var intensityEnd        = GetIntAttributeOrDefault(y, "endIntensity", 0).ToValue();
                    var intensityDifference = intensityEnd - intensityStart;

                    if (intensity == 0 && intensityStart == 0 && intensityEnd == 0)
                    {
                        intensity = Utils.Cell8BitMax;
                    }

                    switch (effectType)
                    {
                    case "intensity":
                        if (intensity > 0)
                        {
                            for (var i = 0; i < eventCount; i++)
                            {
                                SetChannelEvents(isDMX, row, eventStart + i, channelColor, intensity);
                            }
                        }
                        else
                        {
                            for (var i = 0; i < eventCount; i++)
                            {
                                var currentIntensity = (int)((double)i / eventCount * intensityDifference + intensityStart);
                                SetChannelEvents(isDMX, row, eventStart + i, channelColor, currentIntensity);
                            }
                        }
                        break;

                    case "twinkle":
                        twinkle.Set();
                        if (intensity > 0)
                        {
                            for (var i = 0; i < eventCount; i++)
                            {
                                SetChannelEvents(isDMX, row, eventStart + i, channelColor, intensity * twinkle.State);
                                twinkle.Update();
                            }
                        }
                        else
                        {
                            for (var i = 0; i < eventCount; i++)
                            {
                                var currentIntensity = (int)(((double)i / eventCount * intensityDifference + intensityStart) * twinkle.State);
                                SetChannelEvents(isDMX, row, eventStart + i, channelColor, currentIntensity);
                                twinkle.Update();
                            }
                        }
                        break;

                    case "shimmer":
                        var shimmerState = eventStart & 0x01;
                        if (intensity > 0)
                        {
                            for (var i = 0; i < eventCount; i++)
                            {
                                var currentIntensity = intensity * shimmerState;
                                SetChannelEvents(isDMX, row, eventStart + i, channelColor, currentIntensity);
                                shimmerState = 1 - shimmerState;
                            }
                        }
                        else
                        {
                            for (var i = 0; i < eventCount; i++)
                            {
                                var currentIntensity = (int)((((double)i / eventCount) * intensityDifference + intensityStart) * shimmerState);
                                SetChannelEvents(isDMX, row, eventStart + i, channelColor, currentIntensity);
                                shimmerState = 1 - shimmerState;
                            }
                        }
                        break;

                    default:
                        string.Format("Unknow effect type {0} - skipped", effectType).CrashLog();
                        break;
                    }
                }
                row += isDMX ? 3 : 1;
            }
        }
Пример #2
0
        private void SetChannelEvents(IEnumerable<Channel> seqChannels, IEnumerable channelsInfoNode)
        {
            var row = 0;
            var twinkle = new Twinkle();

            foreach (
                var firstNode in
                    from x in
                        seqChannels.Select(c => c.Name).Select(
                            name => (from XmlNode ch in channelsInfoNode where null != ch.Attributes && ch.Attributes["name"].Value == name select ch))
                    select null != x ? x.First() : null
                    into firstNode
                    let attributes = firstNode.Attributes
                    where attributes != null
                    where null != firstNode && null != attributes
                    let channelColor = int.Parse(attributes["color"].Value)
                    select firstNode) {
                // ReSharper disable once PossibleNullReferenceException
                var isDMX = firstNode.Attributes["deviceType"].Value.Equals("DMX");
                var channelColor = int.Parse(firstNode.Attributes["color"].Value);
                foreach (XmlNode y in firstNode.ChildNodes) {
                    if (null == y.Attributes) {
                        continue;
                    }

                    var effectType = y.Attributes["type"].Value.ToLower();

                    var intensity = GetIntAttributeOrDefault(y, "intensity", 0).ToValue();

                    var eventStart = GetIntAttributeOrDefault(y, "startCentisecond", 0);
                    var eventEnd = GetIntAttributeOrDefault(y, "endCentisecond", 0);
                    var eventCount = eventEnd - eventStart;

                    var intensityStart = GetIntAttributeOrDefault(y, "startIntensity", 0).ToValue();
                    var intensityEnd = GetIntAttributeOrDefault(y, "endIntensity", 0).ToValue();
                    var intensityDifference = intensityEnd - intensityStart;

                    if (intensity == 0 && intensityStart == 0 && intensityEnd == 0) {
                        intensity = Utils.Cell8BitMax;
                    }

                    switch (effectType) {
                        case "intensity":
                            if (intensity > 0) {
                                for (var i = 0; i < eventCount; i++) {
                                    SetChannelEvents(isDMX, row, eventStart + i, channelColor, intensity);
                                }
                            }
                            else {
                                for (var i = 0; i < eventCount; i++) {
                                    var currentIntensity = (int) ((double) i / eventCount * intensityDifference + intensityStart);
                                    SetChannelEvents(isDMX, row, eventStart + i, channelColor, currentIntensity);
                                }
                            }
                            break;
                        case "twinkle":
                            twinkle.Set();
                            if (intensity > 0) {
                                for (var i = 0; i < eventCount; i++) {
                                    SetChannelEvents(isDMX, row, eventStart + i, channelColor, intensity * twinkle.State);
                                    twinkle.Update();
                                }
                            }
                            else {
                                for (var i = 0; i < eventCount; i++) {
                                    var currentIntensity = (int)(((double)i / eventCount * intensityDifference + intensityStart) * twinkle.State);
                                    SetChannelEvents(isDMX, row, eventStart + i, channelColor, currentIntensity);
                                    twinkle.Update();
                                }
                            }
                            break;
                        case "shimmer":
                            var shimmerState = eventStart & 0x01;
                            if (intensity > 0) {
                                for (var i = 0; i < eventCount; i++) {
                                    var currentIntensity = intensity * shimmerState;
                                    SetChannelEvents(isDMX, row, eventStart + i, channelColor, currentIntensity);
                                    shimmerState = 1 - shimmerState;
                                }
                            }
                            else {
                                for (var i = 0; i < eventCount; i++) {
                                    var currentIntensity = (int)((((double)i / eventCount) * intensityDifference + intensityStart) * shimmerState);
                                    SetChannelEvents(isDMX, row, eventStart + i, channelColor, currentIntensity);
                                    shimmerState = 1 - shimmerState;
                                }
                            }
                            break;
                        default:
                            string.Format("Unknow effect type {0} - skipped", effectType).CrashLog();
                            break;
                    }
                }
                row += isDMX ? 3 : 1;
            }
        }