Exemplo n.º 1
0
        protected override void _PreRender(CancellationTokenSource tokenSource = null)
        {
            _elementData = new EffectIntents();

            IEnumerable <ElementNode> targetNodes = GetNodesToRenderOn();

            List <IndividualTwinkleDetails> twinkles = null;

            if (!IndividualElements)
            {
                twinkles = GenerateTwinkleData();
            }

            int    totalNodes = targetNodes.Count();
            double i          = 0;

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

                if (node != null)
                {
                    _elementData.Add(RenderElement(node, i++ / (double)totalNodes, twinkles));
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Convienience method to generate intents that knows how to deal with discrete colors.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="gradient"></param>
        /// <param name="level"></param>
        /// <param name="startPos"></param>
        /// <param name="endPos"></param>
        /// <param name="duration"></param>
        /// <param name="startTime"></param>
        /// <param name="isDiscrete"></param>
        /// <returns></returns>
        protected EffectIntents GenerateEffectIntents(ElementNode node, ColorGradient gradient, Curve level, double startPos, double endPos,
                                                      TimeSpan duration, TimeSpan startTime, bool isDiscrete)
        {
            EffectIntents result = new EffectIntents();

            if (isDiscrete)
            {
                IEnumerable <Color> colors = ColorModule.getValidColorsForElementNode(node, false)
                                             .Intersect(gradient.GetColorsInGradient());
                foreach (Color color in colors)
                {
                    double proportion     = gradient.GetProportionOfColorAt(startPos, color);
                    var    startIntensity = (level.GetValue(startPos * 100) / 100) * proportion;
                    proportion = gradient.GetProportionOfColorAt(endPos, color);
                    var endIntensity = (level.GetValue(endPos * 100) / 100) * proportion;
                    if (startIntensity > 0 && endIntensity > 0)
                    {
                        var intent = CreateDiscreteIntent(color, startIntensity, endIntensity, duration);
                        result.AddIntentForElement(node.Element.Id, intent, startTime);
                    }
                }
            }
            else
            {
                var startIntensity = level.GetValue(startPos * 100) / 100;
                var endIntensity   = level.GetValue(endPos * 100) / 100;
                if (startIntensity > 0 && endIntensity > 0)
                {
                    var intent = CreateIntent(gradient.GetColorAt(startPos), gradient.GetColorAt(endPos), startIntensity, endIntensity, duration);
                    result.AddIntentForElement(node.Element.Id, intent, startTime);
                }
            }

            return(result);
        }
Exemplo n.º 3
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.
        public static EffectIntents RenderNode(ElementNode node, Curve levelCurve, ColorGradient colorGradient, TimeSpan duration, bool isDiscrete, bool allowZeroIntensity = false)
        {
            //Collect all the points first.
            double[] allPointsTimeOrdered = _GetAllSignificantDataPoints(levelCurve, colorGradient).ToArray();
            var      elementData          = new EffectIntents();

            foreach (ElementNode elementNode in node.GetLeafEnumerator())
            {
                // this is probably always going to be a single element for the given node, as
                // we have iterated down to leaf nodes in RenderNode() above. May as well do
                // it this way, though, in case something changes in future.
                if (elementNode == null || elementNode.Element == null)
                {
                    continue;
                }

                //ElementColorType colorType = ColorModule.getColorTypeForElementNode(elementNode);

                if (isDiscrete && IsElementDiscrete(node))
                {
                    IEnumerable <Color> colors = ColorModule.getValidColorsForElementNode(elementNode, false)
                                                 .Intersect(colorGradient.GetColorsInGradient());
                    foreach (Color color in colors)
                    {
                        AddIntentsToElement(elementNode.Element, allPointsTimeOrdered, levelCurve, colorGradient, duration, elementData, allowZeroIntensity, color);
                    }
                }
                else
                {
                    AddIntentsToElement(elementNode.Element, allPointsTimeOrdered, levelCurve, colorGradient, duration, elementData, allowZeroIntensity);
                }
            }

            return(elementData);
        }
Exemplo n.º 4
0
        protected EffectIntents RenderNodeByLocation(ElementNode node)
        {
            EffectIntents effectIntents = new EffectIntents();
            int           nFrames       = GetNumberFrames();

            if (nFrames <= 0 | BufferWi == 0 || BufferHt == 0)
            {
                return(effectIntents);
            }
            PixelLocationFrameBuffer buffer = new PixelLocationFrameBuffer(ElementLocations.Distinct().ToList(), nFrames);

            TimeSpan startTime = TimeSpan.Zero;

            // generate all the pixels
            RenderEffectByLocation(nFrames, buffer);

            // create the intents
            var frameTs = new TimeSpan(0, 0, 0, 0, FrameTime);

            foreach (var tuple in buffer.GetElementData())
            {
                if (tuple.Item2.Count != nFrames)
                {
                    Logging.Error("{0} count has {1} instead of {2}", tuple.Item1.ElementNode.Name, tuple.Item2.Count, nFrames);
                }
                IIntent intent = new StaticArrayIntent <RGBValue>(frameTs, tuple.Item2.ToArray(), TimeSpan);
                effectIntents.AddIntentForElement(tuple.Item1.ElementNode.Element.Id, intent, startTime);
            }

            return(effectIntents);
        }
Exemplo n.º 5
0
		protected override void _PreRender(CancellationTokenSource tokenSource = null)
		{
			int scnt = StringCount;
			if (scnt < 2)
			{
				//_data.NutcrackerData.PreviewType = NutcrackerEffects.PreviewType.VerticalLine;
				switch (_data.NutcrackerData.PreviewType)
				{
					case NutcrackerEffects.PreviewType.Arch:
					case NutcrackerEffects.PreviewType.VerticalLine:
					case NutcrackerEffects.PreviewType.HorizontalLine:
						break;
					default:
						_data.NutcrackerData.PreviewType = NutcrackerEffects.PreviewType.VerticalLine;
						break;
				}
			}
				
			_elementData = new EffectIntents();

			foreach (ElementNode node in TargetNodes) {
				if (tokenSource != null && tokenSource.IsCancellationRequested)
					return;
				
				if (node != null)
					RenderNode(node);
			}

			_elementIntents.Clear();
		}
Exemplo n.º 6
0
        protected override void _PreRender(CancellationTokenSource tokenSource = null)
        {
            _elementData = new EffectIntents();

            IEnumerable <ElementNode> targetNodes = GetNodesToRenderOn();

            List <IndividualTwinkleDetails> twinkles = null;

            if (!IndividualElements)
            {
                twinkles = GenerateTwinkleData();
            }

            int    totalNodes = targetNodes.Count();
            double i          = 0;

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

                if (node != null)
                {
                    bool discreteColors = HasDiscreteColors && ColorModule.isElementNodeDiscreteColored(node);
                    var  intents        = RenderElement(node, i++ / totalNodes, discreteColors, twinkles);
                    _elementData.Add(IntentBuilder.ConvertToStaticArrayIntents(intents, TimeSpan, discreteColors));
                }
            }
        }
Exemplo n.º 7
0
        public static EffectIntents ConvertToStaticArrayIntents(EffectIntents intents, TimeSpan duration, bool discrete = false)
        {
            if (discrete)
            {
                return(ConvertToDiscreteStaticArrayIntents(intents, duration));
            }

            var           interval      = VixenSystem.DefaultUpdateTimeSpan;
            var           intervals     = (int)(duration.TotalMilliseconds / interval.TotalMilliseconds);
            EffectIntents effectIntents = new EffectIntents();

            foreach (var effectIntent in intents)
            {
                RGBValue[] values = new RGBValue[intervals + 1];
                for (int i = 0; i < intervals + 1; i++)
                {
                    var currentTime = TimeSpan.FromMilliseconds(interval.TotalMilliseconds * i);
                    var color       = ProcessIntentNodes(effectIntent, currentTime);
                    values[i] = new RGBValue(color);
                }

                effectIntents.AddIntentForElement(effectIntent.Key, new StaticArrayIntent <RGBValue>(interval, values, duration), TimeSpan.Zero);
            }

            return(effectIntents);
        }
Exemplo n.º 8
0
        protected override void _PreRender(CancellationTokenSource tokenSource = null)
        {
            int scnt = StringCount;

            if (scnt < 2)
            {
                //_data.NutcrackerData.PreviewType = NutcrackerEffects.PreviewType.VerticalLine;
                switch (_data.NutcrackerData.PreviewType)
                {
                case NutcrackerEffects.PreviewType.Arch:
                case NutcrackerEffects.PreviewType.VerticalLine:
                case NutcrackerEffects.PreviewType.HorizontalLine:
                    break;

                default:
                    _data.NutcrackerData.PreviewType = NutcrackerEffects.PreviewType.VerticalLine;
                    break;
                }
            }

            _elementData = new EffectIntents();

            foreach (IElementNode node in TargetNodes)
            {
                if (tokenSource != null && tokenSource.IsCancellationRequested)
                {
                    return;
                }

                if (node != null)
                {
                    RenderNode(node);
                }
            }
        }
Exemplo n.º 9
0
        protected override void _PreRender(CancellationTokenSource tokenSource = null)
        {
            if (TargetPositioning == TargetPositioningType.Strings)
            {
                ConfigureStringBuffer();
            }
            else
            {
                ConfigureVirtualBuffer();
            }

            SetupRender();
            int           bufferSize = StringPixelCounts.Sum();
            EffectIntents data       = new EffectIntents(bufferSize);

            foreach (ElementNode node in TargetNodes)
            {
                if (node != null)
                {
                    RenderNode(node, ref data);
                }
            }
            _elementData = data;
            CleanUpRender();
            ElementLocations = null;
        }
Exemplo n.º 10
0
        protected EffectIntents RenderNodeByLocation(ElementNode node, ref EffectIntents effectIntents)
        {
            int nFrames = GetNumberFrames();

            if (nFrames <= 0 | BufferWi == 0 || BufferHt == 0)
            {
                return(effectIntents);
            }
            PixelLocationFrameBuffer buffer = new PixelLocationFrameBuffer(ElementLocations, nFrames);

            TimeSpan startTime = TimeSpan.Zero;

            // generate all the pixels
            RenderEffectByLocation(nFrames, buffer);

            // create the intents
            var frameTs = new TimeSpan(0, 0, 0, 0, FrameTime);

            foreach (var elementLocation in ElementLocations)
            {
                var     frameData = buffer.GetFrameDataAt(elementLocation.X, elementLocation.Y);
                IIntent intent    = new StaticArrayIntent <RGBValue>(frameTs, frameData, TimeSpan);
                effectIntents.AddIntentForElement(elementLocation.ElementNode.Element.Id, intent, startTime);
            }

            return(effectIntents);
        }
Exemplo n.º 11
0
        protected override void _PreRender(CancellationTokenSource cancellationToken = null)
        {
            _elementData = new EffectIntents();

            var elements = GetNodesToRenderOn().Select((x, index) => new { x, index })
                           .GroupBy(x => x.index / GroupLevel, y => y.x);
            var renderNodes = elements as IGrouping <int, ElementNode>[] ?? elements.ToArray();

            _totalNodes = renderNodes.Count();

            _pixels = 0;

            _tempNodes      = new List <TempClass>(_totalNodes);
            _nodes          = new List <TempClass>(_totalNodes);
            _elements       = new List <DissolveClass>();
            _renderElements = new List <DissolveClass>();

            InitializeDissolveClasses();

            _elementData.Add(RenderNode(renderNodes));

            _nodes          = null;
            _tempNodes      = null;
            _elements       = null;
            _renderElements = null;
        }
Exemplo n.º 12
0
        public static EffectIntents ConvertToStaticArrayIntents(EffectIntents intents, TimeSpan duration, bool discrete = false)
        {
            if (discrete)
            {
                return ConvertToDiscreteStaticArrayIntents(intents, duration);
            }

            var interval = VixenSystem.DefaultUpdateTimeSpan;
            var intervals = (int)(duration.TotalMilliseconds / interval.TotalMilliseconds);
            EffectIntents effectIntents = new EffectIntents();

            foreach (var effectIntent in intents)
            {
                RGBValue[] values = new RGBValue[intervals + 1];
                for (int i = 0; i < intervals + 1; i++)
                {
                    var currentTime = TimeSpan.FromMilliseconds(interval.TotalMilliseconds*i);
                    var color = ProcessIntentNodes(effectIntent, currentTime);
                    values[i] = new RGBValue(color);
                }

                effectIntents.AddIntentForElement(effectIntent.Key, new StaticArrayIntent<RGBValue>(interval, values, duration), TimeSpan.Zero);
            }

            return effectIntents;
        }
Exemplo n.º 13
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.
        public static EffectIntents RenderNode(ElementNode node, Curve levelCurve, ColorGradient colorGradient, TimeSpan duration, bool isDiscrete, bool allowZeroIntensity = false)
        {
            //Collect all the points first.
            double[] allPointsTimeOrdered = _GetAllSignificantDataPoints(levelCurve, colorGradient).ToArray();
            var elementData = new EffectIntents();
            foreach (ElementNode elementNode in node.GetLeafEnumerator())
            {
                // this is probably always going to be a single element for the given node, as
                // we have iterated down to leaf nodes in RenderNode() above. May as well do
                // it this way, though, in case something changes in future.
                if (elementNode == null || elementNode.Element == null)
                    continue;

                //ElementColorType colorType = ColorModule.getColorTypeForElementNode(elementNode);

                if (isDiscrete && IsElementDiscrete(node))
                {
                    IEnumerable<Color> colors = ColorModule.getValidColorsForElementNode(elementNode, false)
                         .Intersect(colorGradient.GetColorsInGradient());
                    foreach (Color color in colors)
                    {
                        AddIntentsToElement(elementNode.Element, allPointsTimeOrdered, levelCurve, colorGradient, duration, elementData, allowZeroIntensity, color);
                    }
                }
                else
                {
                    AddIntentsToElement(elementNode.Element, allPointsTimeOrdered, levelCurve, colorGradient, duration, elementData, allowZeroIntensity);
                }
            }

            return elementData;
        }
Exemplo n.º 14
0
        private void GenerateStartingStaticPulse(ElementNode target, IIntentNode intentNode, ColorGradient gradient = null)
        {
            if (intentNode == null || intentNode.StartTime <= TimeSpan.Zero)
            {
                return;
            }
            var lightingIntent = intentNode.Intent as LightingIntent;

            if (lightingIntent != null && lightingIntent.StartValue.Intensity > 0)
            {
                var newCurve =
                    new Curve(
                        new PointPairList(new PointPairList(new[] { 0.0, 100 },
                                                            new[] { lightingIntent.StartValue.Intensity *100, lightingIntent.StartValue.Intensity *100 })));
                var pulse = new Pulse.Pulse
                {
                    TargetNodes   = new[] { target },
                    LevelCurve    = newCurve,
                    ColorGradient = gradient ?? new ColorGradient(lightingIntent.StartValue.FullColor),
                    TimeSpan      = intentNode.StartTime
                };
                EffectIntents result = pulse.Render();
                _elementData.Add(result);
            }
        }
Exemplo n.º 15
0
 private void _DiscoverIntentsFromEffects()
 {
     // For each effect in the in-effect list for the context...
     //Parallel.ForEach(_currentEffects, effectNode =>
     foreach (var effectNode in CurrentEffects)
     {
         var           layer = GetLayerForNode(effectNode);
         TimeSpan      effectRelativeTime = _currentTime - effectNode.StartTime;
         EffectIntents effectIntents      = effectNode.Effect.Render();
         if (effectIntents == null)
         {
             continue;
         }
         foreach (var effectIntent in effectIntents)
         {
             foreach (IIntentNode intentNode in effectIntent.Value)
             {
                 if (TimeNode.IntersectsInclusively(intentNode, effectRelativeTime))
                 {
                     IIntentState intentState = intentNode.CreateIntentState(effectRelativeTime - intentNode.StartTime,
                                                                             layer);
                     _elementStateBuilder.AddElementState(effectIntent.Key, intentState);
                 }
             }
         }
     }
 }
Exemplo n.º 16
0
        protected override void _PreRender()
        {
            _effectIntents = new EffectIntents();

            Image image;

            try {
                image = Image.FromFile(_data.FilePath);
            }
            catch {
                return;
            }

            foreach (ElementNode targetNode in TargetNodes)
            {
                // Each element represents a single pixel in the grid display.
                // Therefore, the intent for the element will represent the state of that
                // pixel over the lifetime of the effect.

                // Get the grid dimensions from the node.
                VixenModules.Property.Grid.Module gridProperty =
                    (VixenModules.Property.Grid.Module)targetNode.Properties.Get(((Descriptor)Descriptor)._gridPropertyId);
                VixenModules.Property.Grid.Data gridData = (VixenModules.Property.Grid.Data)gridProperty.ModuleData;

                // For now, just scale it to the dimensions of the grid.
                Element[] elements    = targetNode.ToArray();
                byte[]    pixelBuffer = new byte[] { 0, 0, 0, byte.MaxValue };
                using (Bitmap bitmap = new Bitmap(gridData.Width, gridData.Height, image.PixelFormat)) {
                    using (Graphics g = Graphics.FromImage(bitmap)) {
                        g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                        g.DrawImage(image, 0, 0, bitmap.Width, bitmap.Height);

                        BitmapData bitmapData = bitmap.LockBits(Rectangle.FromLTRB(0, 0, bitmap.Width, bitmap.Height),
                                                                ImageLockMode.ReadOnly, image.PixelFormat);

                        byte[] rgbValues = new byte[Math.Abs(bitmapData.Stride) * bitmap.Height];
                        System.Runtime.InteropServices.Marshal.Copy(bitmapData.Scan0, rgbValues, 0, rgbValues.Length);

                        int bytesPerPixel = bitmapData.Stride / bitmapData.Width;
                        for (int y = 0, pixelIndex = 0; y < bitmapData.Height; y++)
                        {
                            int sourceDataIndex = y * bitmapData.Stride;
                            for (int x = 0; x < bitmapData.Width; x++, pixelIndex++, sourceDataIndex += bytesPerPixel)
                            {
                                Array.Copy(rgbValues, sourceDataIndex, pixelBuffer, 0, bytesPerPixel);
                                int           argbValue  = BitConverter.ToInt32(pixelBuffer, 0);
                                Color         pixelColor = Color.FromArgb(argbValue);
                                LightingValue startValue = new LightingValue(pixelColor, 1);
                                LightingValue endValue   = new LightingValue(pixelColor, 1);
                                IIntent       intent     = new LightingIntent(startValue, endValue, TimeSpan);
                                _effectIntents.AddIntentForElement(elements[pixelIndex].Id, intent, TimeSpan.Zero);
                            }
                        }

                        bitmap.UnlockBits(bitmapData);
                    }
                }
            }
        }
Exemplo n.º 17
0
        protected override void _PreRender()
        {
            _channelData = new EffectIntents();

            foreach (ChannelNode node in TargetNodes) {
                RenderNode(node);
            }
        }
Exemplo n.º 18
0
        protected override void _PreRender()
        {
            _elementData = new EffectIntents();

            foreach (ElementNode node in TargetNodes) {
                RenderNode(node);
            }
        }
Exemplo n.º 19
0
        protected override void _PreRender(CancellationTokenSource cancellationToken = null)
        {
            _elementData = new EffectIntents();

            var renderNodes = GetNodesToRenderOn();

            _elementData.Add(RenderNode(renderNodes));
        }
Exemplo n.º 20
0
        private void RenderElement(GradientLevelPair gradientLevelPair, TimeSpan startTime, TimeSpan interval,
                                   ElementNode element, EffectIntents effectIntents)
        {
            var result = PulseRenderer.RenderNode(element, gradientLevelPair.Curve, gradientLevelPair.ColorGradient, interval, HasDiscreteColors);

            result.OffsetAllCommandsByTime(startTime);
            effectIntents.Add(result);
        }
Exemplo n.º 21
0
        public EffectIntents Render(TimeSpan restrictingOffsetTime, TimeSpan restrictingTimeSpan)
        {
            EffectIntents effectIntents = Render();

            // NB: the ElementData.Restrict method takes a start and end time, not a start and duration
            effectIntents = EffectIntents.Restrict(effectIntents, restrictingOffsetTime, restrictingOffsetTime + restrictingTimeSpan);
            return(effectIntents);
        }
Exemplo n.º 22
0
 protected EffectIntents RenderNode(ElementNode node, ref EffectIntents effectIntents)
 {
     if (TargetPositioning == TargetPositioningType.Strings)
     {
         return(RenderNodeByStrings(node, ref effectIntents));
     }
     return(RenderNodeByLocation(node, ref effectIntents));
 }
Exemplo n.º 23
0
        protected override void _PreRender(CancellationTokenSource tokenSource = null)
        {
            _elementData = new EffectIntents();

            DoRendering(tokenSource);

            //_elementData = IntentBuilder.ConvertToStaticArrayIntents(_elementData, TimeSpan, IsDiscrete());
        }
        private void _FilterEffectIntents(IEffectNode effectNode)
        {
            EffectIntents effectIntents = effectNode.Effect.Render();

            foreach (Guid channelId in effectIntents.ChannelIds)
            {
                _ApplyFiltersForChannelToIntents(effectIntents, channelId, effectNode.StartTime);
            }
        }
Exemplo n.º 25
0
        private void _FilterEffectIntents(IEffectNode effectNode)
        {
            EffectIntents effectIntents = effectNode.Effect.Render();

            foreach (Guid elementId in effectIntents.ElementIds)
            {
                _ApplyFiltersForElementToIntents(effectIntents, elementId, effectNode.StartTime);
            }
        }
Exemplo n.º 26
0
        protected override void _PreRender(CancellationTokenSource cancellationToken = null)
        {
            _elementData = new EffectIntents();
            IEnumerable <IGrouping <int, IElementNode> > elements;
            IEnumerable <IElementNode> renderNodes = GetNodesToRenderOn();

            switch (DissolveMode)
            {
            case DissolveMode.MarkCollection:
            {
                SetupMarks();
                if ((DissolveMarkType == DissolveMarkType.PerMarkFill ||
                     DissolveMarkType == DissolveMarkType.PerMarkDissolve) && ColorPerStep)
                {
                    int nodeCount     = renderNodes.Count();
                    int nodesPerGroup = DirectionsTogether && BothDirections
                                                        ? nodeCount / (_marks.Count() - 1) / 2
                                                        : nodeCount / (_marks.Count() - 1);
                    elements = renderNodes.Select((x, index) => new { x, index })
                               .GroupBy(x => x.index / nodesPerGroup, y => y.x);
                }
                else
                {
                    elements = renderNodes.Select((x, index) => new { x, index })
                               .GroupBy(x => x.index / GroupLevel, y => y.x);
                }

                break;
            }

            default:
                elements = renderNodes.Select((x, index) => new { x, index })
                           .GroupBy(x => x.index / GroupLevel, y => y.x);
                break;
            }


            var renderNodes1 = elements as IGrouping <int, IElementNode>[] ?? elements.ToArray();

            _totalNodes = renderNodes1.Count();

            _pixels = 0;

            _tempNodes      = new List <TempClass>(_totalNodes);
            _nodes          = new List <TempClass>(_totalNodes);
            _elements       = new List <DissolveClass>();
            _renderElements = new List <DissolveClass>();

            InitializeDissolveClasses(1);

            _elementData.Add(RenderNode(renderNodes1));

            _nodes          = null;
            _tempNodes      = null;
            _elements       = null;
            _renderElements = null;
        }
Exemplo n.º 27
0
        protected override void _PreRender()
        {
            _elementData = new EffectIntents();

            foreach (ElementNode node in TargetNodes)
            {
                RenderNode(node);
            }
        }
Exemplo n.º 28
0
        protected override void _PreRender()
        {
            _effectIntents = new EffectIntents();
            _r = new Random();

            foreach (Element element in TargetNodes.SelectMany(x => x)) {
                _RenderCandleOnElement(element);
            }
        }
Exemplo n.º 29
0
        private void _AddLocalIntents()
        {
            EffectIntents effectIntents = Render();

            foreach (KeyValuePair <Guid, IntentNodeCollection> keyValuePair in effectIntents)
            {
                _elementIntents.AddIntentNodeToElement(keyValuePair.Key, keyValuePair.Value.ToArray());
            }
        }
Exemplo n.º 30
0
        private void _AddLocalIntents(TimeSpan effectRelativeTime)
        {
            EffectIntents effectIntents = Render();

            foreach (Guid elementId in effectIntents.ElementIds)
            {
                IIntentNode[] elementIntents = effectIntents.GetElementIntentsAtTime(elementId, effectRelativeTime);
                _elementIntents.AddIntentNodeToElement(elementId, elementIntents);
            }
        }
Exemplo n.º 31
0
        private void _FilterEffectIntents(IEffectNode effectNode)
        {
            EffectIntents effectIntents = effectNode.Effect.Render();

            effectIntents.ElementIds.AsParallel().ForAll(
                elementId => _ApplyFiltersForElementToIntents(effectIntents, elementId, effectNode.StartTime));
            //foreach(Guid elementId in effectIntents.ElementIds) {
            //	_ApplyFiltersForElementToIntents(effectIntents, elementId, effectNode.StartTime);
            //}
        }
Exemplo n.º 32
0
        protected override void _PreRender()
        {
            _effectIntents = new EffectIntents();
            _r             = new Random();

            foreach (Element element in TargetNodes.SelectMany(x => x))
            {
                _RenderCandleOnElement(element);
            }
        }
Exemplo n.º 33
0
		protected override void _PreRender()
		{
			_effectIntents = new EffectIntents();

			Image image;
			try {
				image = Image.FromFile(_data.FilePath);
			}
			catch {
				return;
			}

			foreach (ElementNode targetNode in TargetNodes) {
				// Each element represents a single pixel in the grid display.
				// Therefore, the intent for the element will represent the state of that
				// pixel over the lifetime of the effect.

				// Get the grid dimensions from the node.
				VixenModules.Property.Grid.Module gridProperty =
					(VixenModules.Property.Grid.Module) targetNode.Properties.Get(((Descriptor) Descriptor)._gridPropertyId);
				VixenModules.Property.Grid.Data gridData = (VixenModules.Property.Grid.Data) gridProperty.ModuleData;

				// For now, just scale it to the dimensions of the grid.
				Element[] elements = targetNode.ToArray();
				byte[] pixelBuffer = new byte[] {0, 0, 0, byte.MaxValue};
				using (Bitmap bitmap = new Bitmap(gridData.Width, gridData.Height, image.PixelFormat)) {
					using (Graphics g = Graphics.FromImage(bitmap)) {
						g.InterpolationMode = InterpolationMode.HighQualityBicubic;
						g.DrawImage(image, 0, 0, bitmap.Width, bitmap.Height);

						BitmapData bitmapData = bitmap.LockBits(Rectangle.FromLTRB(0, 0, bitmap.Width, bitmap.Height),
						                                        ImageLockMode.ReadOnly, image.PixelFormat);

						byte[] rgbValues = new byte[Math.Abs(bitmapData.Stride)*bitmap.Height];
						System.Runtime.InteropServices.Marshal.Copy(bitmapData.Scan0, rgbValues, 0, rgbValues.Length);

						int bytesPerPixel = bitmapData.Stride/bitmapData.Width;
						for (int y = 0, pixelIndex = 0; y < bitmapData.Height; y++) {
							int sourceDataIndex = y*bitmapData.Stride;
							for (int x = 0; x < bitmapData.Width; x++, pixelIndex++, sourceDataIndex += bytesPerPixel) {
								Array.Copy(rgbValues, sourceDataIndex, pixelBuffer, 0, bytesPerPixel);
								int argbValue = BitConverter.ToInt32(pixelBuffer, 0);
								Color pixelColor = Color.FromArgb(argbValue);
								LightingValue startValue = new LightingValue(pixelColor, 1);
								LightingValue endValue = new LightingValue(pixelColor, 1);
								IIntent intent = new LightingIntent(startValue, endValue, TimeSpan);
								_effectIntents.AddIntentForElement(elements[pixelIndex].Id, intent, TimeSpan.Zero);
							}
						}

						bitmap.UnlockBits(bitmapData);
					}
				}
			}
		}
Exemplo n.º 34
0
        public static EffectIntents RenderNode(IElementNode node, double level, Color color, TimeSpan duration)
        {
            var elementData = new EffectIntents();

            if (node.Element != null && level > 0)
            {
                IIntent intent = IntentBuilder.CreateIntent(color, color, level, level, TimeSpan.FromMilliseconds(duration.TotalMilliseconds));
                elementData.AddIntentForElement(node.Element.Id, intent, TimeSpan.Zero);
            }
            return(elementData);
        }
Exemplo n.º 35
0
        protected override void _PreRender(CancellationTokenSource tokenSource = null)
        {
            _elementData = new EffectIntents();

            if (_data == null)
            {
                return;
            }

            ICommand command = null;

            switch (ValueType)
            {
            case CustomValueType._8Bit:
                command = new _8BitCommand(Value8Bit);
                break;

            case CustomValueType._16Bit:
                command = new _16BitCommand(Value16Bit);
                break;

            case CustomValueType._32Bit:
                command = new _32BitCommand(Value32Bit);
                break;

            case CustomValueType._64Bit:
                command = new _64BitCommand(Value64Bit);
                break;

            case CustomValueType.Color:
                command = new ColorCommand(ColorValue);
                break;

            case CustomValueType.String:
                command = new StringCommand(StringValue);
                break;
            }

            CommandValue value = new CommandValue(command);

            foreach (ElementNode node in TargetNodes)
            {
                foreach (var leafNode in node.GetLeafEnumerator())
                {
                    if (tokenSource != null && tokenSource.IsCancellationRequested)
                    {
                        return;
                    }

                    IIntent intent = new CommandIntent(value, TimeSpan);
                    _elementData.AddIntentForElement(leafNode.Element.Id, intent, TimeSpan.Zero);
                }
            }
        }
Exemplo n.º 36
0
 private void _ApplyFiltersForElementToIntents(EffectIntents effectIntents, Guid elementId, TimeSpan effectStartTime)
 {
     foreach (IntentNode intentNode in effectIntents.GetIntentNodesForElement(elementId))
     {
         ISequenceFilterNode[] elementFilters = _filterLookup.GetFiltersForElement(elementId, intentNode).ToArray();
         foreach (var filter in elementFilters)
         {
             intentNode.ApplyFilter(filter, effectStartTime);
         }
     }
 }
Exemplo n.º 37
0
        protected override void _PreRender()
        {
            _intents = new EffectIntents();
            Channel[] channels = TargetNodes.SelectMany(x => x).ToArray();

            foreach(Channel channel in channels) {
                //IIntent intent = new FloatTransitionIntent(StartLevel, EndLevel, TimeSpan);
                //IIntent intent = new PercentageTransitionIntent(StartLevel / 255, EndLevel / 255, TimeSpan);
                IIntent intent = new LongLinearIntent((long)StartLevel, (long)EndLevel, TimeSpan);
                _intents.AddIntentForChannel(channel.Id, intent, TimeSpan.Zero);
            }
        }
Exemplo n.º 38
0
		protected override void _PreRender(CancellationTokenSource cancellationToken = null)
		{
			EffectIntents data = new EffectIntents();

			foreach (ElementNode node in TargetNodes)
			{
				if (node != null)
					data.Add(RenderNode(node));
			}

			_elementData = data;
		}
Exemplo n.º 39
0
        private void RenderElement(Pulse.Pulse pulse, GradientLevelPair gradientLevelPair, TimeSpan startTime,
                                   ElementNode element, EffectIntents effectIntents)
        {
            pulse.ColorGradient = gradientLevelPair.ColorGradient;
            pulse.LevelCurve    = gradientLevelPair.Curve;
            pulse.TargetNodes   = new[] { element };

            var result = pulse.Render();

            result.OffsetAllCommandsByTime(startTime);
            effectIntents.Add(result);
        }
Exemplo n.º 40
0
		protected override void _PreRender(CancellationTokenSource tokenSource = null)
		{
			_elementData = new EffectIntents();
			
			foreach (ElementNode node in TargetNodes) {
				if (tokenSource != null && tokenSource.IsCancellationRequested)
					return;

				if (node != null)
					RenderNode(node);
			}
		}
Exemplo n.º 41
0
		protected override void _PreRender(CancellationTokenSource tokenSource = null)
		{
			SetupRender();
			EffectIntents data = new EffectIntents();
			foreach (ElementNode node in TargetNodes)
			{
				if (node != null)
					data.Add(RenderNode(node));
			}
			_elementData = data;
			CleanUpRender();
			_elementIntents.Clear();
		}
Exemplo n.º 42
0
        protected override void _PreRender()
        {
            _effectIntents = new EffectIntents();

            foreach(ElementNode node in TargetNodes) {
                foreach(Element element in node.GetElementEnumerator()) {
                    PositionValue startPosition = new PositionValue(StartPosition);
                    PositionValue endPosition = new PositionValue(EndPosition);
                    IIntent intent = new PositionIntent(startPosition, endPosition, TimeSpan);
                    _effectIntents.AddIntentForElement(element.Id, intent, TimeSpan.Zero);
                }
            }
        }
Exemplo n.º 43
0
        protected override void _PreRender(CancellationTokenSource cancellationToken = null)
        {
            _elementData = new EffectIntents();
            var targetNodes = TargetNodes.AsParallel();

            if (cancellationToken != null)
                targetNodes = targetNodes.WithCancellation(cancellationToken.Token);

            targetNodes.ForAll(node =>
            {
                if (node != null)
                    RenderNode(node);
            });
        }
Exemplo n.º 44
0
		protected override void _PreRender(CancellationTokenSource tokenSource = null)
		{
			_elementData = new EffectIntents();

			CommandValue value = new CommandValue(new StringCommand(string.Format("{0}|{1}", "RDS", _data.Title)));

			foreach (ElementNode node in TargetNodes) {
				if (tokenSource != null && tokenSource.IsCancellationRequested)
					return;
				 

				IIntent i = new CommandIntent(value, TimeSpan);
				_elementData.AddIntentForElement(node.Element.Id, i, TimeSpan.Zero);
			}
		}
Exemplo n.º 45
0
        protected override void _PreRender()
        {
            _intents = new EffectIntents();
            Channel[] channels = TargetNodes.SelectMany(x => x).ToArray();

            foreach(Channel channel in channels) {
                // Generating color intents...
                //ColorTransitionIntent intent = new ColorTransitionIntent(ColorGradient.Colors.First().Color.ToRGB(), ColorGradient.Colors.Last().Color.ToRGB(), TimeSpan);
                // Generating lighting intents...
                LightingValue startValue = new LightingValue(ColorGradient.Colors.First().Color.ToRGB(), 1);
                LightingValue endValue = new LightingValue(ColorGradient.Colors.Last().Color.ToRGB(), 1);
                LightingLinearIntent intent = new LightingLinearIntent(startValue, endValue, TimeSpan);
                _intents.AddIntentForChannel(channel.Id, intent, TimeSpan.Zero);
            }
        }
Exemplo n.º 46
0
		protected override void _PreRender(CancellationTokenSource cancellationToken = null)
		{
			_elementData = new EffectIntents();

			var value = new CommandValue(new StringCommand(string.Format("{0}|{1},{2}", "Launcher", _data.Executable, _data.Arguments)));

			foreach (var node in TargetNodes)
			{
				foreach (var elementNode in node.GetLeafEnumerator())
				{
					IIntent i = new CommandIntent(value, TimeSpan);
					_elementData.AddIntentForElement(elementNode.Element.Id, i, TimeSpan.Zero);	
				}
			}
				
		}
Exemplo n.º 47
0
        private static void AddIntentsToElement(Element element, double[] allPointsTimeOrdered, Curve levelCurve, ColorGradient colorGradient, TimeSpan duration, EffectIntents elementData, bool allowZeroIntensity, Color? color = null)
        {
            if (element != null)
            {
                double lastPosition = allPointsTimeOrdered[0];
                TimeSpan lastEnd = TimeSpan.Zero;
                for (var i = 1; i < allPointsTimeOrdered.Length; i++)
                {
                    double position = allPointsTimeOrdered[i];
                    TimeSpan startTime = lastEnd;
                    TimeSpan timeSpan = TimeSpan.FromMilliseconds(duration.TotalMilliseconds * (position - lastPosition));

                    if (color == null)
                    {
                        var startColor = colorGradient.GetColorAt(lastPosition);
                        var endColor = colorGradient.GetColorAt(position);
                        var startIntensity = levelCurve.GetValue(lastPosition * 100) / 100;
                        var endIntensity = levelCurve.GetValue(position * 100) / 100;

                        if (allowZeroIntensity || !(startIntensity.Equals(0) && endIntensity.Equals(0)))
                        {
                            IIntent intent = IntentBuilder.CreateIntent(startColor, endColor, startIntensity, endIntensity, timeSpan);
                            elementData.AddIntentForElement(element.Id, intent, startTime);
                        }
                    }
                    else
                    {
                        var startIntensity = (colorGradient.GetProportionOfColorAt(lastPosition, (Color)color) * levelCurve.GetValue(lastPosition * 100) / 100);
                        var endIntensity = (colorGradient.GetProportionOfColorAt(position, (Color)color) * levelCurve.GetValue(position * 100) / 100);

                        if (allowZeroIntensity || !(startIntensity.Equals(0) && endIntensity.Equals(0)))
                        {
                            IIntent intent = IntentBuilder.CreateDiscreteIntent((Color)color, startIntensity, endIntensity, timeSpan);
                            elementData.AddIntentForElement(element.Id, intent, startTime);
                        }

                    }

                    lastPosition = position;
                    lastEnd = startTime + timeSpan;
                }
            }
        }
Exemplo n.º 48
0
		protected override void _PreRender(CancellationTokenSource tokenSource = null)
		{
			_elementData = new EffectIntents();

			IEnumerable<ElementNode> targetNodes = GetNodesToRenderOn();

			List<IndividualTwinkleDetails> twinkles = null;
			if (!IndividualElements)
				twinkles = GenerateTwinkleData();

			int totalNodes = targetNodes.Count();
			double i = 0;

			foreach (ElementNode node in targetNodes) {
				if (tokenSource != null && tokenSource.IsCancellationRequested)
					return;

				if (node != null)
					_elementData.Add(RenderElement(node, i++/(double) totalNodes, twinkles));
			}
		}
Exemplo n.º 49
0
        protected override void _PreRender(CancellationTokenSource cancellationToken = null)
        {
            _elementData = new EffectIntents();

            foreach (ElementNode node in TargetNodes)
            {
                if (node != null)
                    _elementData.Add(RenderNode(node));
            }

            //_elementData = IntentBuilder.ConvertToStaticArrayIntents(_elementData, TimeSpan, IsDiscrete());
        }
Exemplo n.º 50
0
        private void DoRendering(CancellationTokenSource tokenSource = null)
        {
            //TODO: get a better increment time. doing it every X ms is..... shitty at best.
            TimeSpan increment = TimeSpan.FromMilliseconds(10);

            List<ElementNode> renderNodes = GetNodesToRenderOn();
            int targetNodeCount = renderNodes.Count;

            //If there are no nodes to render on Exit!
            if (targetNodeCount == 0) return;

            ElementNode lastTargetedNode = null;

            //Pulse.Pulse pulse;
            EffectIntents pulseData;

            // apply the 'background' values to all targets if nonzero
            if (EnableDefaultLevel) {
                int i = 0;
                foreach (ElementNode target in renderNodes)
                {
                    if (tokenSource != null && tokenSource.IsCancellationRequested) return;

                    bool discreteColors = ColorModule.isElementNodeDiscreteColored(target);

                    if (target == null)
                        continue;

                    if (target != null) {
                        double level = DefaultLevel*100.0;

                        // figure out what color gradient to use for the pulse
                        switch (ColorHandling) {
                            case SpinColorHandling.GradientForEachPulse:
                                pulseData = PulseRenderer.RenderNode(target,
                                    new Curve(new PointPairList(new double[] {0, 100}, new [] {level, level})), StaticColorGradient, TimeSpan, HasDiscreteColors, true);
                                _elementData.Add(pulseData);
                                break;

                            case SpinColorHandling.GradientThroughWholeEffect:
                                pulseData = PulseRenderer.RenderNode(target,
                                    new Curve(new PointPairList(new double[] { 0, 100 }, new [] { level, level })), ColorGradient, TimeSpan, HasDiscreteColors, true);
                                _elementData.Add(pulseData);
                                break;

                            case SpinColorHandling.StaticColor:
                                pulseData = PulseRenderer.RenderNode(target,
                                    new Curve(new PointPairList(new double[] {0, 100}, new[] {level, level})), StaticColorGradient, TimeSpan, HasDiscreteColors, true);
                                _elementData.Add(pulseData);
                                break;

                            case SpinColorHandling.ColorAcrossItems:
                                double positionWithinGroup = i/(double) targetNodeCount;
                                if (discreteColors) {
                                    List<Tuple<Color, float>> colorsAtPosition =
                                        ColorGradient.GetDiscreteColorsAndProportionsAt(positionWithinGroup);
                                    foreach (Tuple<Color, float> colorProportion in colorsAtPosition) {
                                        double value = level*colorProportion.Item2;
                                        pulseData = PulseRenderer.RenderNode(target,
                                            new Curve(new PointPairList(new double[] { 0, 100 }, new [] { value, value })), new ColorGradient(colorProportion.Item1), TimeSpan, HasDiscreteColors, true);
                                        _elementData.Add(pulseData);
                                    }
                                }
                                else {
                                    pulseData = PulseRenderer.RenderNode(target,
                                            new Curve(new PointPairList(new double[] { 0, 100 }, new double[] { level, level })), new ColorGradient(ColorGradient.GetColorAt(positionWithinGroup)), TimeSpan, HasDiscreteColors, true);
                                    _elementData.Add(pulseData);
                                }
                                break;
                        }

                        i++;
                    }
                }
            }

            // calculate the pulse time and revolution time exactly (based on the parameters from the data)
            double revTimeMs = 0; // single revolution time (ms)

            // figure out the relative length of a individual pulse
            double pulseConstant = 0; // how much of each pulse is a constant time
            double pulseFractional = 0; // how much of each pulse is a fraction of a single spin
            if (PulseLengthFormat == SpinPulseLengthFormat.FixedTime) {
                pulseConstant = PulseTime;
            }
            else if (PulseLengthFormat == SpinPulseLengthFormat.PercentageOfRevolution) {
                pulseFractional = PulsePercentage/100.0;
            }
            else if (PulseLengthFormat == SpinPulseLengthFormat.EvenlyDistributedAcrossSegments) {
                pulseFractional = 1.0/(double) targetNodeCount;
            }

            // magic number. (the inaccuracy of interpolating the curve into a position. eg. if we have 5 'positions', then
            // the curve should really be from 0-80% for the last spin, to make sure the last pulse finishes accurately.)
            double pulseInterpolationOffset = 1.0/(double) targetNodeCount;

            // figure out either the revolution count or time, based on what data we have
            if (SpeedFormat == SpinSpeedFormat.RevolutionCount) {
                revTimeMs = (TimeSpan.TotalMilliseconds - pulseConstant)/
                            (RevolutionCount + pulseFractional - pulseInterpolationOffset);
            }
            else if (SpeedFormat == SpinSpeedFormat.RevolutionFrequency) {
                revTimeMs = (1.0/RevolutionFrequency)*1000.0; // convert Hz to period ms
            }
            else if (SpeedFormat == SpinSpeedFormat.FixedTime) {
                revTimeMs = RevolutionTime;
            }

            double pulTimeMs = pulseConstant + (revTimeMs*pulseFractional);

            TimeSpan revTimeSpan = TimeSpan.FromMilliseconds(revTimeMs);
            TimeSpan pulseTimeSpan = TimeSpan.FromMilliseconds(pulTimeMs);

            // figure out which way we're moving through the elements
            Curve movement;
            if (ReverseSpin)
                movement = new Curve(new PointPairList(new double[] {0, 100}, new double[] {100, 0}));
            else
                movement = new Curve(new PointPairList(new double[] {0, 100}, new double[] {0, 100}));

            // iterate up to and including the last pulse generated
            // a bit iffy, but stops 'carry over' spins past the end (when there's overlapping spins). But we need to go past
            // (total - pulse) as the last pulse can often be a bit inaccurate due to the rounding of the increment
            for (TimeSpan current = TimeSpan.Zero; current <= TimeSpan - pulseTimeSpan + increment; current += increment) {
                if (tokenSource != null && tokenSource.IsCancellationRequested)
                    return;

                double currentPercentageIntoSpin = ((double) (current.Ticks%revTimeSpan.Ticks)/(double) revTimeSpan.Ticks)*100.0;

                double targetElementPosition = movement.GetValue(currentPercentageIntoSpin);
                int currentNodeIndex = (int) ((targetElementPosition/100.0)*targetNodeCount);

                // on the off chance we hit the 100% mark *exactly*...
                if (currentNodeIndex == targetNodeCount)
                    currentNodeIndex--;

                if (currentNodeIndex >= targetNodeCount) {
                    Logging.Warn(
                        "Spin effect: rendering, but the current node index is higher or equal to the total target nodes.");
                    continue;
                }

                ElementNode currentNode = renderNodes[currentNodeIndex];
                if (currentNode == lastTargetedNode)
                    continue;

                bool discreteColors = ColorModule.isElementNodeDiscreteColored(currentNode);

                // figure out what color gradient to use for the pulse
                switch (ColorHandling) {
                    case SpinColorHandling.GradientForEachPulse:
                        pulseData = PulseRenderer.RenderNode(currentNode, new Curve(PulseCurve), ColorGradient, pulseTimeSpan, HasDiscreteColors);
                        pulseData.OffsetAllCommandsByTime(current);
                        _elementData.Add(pulseData);
                        break;

                    case SpinColorHandling.GradientThroughWholeEffect:
                        double startPos = ((double) current.Ticks/(double) TimeSpan.Ticks);
                        double endPos = 1.0;
                        if (TimeSpan - current >= pulseTimeSpan)
                            endPos = ((double)(current + pulseTimeSpan).Ticks / (double)TimeSpan.Ticks);

                        if (discreteColors) {
                            double range = endPos - startPos;
                            if (range <= 0.0) {
                                Logging.Error("Spin: bad range: " + range + " (SP=" + startPos + ", EP=" + endPos + ")");
                                break;
                            }

                            ColorGradient cg = ColorGradient.GetSubGradientWithDiscreteColors(startPos, endPos);

                            foreach (Color color in cg.GetColorsInGradient()) {
                                if (tokenSource != null && tokenSource.IsCancellationRequested)
                                    return;
                                Curve newCurve = new Curve(PulseCurve.Points);
                                foreach (PointPair point in newCurve.Points)
                                {
                                    double effectRelativePosition = startPos + ((point.X / 100.0) * range);
                                    double proportion = ColorGradient.GetProportionOfColorAt(effectRelativePosition, color);
                                    point.Y *= proportion;
                                }
                                pulseData = PulseRenderer.RenderNode(currentNode, newCurve, new ColorGradient(color), pulseTimeSpan, HasDiscreteColors);
                                pulseData.OffsetAllCommandsByTime(current);
                                _elementData.Add(pulseData);
                            }
                        } else {
                            pulseData = PulseRenderer.RenderNode(currentNode, new Curve(PulseCurve), ColorGradient.GetSubGradient(startPos, endPos), pulseTimeSpan, HasDiscreteColors);
                            pulseData.OffsetAllCommandsByTime(current);
                            _elementData.Add(pulseData);
                        }
                        break;

                    case SpinColorHandling.StaticColor:
                        pulseData = PulseRenderer.RenderNode(currentNode, new Curve(PulseCurve), StaticColorGradient, pulseTimeSpan, HasDiscreteColors);
                        pulseData.OffsetAllCommandsByTime(current);
                        _elementData.Add(pulseData);
                        break;

                    case SpinColorHandling.ColorAcrossItems:
                        if (discreteColors) {
                            List<Tuple<Color, float>> colorsAtPosition = ColorGradient.GetDiscreteColorsAndProportionsAt(targetElementPosition / 100.0);
                            foreach (Tuple<Color, float> colorProportion in colorsAtPosition) {
                                if (tokenSource != null && tokenSource.IsCancellationRequested)
                                    return;

                                float proportion = colorProportion.Item2;
                                // scale all levels of the pulse curve by the proportion that is applicable to this color

                                Curve newCurve = new Curve(PulseCurve.Points);
                                foreach (PointPair pointPair in newCurve.Points)
                                {
                                    pointPair.Y *= proportion;
                                }
                                pulseData = PulseRenderer.RenderNode(currentNode, newCurve, new ColorGradient(colorProportion.Item1), pulseTimeSpan, HasDiscreteColors);
                                pulseData.OffsetAllCommandsByTime(current);
                                _elementData.Add(pulseData);
                            }
                        } else {
                            pulseData = PulseRenderer.RenderNode(currentNode, new Curve(PulseCurve), new ColorGradient(ColorGradient.GetColorAt(targetElementPosition / 100.0)), pulseTimeSpan, HasDiscreteColors);
                            pulseData.OffsetAllCommandsByTime(current);
                            _elementData.Add(pulseData);
                        }
                        break;
                }

                lastTargetedNode = currentNode;
            }

            _elementData = EffectIntents.Restrict(_elementData, TimeSpan.Zero, TimeSpan);
        }
Exemplo n.º 51
0
        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);

            }
        }
