Exemple #1
0
        private List <ElementNode> GetNodesToRenderOn()
        {
            IEnumerable <ElementNode> renderNodes = null;

            if (DepthOfEffect == 0)
            {
                renderNodes = TargetNodes.SelectMany(x => x.GetLeafEnumerator()).ToList();
            }
            else
            {
                renderNodes = TargetNodes;
                for (int i = 0; i < DepthOfEffect; i++)
                {
                    renderNodes = renderNodes.SelectMany(x => x.Children);
                }
            }

            // If the given DepthOfEffect results in no nodes (because it goes "too deep" and misses all nodes),
            // then we'll default to the LeafElements, which will at least return 1 element (the TargetNode)
            if (!renderNodes.Any())
            {
                renderNodes = TargetNodes.SelectMany(x => x.GetLeafEnumerator());
            }

            return(renderNodes.ToList());
        }
Exemple #2
0
        //Validate that the we are using valid colors and set appropriate defaults if not.
        private void CheckForInvalidColorData()
        {
            // check for sane default colors when first rendering it
            HashSet <Color> validColors = new HashSet <Color>();

            validColors.AddRange(TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true)));

            //Validate Color 1
            if (validColors.Any() &&
                (!validColors.Contains(_data.Color1.ToArgb()) || !_data.ColorGradient1.GetColorsInGradient().IsSubsetOf(validColors)))
            {
                Color1         = validColors.First();
                ColorGradient1 = new ColorGradient(validColors.First());
            }

            //Validate color 2
            if (validColors.Any() &&
                (!validColors.Contains(_data.Color2.ToArgb()) || !_data.ColorGradient2.GetColorsInGradient().IsSubsetOf(validColors)))
            {
                if (validColors.Count > 1)
                {
                    Color2         = validColors.ElementAt(1);
                    ColorGradient2 = new ColorGradient(validColors.ElementAt(1));
                }
                else
                {
                    Color2         = validColors.First();
                    ColorGradient2 = new ColorGradient(validColors.First());
                }
            }
        }
Exemple #3
0
        private IEnumerable <IElementNode> GetNodesToRenderOn()
        {
            IEnumerable <IElementNode> renderNodes = TargetNodes;

            renderNodes = TargetNodes.SelectMany(x => x.GetLeafEnumerator());

            return(renderNodes);
        }
 private void CalculateAffectedElements()
 {
     if (TargetNodes == null || TargetNodes.Length == 0)
     {
         EffectedElementIds = Enumerable.Empty <Guid>();
     }
     EffectedElementIds =
         TargetNodes.SelectMany(y => y.GetElementEnumerator()).Select(z => z.Id);
 }
        protected override void _PreRender()
        {
            _effectIntents = new EffectIntents();
            _r             = new Random();

            foreach (Element element in TargetNodes.SelectMany(x => x))
            {
                _RenderCandleOnElement(element);
            }
        }
Exemple #6
0
        /// <summary>
        /// Gets the list of valid colors this effect can use and sets the hasDiscreteColors flag if any of it's targeted elements are discrete and have a restricted list.
        /// </summary>
        /// <returns></returns>
        protected HashSet <Color> GetValidColors()
        {
            HashSet <Color> validColors = new HashSet <Color>();

            validColors.AddRange(TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true)));
            if (validColors.Any())
            {
                HasDiscreteColors = true;
            }
            return(validColors);
        }
Exemple #7
0
        //Validate that the we are using valid colors and set appropriate defaults if not.
        private void CheckForInvalidColorData()
        {
            HashSet <Color> validColors = new HashSet <Color>();

            validColors.AddRange(TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true)));
            if (validColors.Any() && !validColors.Contains(_data.color.ToArgb()))
            {
                //Our color is not valid for any elements we have.
                //Set a default color
                Color = validColors.First();
            }
        }
Exemple #8
0
        private void CheckForInvalidColorData()
        {
            HashSet <Color> validColors = new HashSet <Color>();

            validColors.AddRange(TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true)));
            if (validColors.Any() && !_data.ColorGradient.GetColorsInGradient().IsSubsetOf(validColors))
            {
                //Our color is not valid for any elements we have.
                //Try to set a default color gradient from our available colors
                _data.ColorGradient = new ColorGradient(validColors.First());
            }
        }
Exemple #9
0
        private void ConfigureVirtualBuffer()
        {
            ElementLocations = TargetNodes.SelectMany(x => x.GetLeafEnumerator()).Select(x => new ElementLocation(x)).ToList();
            var xMax = ElementLocations.Max(p => p.X);
            var xMin = ElementLocations.Min(p => p.X);
            var yMax = ElementLocations.Max(p => p.Y);
            var yMin = ElementLocations.Min(p => p.Y);

            _bufferWi       = (yMax - yMin) + 1;
            _bufferHt       = (xMax - xMin) + 1;
            _bufferWiOffset = yMin;
            _bufferHtOffset = xMin;
        }