Exemplo n.º 52
0
        protected override void _PreRender(CancellationTokenSource tokenSource = null)
        {
            _elementData = new EffectIntents();

            foreach (ElementNode node in TargetNodes) {
                if (tokenSource != null && tokenSource.IsCancellationRequested)
                    return;

                if (node != null)
                {
                    _elementData = RenderNode(node);
                    //_elementData = IntentBuilder.ConvertToStaticArrayIntents(_elementData, TimeSpan, IsDiscrete());

                }
            }
        }
Exemplo n.º 53
0
        protected override void _PreRender(CancellationTokenSource tokenSource = null)
        {
            _elementData = new EffectIntents();

            DoRendering(tokenSource);

            //_elementData = IntentBuilder.ConvertToStaticArrayIntents(_elementData, TimeSpan, IsDiscrete());
        }
Exemplo n.º 54
0
        protected EffectIntents RenderNode(ElementNode node)
        {
            EffectIntents effectIntents = new EffectIntents();
            int nFrames = (int)(TimeSpan.TotalMilliseconds / FrameTime);
            if (nFrames <= 0) return effectIntents;
            var buffer = new PixelFrameBuffer(BufferWi, BufferHt, UseBaseColor?BaseColor:Color.Transparent);

            int bufferSize = StringPixelCounts.Sum();

            TimeSpan startTime = TimeSpan.Zero;

            // set up arrays to hold the generated colors
            var pixels = new RGBValue[bufferSize][];
            for (int eidx = 0; eidx < bufferSize; eidx++)
                pixels[eidx] = new RGBValue[nFrames];

            // generate all the pixels
            for (int frameNum = 0; frameNum < nFrames; frameNum++)
            {
                if (UseBaseColor)
                {
                    var level = BaseLevelCurve.GetValue(GetEffectTimeIntervalPosition(frameNum)*100)/100;
                    buffer.ClearBuffer(level);
                }
                else
                {
                    buffer.ClearBuffer();
                }

                RenderEffect(frameNum, ref buffer);
                // peel off this frames pixels...
                if (StringOrientation == StringOrientation.Horizontal)
                {
                    int i = 0;
                    for (int y = 0; y < BufferHt; y++)
                    {
                        for (int x = 0; x < StringPixelCounts[y]; x++)
                        {
                            pixels[i][frameNum] = new RGBValue(buffer.GetColorAt(x,y));
                            i++;
                        }
                    }
                }
                else
                {
                    int i = 0;
                    for (int x = 0; x < BufferWi; x++)
                    {
                        for (int y = 0; y < StringPixelCounts[x]; y++)
                        {
                            pixels[i][frameNum] = new RGBValue(buffer.GetColorAt(x, y));
                            i++;
                        }
                    }
                }
            };

            // create the intents
            var frameTs = new TimeSpan(0, 0, 0, 0, FrameTime);
            List<Element> elements = node.ToList();
            int numElements = node.Count();
            for (int eidx = 0; eidx < numElements; eidx++)
            {
                IIntent intent = new StaticArrayIntent<RGBValue>(frameTs, pixels[eidx], TimeSpan);
                effectIntents.AddIntentForElement(elements[eidx].Id, intent, startTime);
            }

            return effectIntents;
        }
Exemplo n.º 55
0
 private void RenderElement(GradientLevelPair gradientLevelPair, TimeSpan startTime, TimeSpan interval,
     ElementNode element, EffectIntents effectIntents)
 {
     var result = PulseRenderer.RenderNode(element, gradientLevelPair.Curve, gradientLevelPair.ColorGradient, interval, HasDiscreteColors);
     result.OffsetAllCommandsByTime(startTime);
     effectIntents.Add(result);
 }
Exemplo n.º 56
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 EffectIntents RenderNode(ElementNode node)
        {
            EffectIntents effectIntents = new EffectIntents();
            foreach (ElementNode elementNode in node.GetLeafEnumerator())
            {

                if (HasDiscreteColors && IsElementDiscrete(elementNode))
                {
                    IEnumerable<Color> colors = ColorModule.getValidColorsForElementNode(elementNode, false);
                    if (!colors.Contains(Color))
                    {
                        continue;
                    }
                }

                var intent = CreateIntent(elementNode, Color, (float)HSV.FromRGB(Color).V * IntensityLevel, TimeSpan);
                effectIntents.AddIntentForElement(elementNode.Element.Id, intent, TimeSpan.Zero);
            }

            return effectIntents;
        }
Exemplo n.º 57
0
        private void RenderElement(Pulse.Pulse pulse, GradientLevelPair gradientLevelPair, TimeSpan startTime,
            ElementNode element, EffectIntents effectIntents)
        {
            pulse.ColorGradient = gradientLevelPair.ColorGradient;
            pulse.LevelCurve = gradientLevelPair.Curve;
            pulse.TargetNodes = new[] { element };

            var result = pulse.Render();

            result.OffsetAllCommandsByTime(startTime);
            effectIntents.Add(result);
        }