Exemple #10
0
        //Validate that the we are using valid colors and set appropriate defaults if not.
        private void CheckForInvalidColorData()
        {
            HashSet <Color> validColors = new HashSet <Color>();

            validColors.AddRange(TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true)));

            if (validColors.Any() &&
                (!validColors.Contains(_data.StaticColor) || !_data.ColorGradient.GetColorsInGradient().IsSubsetOf(validColors)))                 //Discrete colors specified
            {
                _data.ColorGradient = new ColorGradient(validColors.DefaultIfEmpty(Color.White).First());
                _data.StaticColor   = validColors.First();
            }
        }
Exemple #11
0
        protected override void _PreRender(CancellationTokenSource cancellationToken = null)
        {
            _effectIntents = new EffectIntents();
            _r             = new Random();

            var nodes = TargetNodes.SelectMany(x => x.GetLeafEnumerator());

            var elementGroup = nodes.Select((x, index) => new { x, index })
                               .GroupBy(x => x.index / GroupLevel, y => y.x);

            foreach (IGrouping <int, ElementNode> block in elementGroup)
            {
                _RenderCandleOnElements(block.GetElements().ToList());
            }
        }
Exemple #12
0
        protected override void _PreRender(CancellationTokenSource cancellationToken = null)
        {
            _effectIntents = new EffectIntents();
            _r             = new Random();

            var nodes = TargetNodes.SelectMany(x => x.GetLeafEnumerator());

            var elementGroup = nodes.Select((x, index) => new { x, index })
                               .GroupBy(x => x.index / GroupLevel, y => y.x);

            foreach (IGrouping <int, IElementNode> block in elementGroup)
            {
                _RenderCandleOnElements(block.ToList());
            }

            //_effectIntents = IntentBuilder.ConvertToStaticArrayIntents(_effectIntents, TimeSpan, IsDiscrete());
        }
        protected override void _PreRender(CancellationTokenSource cancellationToken = null)
        {
            _effectIntents = new EffectIntents();
            _r             = new Random();

            foreach (Element element in TargetNodes.SelectMany(x => x))
            {
                if (cancellationToken != null && cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                if (element != null)
                {
                    _RenderCandleOnElement(element);
                }
            }
        }
Exemple #14
0
        // renders the given node to the internal ElementData dictionary. If the given node is
        // not a element, will recursively descend until we render its elements.
        private void RenderNodes()
        {
            var renderNodes = TargetNodes.SelectMany(x => x.GetNodeEnumerator());

            if (LipSyncMode == LipSyncMode.MarkCollection)
            {
                SetupMarks();
            }

            PhonemeType phoneme = _data.StaticPhoneme;

            if (MappingType == MappingType.Map)
            {
                if (!_library.Library.ContainsKey(_data.PhonemeMapping))
                {
                    _data.PhonemeMapping = _library.DefaultMappingName;
                }

                LipSyncMapData mapData;
                if (_library.Library.TryGetValue(_data.PhonemeMapping, out mapData))
                {
                    if (mapData.IsMatrix)
                    {
                        RenderMapMatrix(mapData, phoneme);
                    }
                    else
                    {
                        //We should never get here becasue we no longer have string maps
                        Logging.Error("Trying to render as deprecated string maps!");
                        foreach (var element in renderNodes)
                        {
                            RenderMapElements(mapData, element, phoneme);
                        }
                    }
                }
            }
            else
            {
                foreach (var element in renderNodes)
                {
                    RenderPropertyMapElements(element, phoneme);
                }
            }
        }
Exemple #15
0
        private IEnumerable <ElementNode> FindLeafParents()
        {
            var nodes           = new List <ElementNode>();
            var nonLeafElements = new List <ElementNode>();

            if (TargetNodes.FirstOrDefault() != null)
            {
                nonLeafElements = TargetNodes.SelectMany(x => x.GetNonLeafEnumerator()).ToList();
                foreach (var elementNode in TargetNodes)
                {
                    foreach (var leafNode in elementNode.GetLeafEnumerator())
                    {
                        nodes.AddRange(leafNode.Parents);
                    }
                }
            }
            //Some nodes can have multiple node parents with odd groupings so this fancy linq query makes sure that the parent
            //node is part of the Target nodes lineage.
            return(nodes.Distinct().Intersect(nonLeafElements));
        }
Exemple #16
0
        //Validate that the we are using valid colors and set appropriate defaults if not.
        //we only need to check against 1 color variable,
        //it should be checked at a later time than what this is doing currently
        private void CheckForInvalidColorData()
        {
            // check for sane default colors when first rendering it
            var validColors = new HashSet <Color>();

            validColors.AddRange(TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true)));

            if (validColors.Any())
            {
                bool changed = false;
                foreach (GradientLevelPair t in Colors)
                {
                    if (!t.ColorGradient.GetColorsInGradient().IsSubsetOf(validColors))
                    {
                        t.ColorGradient = new ColorGradient(validColors.First());
                        changed         = true;
                    }
                }
                if (changed)
                {
                    OnPropertyChanged("Colors");
                }
            }
        }
Exemple #17
0
        // renders the given node to the internal ElementData dictionary. If the given node is
        // not a element, will recursively descend until we render its elements.
        private void RenderNode(ElementNode node)
        {
            EffectIntents      result;
            LipSyncMapData     mapData     = null;
            List <ElementNode> renderNodes = TargetNodes.SelectMany(x => x.GetNodeEnumerator()).ToList();

            if (_data.PhonemeMapping != null)
            {
                if (!_library.Library.ContainsKey(_data.PhonemeMapping))
                {
                    _data.PhonemeMapping = _library.DefaultMappingName;
                }

                PhonemeType phoneme = _data.StaticPhoneme;
                if (_library.Library.TryGetValue(_data.PhonemeMapping, out mapData))
                {
                    renderNodes.ForEach(delegate(ElementNode element)
                    {
                        LipSyncMapItem item = mapData.FindMapItem(element.Name);
                        if (item != null)
                        {
                            if (mapData.PhonemeState(element.Name, _data.StaticPhoneme.ToString(), item))
                            {
                                var level            = new SetLevel.SetLevel();
                                level.TargetNodes    = new ElementNode[] { element };
                                level.Color          = mapData.ConfiguredColor(element.Name, phoneme, item);
                                level.IntensityLevel = mapData.ConfiguredIntensity(element.Name, phoneme, item);
                                level.TimeSpan       = TimeSpan;
                                result = level.Render();
                                _elementData.Add(result);
                            }
                        }
                    });
                }
            }
        }