Exemplo n.º 58
0
        private void DoRendering()
        {
            //TODO: get a better increment time. doing it every X ms is..... shitty at best.
            TimeSpan increment = TimeSpan.FromMilliseconds(2);

            List<ChannelNode> renderNodes = TargetNodes.SelectMany(x => x.GetLeafEnumerator()).ToList();
            int targetNodeCount = renderNodes.Count;

            Pulse.Pulse pulse;
            EffectIntents pulseData;

            // apply the 'background' values to all targets
            int i = 0;
            foreach (ChannelNode target in renderNodes) {
                pulse = new Pulse.Pulse();
                pulse.TargetNodes = new ChannelNode[] { target };
                pulse.TimeSpan = TimeSpan;
                pulse.LevelCurve = new Curve(new PointPairList(new double[] { 0, 100 }, new double[] { DefaultLevel * 100, DefaultLevel * 100 }));

                // figure out what color gradient to use for the pulse
                switch (ColorHandling) {
                    case ChaseColorHandling.GradientForEachPulse:
                        pulse.ColorGradient = new ColorGradient(StaticColor);
                        break;

                    case ChaseColorHandling.GradientThroughWholeEffect:
                        pulse.ColorGradient = ColorGradient;
                        break;

                    case ChaseColorHandling.StaticColor:
                        pulse.ColorGradient = new ColorGradient(StaticColor);
                        break;

                    case ChaseColorHandling.ColorAcrossItems:
                        pulse.ColorGradient = new ColorGradient(ColorGradient.GetColorAt((double)i / (double)targetNodeCount));
                        break;
                }

                pulseData = pulse.Render();
                _channelData.Add(pulseData);
                i++;
            }

            // the total chase time
            TimeSpan chaseTime = TimeSpan.FromMilliseconds(TimeSpan.TotalMilliseconds - PulseOverlap);
            if (chaseTime.TotalMilliseconds <= 0)
                chaseTime = TimeSpan.FromMilliseconds(1);

            // we need to keep track of the channel that is 'under' the curve at a given time, to see if it changes,
            // and when it does, we make the effect for it then (since it's a variable time pulse).
            ChannelNode lastTargetedNode = null;
            TimeSpan lastNodeStartTime = TimeSpan.Zero;

            // iterate up to and including the last pulse generated
            for (TimeSpan current = TimeSpan.Zero; current <= TimeSpan; current += increment) {
                double currentPercentageIntoChase = ((double)current.Ticks / (double)chaseTime.Ticks) * 100.0;

                double currentMovementPosition = ChaseMovement.GetValue(currentPercentageIntoChase);
                int currentNodeIndex = (int)((currentMovementPosition / 100.0) * targetNodeCount);

                // on the off chance we hit the 100% mark *exactly*...
                if (currentNodeIndex == targetNodeCount)
                    currentNodeIndex--;

                if (currentNodeIndex >= targetNodeCount) {
                    VixenSystem.Logging.Warning("Chase effect: rendering, but the current node index is higher or equal to the total target nodes.");
                    continue;
                }

                ChannelNode currentNode = renderNodes[currentNodeIndex];
                if (currentNode == lastTargetedNode)
                    continue;

                // if the last node targeted wasn't null, we need to make a pulse for it
                if (lastTargetedNode != null) {
                    GeneratePulse(lastTargetedNode, lastNodeStartTime, current - lastNodeStartTime + TimeSpan.FromMilliseconds(PulseOverlap), currentMovementPosition);
                }

                lastTargetedNode = currentNode;
                lastNodeStartTime = current;

                // if we've hit the 100% mark of the chase curve, bail (the last one gets generated after)
                if (currentPercentageIntoChase >= 100.0)
                    break;
            }

            // generate the last pulse
            if (lastTargetedNode != null) {
                GeneratePulse(lastTargetedNode, lastNodeStartTime, TimeSpan - lastNodeStartTime, 1.0);
            }

            _channelData = EffectIntents.Restrict(_channelData, TimeSpan.Zero, TimeSpan);
        }