Exemple #18
0
        private void RenderBurst(CancellationTokenSource tokenSource, WipeDirection direction)
        {
            switch (direction)
            {
            case WipeDirection.In:
            case WipeDirection.Out:
                break;

            default:
                throw new InvalidOperationException("the RenderBurst method should only be called for Wipe Directions In and Out");
                break;
            }
            var burstNodes = TargetNodes.SelectMany(x => x.GetLeafEnumerator())
                             .Select(s =>
            {
                var prop = s.Properties.Get(LocationDescriptor._typeId);
                if (prop != null)
                {
                    return(new Tuple <ElementNode, int, int, int>(s, ((LocationData)prop.ModuleData).X, ((LocationData)prop.ModuleData).Y, ((LocationData)prop.ModuleData).Z));
                }
                return(new Tuple <ElementNode, int, int, int>(null, -1, -1, -1));
                //return null
            })
                             .Where(s => s.Item2 > 0)                                                                               // Ignore the pseudo null values
                             .ToList();

            if (!burstNodes.Any())
            {
                return;
            }
            var maxX = burstNodes.Max(m => m.Item2);
            var maxY = burstNodes.Max(m => m.Item3);

            var minX = burstNodes.Min(m => m.Item2);
            var minY = burstNodes.Min(m => m.Item3);

            var Steps = (int)(Math.Max(maxX - minX, maxY - minY) / 2);

            List <Tuple <int, ElementNode[]> > groups = new List <Tuple <int, ElementNode[]> >();

            for (int i = 0; i < Steps; i++)
            {
                List <ElementNode> elements = new List <ElementNode>();

                var xNodes = burstNodes.Where(x =>
                                              (x.Item2 == minX + i || x.Item2 == maxX - i)
                                              )
                             .Select(s => s.Item1).ToList();

                var yNodes = burstNodes.Where(x =>
                                              (
                                                  x.Item3 == minY + i ||
                                                  x.Item3 == maxY - i)
                                              )
                             .Select(s => s.Item1).ToList();
                yNodes.RemoveAll(s =>
                {
                    var prop = s.Properties.Get(LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).X < minX + i || ((LocationData)prop.ModuleData).X > maxX - i);
                    }
                    return(false);
                });
                xNodes.RemoveAll(s =>
                {
                    var prop = s.Properties.Get(LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).Y < minY + i || ((LocationData)prop.ModuleData).Y > maxY - i);
                    }
                    return(false);
                });
                elements.AddRange(yNodes);
                elements.AddRange(xNodes);

                groups.Add(new Tuple <int, ElementNode[]>(i, elements.ToArray()));
            }
            List <ElementNode[]> renderNodes = new List <ElementNode[]>();

            switch (direction)
            {
            case WipeDirection.In:
                renderNodes = groups.OrderBy(o => o.Item1).Select(s => s.Item2).ToList();
                break;

            case WipeDirection.Out:
                renderNodes = groups.OrderByDescending(o => o.Item1).Select(s => s.Item2).ToList();
                break;
            }

            //var pulse = new Pulse.Pulse();
            if (renderNodes != null && renderNodes.Any())
            {
                TimeSpan effectTime = TimeSpan.Zero;
                if (WipeByCount)
                {
                    int      count        = 0;
                    double   pulseSegment = TimeSpan.Ticks / (double)PassCount * (PulsePercent / 100);
                    TimeSpan intervalTime = TimeSpan.FromTicks((long)((TimeSpan.Ticks - pulseSegment) / (renderNodes.Count() * PassCount)));
                    TimeSpan segmentPulse = TimeSpan.FromTicks((long)pulseSegment);

                    while (count < PassCount)
                    {
                        foreach (var item in renderNodes)
                        {
                            if (tokenSource != null && tokenSource.IsCancellationRequested)
                            {
                                return;
                            }
                            EffectIntents result;

                            foreach (ElementNode element in item)
                            {
                                if (tokenSource != null && tokenSource.IsCancellationRequested)
                                {
                                    return;
                                }
                                if (element != null)
                                {
                                    //pulse.TimeSpan = segmentPulse;
                                    //pulse.ColorGradient = _data.ColorGradient;
                                    //pulse.LevelCurve = _data.Curve;
                                    //pulse.TargetNodes = new ElementNode[] { element };
                                    //result = pulse.Render();
                                    result = PulseRenderer.RenderNode(element, _data.Curve, _data.ColorGradient, segmentPulse, HasDiscreteColors);
                                    result.OffsetAllCommandsByTime(effectTime);
                                    bool discreteElement = HasDiscreteColors && ColorModule.isElementNodeDiscreteColored(element);
                                    _elementData.Add(IntentBuilder.ConvertToStaticArrayIntents(result, TimeSpan, discreteElement));
                                }
                            }
                            effectTime += intervalTime;
                        }
                        count++;
                    }
                }
                else
                {
                    double intervals    = (double)PulseTime / (double)renderNodes.Count();
                    var    intervalTime = TimeSpan.FromMilliseconds(intervals);
                    // the calculation above blows up render time/memory as count goes up, try this..
                    // also fails if intervals is less than half a ms and intervalTime then gets 0
                    intervalTime = TimeSpan.FromMilliseconds(Math.Max(intervalTime.TotalMilliseconds, 5));
                    TimeSpan segmentPulse = TimeSpan.FromMilliseconds(PulseTime);
                    while (effectTime < TimeSpan)
                    {
                        foreach (var item in renderNodes)
                        {
                            EffectIntents result;

                            if (tokenSource != null && tokenSource.IsCancellationRequested)
                            {
                                return;
                            }
                            foreach (ElementNode element in item)
                            {
                                if (element != null)
                                {
                                    if (tokenSource != null && tokenSource.IsCancellationRequested)
                                    {
                                        return;
                                    }

                                    //pulse.TimeSpan = segmentPulse;
                                    //pulse.ColorGradient = _data.ColorGradient;
                                    //pulse.LevelCurve = _data.Curve;
                                    //pulse.TargetNodes = new ElementNode[] { element };
                                    //result = pulse.Render();
                                    result = PulseRenderer.RenderNode(element, _data.Curve, _data.ColorGradient, segmentPulse, HasDiscreteColors);
                                    result.OffsetAllCommandsByTime(effectTime);
                                    bool discreteElement = HasDiscreteColors && ColorModule.isElementNodeDiscreteColored(element);
                                    _elementData.Add(IntentBuilder.ConvertToStaticArrayIntents(result, TimeSpan, discreteElement));
                                }
                            }
                            effectTime += intervalTime;
                            if (effectTime >= TimeSpan)
                            {
                                return;
                            }
                        }
                    }
                }
            }
        }
Exemple #19
0
 private void CalculateAffectedElements()
 {
     EffectedElementIds =
         TargetNodes.SelectMany(y => y.GetElementEnumerator()).Select(z => z.Id);
 }
Exemple #20
0
        // renders the given node to the internal ElementData dictionary. If the given node is
        // not a element, will recursively descend until we render its elements.
        private void RenderNodes()
        {
            EffectIntents      result;
            LipSyncMapData     mapData     = null;
            List <ElementNode> renderNodes = TargetNodes.SelectMany(x => x.GetNodeEnumerator()).ToList();

            if (LipSyncMode == LipSyncMode.MarkCollection)
            {
                SetupMarks();
            }

            if (_data.PhonemeMapping != null)
            {
                if (!_library.Library.ContainsKey(_data.PhonemeMapping))
                {
                    _data.PhonemeMapping = _library.DefaultMappingName;
                }

                PhonemeType phoneme = _data.StaticPhoneme;
                if (_library.Library.TryGetValue(_data.PhonemeMapping, out mapData))
                {
                    if (mapData.IsMatrix)
                    {
                        SetupPictureEffect();
                        if (LipSyncMode == LipSyncMode.MarkCollection)
                        {
                            foreach (var mark in _marks)
                            {
                                var file = mapData.PictureFileName(mark.Text.ToUpper());
                                _thePic.Image    = LoadImage(file);
                                _thePic.TimeSpan = mark.Duration;
                                _thePic.MarkDirty();
                                result = _thePic.Render();
                                result.OffsetAllCommandsByTime(mark.StartTime - StartTime);
                                _elementData.Add(result);
                                //}
                            }
                        }
                        else
                        {
                            var file = mapData.PictureFileName(phoneme);
                            if (File.Exists(file))
                            {
                                _thePic.Image = LoadImage(file);
                                result        = _thePic.Render();
                                _elementData.Add(result);
                            }
                        }

                        if (null != _thePic)
                        {
                            result = _thePic.Render();
                            _elementData.Add(result);
                        }
                    }
                    else
                    {
                        renderNodes.ForEach(delegate(ElementNode element)
                        {
                            LipSyncMapItem item = mapData.FindMapItem(element.Name);
                            if (item != null)
                            {
                                if (LipSyncMode == LipSyncMode.MarkCollection && _marks != null)
                                {
                                    foreach (var mark in _marks)
                                    {
                                        if (mapData.PhonemeState(element.Name, mark.Text.ToUpper(), item))
                                        {
                                            var colorVal = mapData.ConfiguredColorAndIntensity(element.Name, mark.Text.ToUpper(), item);
                                            result       = CreateIntentsForPhoneme(element, colorVal.Item1, colorVal.Item2, mark.Duration);
                                            result.OffsetAllCommandsByTime(mark.StartTime - StartTime);
                                            _elementData.Add(result);
                                        }
                                    }
                                }
                                else
                                {
                                    if (mapData.PhonemeState(element.Name, phoneme.ToString(), item))
                                    {
                                        var colorVal = mapData.ConfiguredColorAndIntensity(element.Name, phoneme.ToString(), item);
                                        result       = CreateIntentsForPhoneme(element, colorVal.Item1, colorVal.Item2, TimeSpan);
                                        _elementData.Add(result);
                                    }
                                }
                            }
                        });

                        TearDownPictureEffect();
                    }
                }
            }
        }