Exemplo n.º 59
0
        //(Numbers represent color/curve pairs, rows are elements columns are intervals)
        //12341234
        //23412341
        //34123412
        //41234123
        //An offset of 2
        //12341234
        //34123412
        //12341234
        //34123412
        //Offset 3
        //12341234
        //41234123
        //23412341
        //12341234
        // 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 EffectIntents RenderNode(ElementNode node)
        {
            EffectIntents effectIntents = new EffectIntents();
            int intervals = 1;
            var gradientLevelItem = 0;
            var startIndexOffset = 0;
            //make local hold variables to prevent changes in the middle of rendering.
            int group = GroupLevel;
            var skip = IntervalSkipCount;
            int colorCount = Colors.Count();
            //Use a single pulse to do our work, we don't need to keep creating it and then thowing it away making the GC work
            //hard for no reason.

            if (!EnableStatic)
            {
                intervals = Convert.ToInt32(Math.Ceiling(TimeSpan.TotalMilliseconds/Interval));
            }

            var startTime = TimeSpan.Zero;
            var nodes = node.GetLeafEnumerator();

            var intervalTime = intervals == 1
                    ? TimeSpan
                    : TimeSpan.FromMilliseconds(Interval);

            for (int i = 0; i < intervals; i++)
            {
                var elements = nodes.Select((x, index) => new { x, index })
                    .GroupBy(x => x.index / group, y => y.x);

                foreach (IGrouping<int, ElementNode> elementGroup in elements)
                {
                    var glp = Colors[gradientLevelItem];
                    foreach (var element in elementGroup)
                    {
                        RenderElement(glp, startTime, intervalTime, element, effectIntents);
                    }
                    gradientLevelItem = ++gradientLevelItem % colorCount;

                }

                startIndexOffset = (skip+startIndexOffset) % colorCount;
                gradientLevelItem = startIndexOffset;

                startTime += intervalTime;
            }

            return effectIntents;
        }
Exemplo n.º 60
0
		protected override void _PreRender(CancellationTokenSource tokenSource = null)
		{

			_elementData = new EffectIntents();

			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();
					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();
					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();
					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();
					break;
				case WipeDirection.Out:
				case WipeDirection.In:
					RenderBurst(tokenSource, _data.Direction);

					return;

					break;
				default:
					break;
			}

			RenderNonBurst(tokenSource, renderNodes);
		}