Exemple #21
0
        protected override void _PreRender(CancellationTokenSource tokenSource = null)
        {
            _elementData = new EffectIntents();

            IEnumerable <IGrouping <int, ElementNode> > renderNodes = null;

            var enumerator = TargetNodes.SelectMany(x => x.GetLeafEnumerator());
            var b          = enumerator;

            switch (_data.Direction)
            {
            case WipeDirection.Up:
                renderNodes = TargetNodes
                              .SelectMany(x => x.GetLeafEnumerator())
                              .OrderByDescending(x => {
                    var prop = x.Properties.Get(VixenModules.Property.Location.LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).Y);
                    }
                    else
                    {
                        return(1);
                    }
                })
                              .ThenBy(x => {
                    var prop = x.Properties.Get(VixenModules.Property.Location.LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).X);
                    }
                    else
                    {
                        return(1);
                    }
                })
                              .GroupBy(x => {
                    var prop = x.Properties.Get(VixenModules.Property.Location.LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).Y);
                    }
                    else
                    {
                        return(1);
                    }
                })
                              .Distinct();
                break;

            case WipeDirection.Down:

                renderNodes = TargetNodes.SelectMany(x => x.GetLeafEnumerator())
                              .OrderBy(x => {
                    var prop = x.Properties.Get(VixenModules.Property.Location.LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).Y);
                    }
                    else
                    {
                        return(1);
                    }
                })
                              .ThenBy(x => {
                    var prop = x.Properties.Get(VixenModules.Property.Location.LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).X);
                    }
                    else
                    {
                        return(1);
                    }
                })
                              .GroupBy(x => {
                    var prop = x.Properties.Get(VixenModules.Property.Location.LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).Y);
                    }
                    else
                    {
                        return(1);
                    }
                })
                              .Distinct();
                break;

            case WipeDirection.Right:

                renderNodes = TargetNodes.SelectMany(x => x.GetLeafEnumerator())
                              .OrderBy(x => {
                    var prop = x.Properties.Get(VixenModules.Property.Location.LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).X);
                    }
                    else
                    {
                        return(1);
                    }
                })
                              .ThenBy(x => {
                    var prop = x.Properties.Get(VixenModules.Property.Location.LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).Y);
                    }
                    else
                    {
                        return(1);
                    }
                })
                              .GroupBy(x => {
                    var prop = x.Properties.Get(VixenModules.Property.Location.LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).X);
                    }
                    else
                    {
                        return(1);
                    }
                })
                              .Distinct();
                break;

            case WipeDirection.Left:

                renderNodes = TargetNodes.SelectMany(x => x.GetLeafEnumerator())
                              .OrderByDescending(x => {
                    var prop = x.Properties.Get(VixenModules.Property.Location.LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).X);
                    }
                    return(1);
                })
                              .ThenBy(x => {
                    var prop = x.Properties.Get(VixenModules.Property.Location.LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).Y);
                    }
                    return(1);
                })
                              .GroupBy(x => {
                    var prop = x.Properties.Get(VixenModules.Property.Location.LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).X);
                    }
                    return(1);
                })

                              .Distinct();
                break;

            default:
                break;
            }

            if (renderNodes != null && renderNodes.Count() > 0)
            {
                TimeSpan effectTime = TimeSpan.Zero;
                if (WipeByCount)
                {
                    int      count        = 0;
                    double   pulseSegment = (TimeSpan.TotalMilliseconds / PassCount) * (PulsePercent / 100);
                    TimeSpan intervalTime = TimeSpan.FromMilliseconds((TimeSpan.TotalMilliseconds - pulseSegment) / (renderNodes.Count() * PassCount));
                    TimeSpan segmentPulse = TimeSpan.FromMilliseconds(pulseSegment);

                    while (count < PassCount)
                    {
                        foreach (var item in renderNodes)
                        {
                            if (tokenSource != null && tokenSource.IsCancellationRequested)
                            {
                                return;
                            }
                            EffectIntents result;

                            foreach (ElementNode element in item)
                            {
                                if (tokenSource != null && tokenSource.IsCancellationRequested)
                                {
                                    return;
                                }
                                if (element != null)
                                {
                                    var pulse = new Pulse.Pulse();
                                    pulse.TargetNodes   = new ElementNode[] { element };
                                    pulse.TimeSpan      = segmentPulse;
                                    pulse.ColorGradient = _data.ColorGradient;
                                    pulse.LevelCurve    = _data.Curve;
                                    result = pulse.Render();
                                    result.OffsetAllCommandsByTime(effectTime);
                                    _elementData.Add(result);
                                }
                            }
                            effectTime += intervalTime;
                        }
                        count++;
                    }
                }
                else
                {
                    double intervals    = (double)PulseTime / (double)renderNodes.Count();
                    var    intervalTime = TimeSpan.FromMilliseconds(intervals);
                    // the calculation above blows up render time/memory as count goes up, try this..
                    // also fails if intervals is less than half a ms and intervalTime then gets 0
                    intervalTime = TimeSpan.FromMilliseconds(Math.Max(intervalTime.TotalMilliseconds, 50));
                    TimeSpan segmentPulse = TimeSpan.FromMilliseconds(PulseTime);
                    while (effectTime < TimeSpan)
                    {
                        foreach (var item in renderNodes)
                        {
                            EffectIntents result;

                            if (tokenSource != null && tokenSource.IsCancellationRequested)
                            {
                                return;
                            }
                            foreach (ElementNode element in item)
                            {
                                if (element != null)
                                {
                                    if (tokenSource != null && tokenSource.IsCancellationRequested)
                                    {
                                        return;
                                    }
                                    var pulse = new Pulse.Pulse();
                                    pulse.TargetNodes   = new ElementNode[] { element };
                                    pulse.TimeSpan      = segmentPulse;
                                    pulse.ColorGradient = _data.ColorGradient;
                                    pulse.LevelCurve    = _data.Curve;
                                    result = pulse.Render();

                                    result.OffsetAllCommandsByTime(effectTime);
                                    _elementData.Add(result);
                                }
                            }
                            effectTime += intervalTime;
                            if (effectTime >= TimeSpan)
                            {
                                return;
                            }
                        }
                    }
                }
            }
        }
Exemple #22
0
        protected override void _PreRender(CancellationTokenSource tokenSource = null)
        {
            _elementData = new EffectIntents();

            List <IElementNode[]> renderNodes = new List <IElementNode[]>();
            List <Tuple <IElementNode, int, int, int> > renderedNodes = TargetNodes.SelectMany(x => x.GetLeafEnumerator())
                                                                        .Select(s =>
            {
                var prop = s.Properties.Get(LocationDescriptor._typeId);
                if (prop != null)
                {
                    return(new Tuple <IElementNode, int, int, int>(s, ((LocationData)prop.ModuleData).X,
                                                                   ((LocationData)prop.ModuleData).Y, ((LocationData)prop.ModuleData).Z));
                }
                return(new Tuple <IElementNode, int, int, int>(null, -1, -1, -1));
            })
                                                                        .Where(s => s.Item2 > 0)
                                                                        .ToList();

            if (!renderedNodes.Any())
            {
                return;
            }

            _maxX         = renderedNodes.Max(m => m.Item2);
            _maxY         = renderedNodes.Max(m => m.Item3);
            _minX         = renderedNodes.Min(m => m.Item2);
            _minY         = renderedNodes.Min(m => m.Item3);
            _bufferWidth  = _maxX - _minX;
            _bufferHeight = _maxY - _minY;
            _midX         = _bufferWidth / 2;
            _midY         = _bufferHeight / 2;

            switch (Direction)
            {
            case WipeDirection.DiagonalUp:
            case WipeDirection.DiagonalDown:
                renderNodes = GetRenderedDiagonal(renderedNodes);
                break;

            case WipeDirection.Vertical:
            case WipeDirection.Horizontal:
                renderNodes = GetRenderedLRUD(renderedNodes);
                break;

            case WipeDirection.Circle:
                renderNodes = GetRenderedCircle(renderedNodes);
                break;

            case WipeDirection.Dimaond:
                renderNodes = GetRenderedDiamond(renderedNodes);
                break;

            case WipeDirection.Burst:
                renderNodes = GetRenderedRectangle(renderedNodes);
                break;
            }

            switch (WipeMovement)
            {
            case WipeMovement.Count:
                RenderCount(renderNodes, tokenSource);
                break;

            case WipeMovement.PulseLength:
                RenderPulseLength(renderNodes, tokenSource);
                break;

            case WipeMovement.Movement:
                RenderMovement(renderNodes, tokenSource);
                break;
            }
        }
Exemple #23
0
        private void RenderNodes(CancellationTokenSource tokenSource)
        {
            IEnumerable <IGrouping <int, ElementNode> > renderNodes = null;

            switch (_data.Direction)
            {
            case WipeDirection.Up:
                renderNodes = TargetNodes
                              .SelectMany(x => x.GetLeafEnumerator())
                              .OrderByDescending(x =>
                {
                    var prop = x.Properties.Get(LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).Y);
                    }
                    else
                    {
                        return(1);
                    }
                })
                              .ThenBy(x =>
                {
                    var prop = x.Properties.Get(LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).X);
                    }
                    else
                    {
                        return(1);
                    }
                })
                              .GroupBy(x =>
                {
                    var prop = x.Properties.Get(LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).Y);
                    }
                    else
                    {
                        return(1);
                    }
                })
                              .Distinct();
                RenderNonBurst(tokenSource, renderNodes);
                break;

            case WipeDirection.Down:

                renderNodes = TargetNodes.SelectMany(x => x.GetLeafEnumerator())
                              .OrderBy(x =>
                {
                    var prop = x.Properties.Get(LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).Y);
                    }
                    else
                    {
                        return(1);
                    }
                })
                              .ThenBy(x =>
                {
                    var prop = x.Properties.Get(LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).X);
                    }
                    else
                    {
                        return(1);
                    }
                })
                              .GroupBy(x =>
                {
                    var prop = x.Properties.Get(LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).Y);
                    }
                    else
                    {
                        return(1);
                    }
                })
                              .Distinct();
                RenderNonBurst(tokenSource, renderNodes);
                break;

            case WipeDirection.Right:

                renderNodes = TargetNodes.SelectMany(x => x.GetLeafEnumerator())
                              .OrderBy(x =>
                {
                    var prop = x.Properties.Get(LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).X);
                    }
                    else
                    {
                        return(1);
                    }
                })
                              .ThenBy(x =>
                {
                    var prop = x.Properties.Get(LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).Y);
                    }
                    else
                    {
                        return(1);
                    }
                })
                              .GroupBy(x =>
                {
                    var prop = x.Properties.Get(LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).X);
                    }
                    else
                    {
                        return(1);
                    }
                })
                              .Distinct();
                RenderNonBurst(tokenSource, renderNodes);
                break;

            case WipeDirection.Left:

                renderNodes = TargetNodes.SelectMany(x => x.GetLeafEnumerator())
                              .OrderByDescending(x =>
                {
                    var prop = x.Properties.Get(LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).X);
                    }
                    return(1);
                })
                              .ThenBy(x =>
                {
                    var prop = x.Properties.Get(LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).Y);
                    }
                    return(1);
                })
                              .GroupBy(x =>
                {
                    var prop = x.Properties.Get(LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).X);
                    }
                    return(1);
                })
                              .Distinct();
                RenderNonBurst(tokenSource, renderNodes);
                break;

            case WipeDirection.Out:
            case WipeDirection.In:
                RenderBurst(tokenSource, _data.Direction);
                break;
            }
        }
Exemple #24
0
        protected override void _PreRender(CancellationTokenSource tokenSource = null)
        {
            _elementData = new EffectIntents();

            IEnumerable <IGrouping <int, ElementNode> > renderNodes = null;


            var enumerator = TargetNodes.SelectMany(x => x.GetLeafEnumerator());
            var b          = enumerator;

            switch (_data.Direction)
            {
            case WipeDirection.Up:
                renderNodes = TargetNodes
                              .SelectMany(x => x.GetLeafEnumerator())
                              .OrderByDescending(x =>
                {
                    var prop = x.Properties.Get(VixenModules.Property.Location.LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).Y);
                    }
                    else
                    {
                        return(1);
                    }
                })
                              .ThenBy(x =>
                {
                    var prop = x.Properties.Get(VixenModules.Property.Location.LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).X);
                    }
                    else
                    {
                        return(1);
                    }
                })
                              .GroupBy(x =>
                {
                    var prop = x.Properties.Get(VixenModules.Property.Location.LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).Y);
                    }
                    else
                    {
                        return(1);
                    }
                })
                              .Distinct();
                break;

            case WipeDirection.Down:

                renderNodes = TargetNodes.SelectMany(x => x.GetLeafEnumerator())
                              .OrderBy(x =>
                {
                    var prop = x.Properties.Get(VixenModules.Property.Location.LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).Y);
                    }
                    else
                    {
                        return(1);
                    }
                })
                              .ThenBy(x =>
                {
                    var prop = x.Properties.Get(VixenModules.Property.Location.LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).X);
                    }
                    else
                    {
                        return(1);
                    }
                })
                              .GroupBy(x =>
                {
                    var prop = x.Properties.Get(VixenModules.Property.Location.LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).Y);
                    }
                    else
                    {
                        return(1);
                    }
                })
                              .Distinct();
                break;

            case WipeDirection.Right:

                renderNodes = TargetNodes.SelectMany(x => x.GetLeafEnumerator())
                              .OrderBy(x =>
                {
                    var prop = x.Properties.Get(VixenModules.Property.Location.LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).X);
                    }
                    else
                    {
                        return(1);
                    }
                })
                              .ThenBy(x =>
                {
                    var prop = x.Properties.Get(VixenModules.Property.Location.LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).Y);
                    }
                    else
                    {
                        return(1);
                    }
                })
                              .GroupBy(x =>
                {
                    var prop = x.Properties.Get(VixenModules.Property.Location.LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).X);
                    }
                    else
                    {
                        return(1);
                    }
                })
                              .Distinct();
                break;

            case WipeDirection.Left:

                renderNodes = TargetNodes.SelectMany(x => x.GetLeafEnumerator())
                              .OrderByDescending(x =>
                {
                    var prop = x.Properties.Get(VixenModules.Property.Location.LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).X);
                    }
                    return(1);
                })
                              .ThenBy(x =>
                {
                    var prop = x.Properties.Get(VixenModules.Property.Location.LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).Y);
                    }
                    return(1);
                })
                              .GroupBy(x =>
                {
                    var prop = x.Properties.Get(VixenModules.Property.Location.LocationDescriptor._typeId);
                    if (prop != null)
                    {
                        return(((LocationData)prop.ModuleData).X);
                    }
                    return(1);
                })

                              .Distinct();
                break;

            case WipeDirection.Out:
            case WipeDirection.In:
                RenderBurst(tokenSource, _data.Direction);

                return;

                break;

            default:
                break;
            }

            RenderNonBurst(tokenSource, renderNodes);
        }