Example #1
0
 public static IIntent CreateIntent(Color startColor, Color endColor, double startIntensity, double endIntensity, TimeSpan duration)
 {
     var startValue = new LightingValue(startColor, startIntensity);
     var endValue = new LightingValue(endColor, endIntensity);
     IIntent intent = new LightingIntent(startValue, endValue, duration);
     return intent;
 }
Example #2
0
        private void _RenderCandleOnElement(Element element)
        {
            float startTime = 0;
            float endTime   = (float)TimeSpan.TotalMilliseconds;

            float currentLevel = _GenerateStartingLevel();

            while (startTime < endTime)
            {
                // What will our new value be?
                float currentLevelChange = _GenerateLevelChange();
                float nextLevel          = currentLevel + currentLevelChange;

                // Make sure we're still within our bounds.
                nextLevel = Math.Max(nextLevel, _data.MinLevel);
                nextLevel = Math.Min(nextLevel, _data.MaxLevel);

                // How long will this state last?
                float stateLength = _GenerateStateLength();

                // Make sure we don't exceed the end of the effect.
                stateLength = Math.Min(stateLength, endTime - startTime);

                // Add the intent.
                LightingValue startValue = new LightingValue(Color.White, currentLevel);
                LightingValue endValue   = new LightingValue(Color.White, nextLevel);
                IIntent       intent     = new LightingIntent(startValue, endValue, TimeSpan.FromMilliseconds(stateLength));
                _effectIntents.AddIntentForElement(element.Id, intent, TimeSpan.FromMilliseconds(startTime));

                startTime   += stateLength;
                currentLevel = nextLevel;
            }
        }
Example #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.
        private void RenderNode(ElementNode node)
        {
            foreach (Element element in node)
            {
                // 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 (element == null)
                {
                    continue;
                }

                double[] allPointsTimeOrdered = _GetAllSignificantDataPoints().ToArray();
                Debug.Assert(allPointsTimeOrdered.Length > 1);

                double lastPosition = allPointsTimeOrdered[0];
                for (int i = 1; i < allPointsTimeOrdered.Length; i++)
                {
                    double position = allPointsTimeOrdered[i];

                    LightingValue startValue = new LightingValue(ColorGradient.GetColorAt(lastPosition), (float)LevelCurve.GetValue(lastPosition * 100) / 100);
                    LightingValue endValue   = new LightingValue(ColorGradient.GetColorAt(position), (float)LevelCurve.GetValue(position * 100) / 100);

                    TimeSpan startTime = TimeSpan.FromMilliseconds(TimeSpan.TotalMilliseconds * lastPosition);
                    TimeSpan timeSpan  = TimeSpan.FromMilliseconds(TimeSpan.TotalMilliseconds * (position - lastPosition));

                    IIntent intent = new LightingIntent(startValue, endValue, timeSpan);

                    _elementData.AddIntentForElement(element.Id, intent, startTime);

                    lastPosition = position;
                }
            }
        }
Example #4
0
        /// <summary>
        /// When adding IntentNodes, check the existing nodes for IntentNodes that are consecutive... if they are consecutive, and the colors match, combine the Intents
        /// </summary>
        /// <param name="intentNodes"></param>
        public void AddRangeCombiner(IEnumerable <IIntentNode> intentNodes)
        {
            //AddRange(intentNodes);
            //return;
            // TODO: it looks like these only support LightingIntents. It should either be made generic, or the class made specific.
            foreach (var node in intentNodes)
            {
                var newIntent = node.Intent as LightingIntent;

                if (newIntent != null)
                {
                    var oldIntentNode = this.FirstOrDefault(nn => nn.EndTime.Equals(node.StartTime));
                    if (oldIntentNode != null)
                    {
                        var oldIntent = oldIntentNode.Intent as LightingIntent;
                        if (oldIntent != null && oldIntent.EndValue.FullColor.ToArgb() == newIntent.StartValue.FullColor.ToArgb() && CreateNewIntent(oldIntent, newIntent))
                        {
                            //Create a new IntentNode to replace the old one with the new values.
                            var lIntent = new LightingIntent(oldIntent.StartValue, newIntent.EndValue, oldIntent.TimeSpan.Add(newIntent.TimeSpan));

                            lIntent.GenericID = ((LightingIntent)oldIntentNode.Intent).GenericID;

                            var intentNode = new IntentNode(lIntent, oldIntentNode.StartTime);

                            this.Remove(oldIntentNode);
                            Add(intentNode);
                            continue;
                        }
                    }
                }

                Add(node);
            }
        }
Example #5
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);
                    }
                }
            }
        }
Example #6
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)
 {
     foreach (ElementNode elementNode in node.GetLeafEnumerator())
     {
         LightingValue lightingValue = new LightingValue(Color, (float)IntensityLevel);
         IIntent       intent        = new LightingIntent(lightingValue, lightingValue, TimeSpan);
         _elementData.AddIntentForElement(elementNode.Element.Id, intent, TimeSpan.Zero);
     }
 }
Example #7
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);
					}
				}
			}
		}
Example #8
0
        private void _RenderCandleOnElements(List <Element> elements)
        {
            TimeSpan startTime    = TimeSpan.Zero;
            double   currentLevel = _GenerateStartingLevel();

            while (startTime < TimeSpan)
            {
                // What will our new value be?
                double currentLevelChange = _GenerateLevelChange();
                double nextLevel          = currentLevel + currentLevelChange;

                // Make sure we're still within our bounds.
                nextLevel = Math.Max(nextLevel, _data.MinLevel);
                nextLevel = Math.Min(nextLevel, _data.MaxLevel);

                // How long will this state last?
                double stateLength = _GenerateStateLength();

                // Make sure we don't exceed the end of the effect.
                stateLength = Math.Min(stateLength, (TimeSpan - startTime).TotalMilliseconds);
                var length = TimeSpan.FromMilliseconds(stateLength);
                if (length == TimeSpan.Zero)
                {
                    length = TimeSpan.FromMilliseconds(1);
                }
                else
                {
                    // Add the intent.
                    LightingValue startValue = new LightingValue(Color, currentLevel);
                    LightingValue endValue   = new LightingValue(Color, nextLevel);

                    IIntent intent = new LightingIntent(startValue, endValue, length);
                    try
                    {
                        foreach (var element in elements)
                        {
                            if (element != null)
                            {
                                _effectIntents.AddIntentForElement(element.Id, intent, startTime);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Logging.Error("Error generating Candle intents", e);
                        throw;
                    }
                }

                startTime   += length;
                currentLevel = nextLevel;
            }
        }
Example #9
0
        private void addIntentsToElement(Element element, Color?color = null)
        {
            if (element != null)
            {
                double[] allPointsTimeOrdered = _GetAllSignificantDataPoints().ToArray();
                Debug.Assert(allPointsTimeOrdered.Length > 1);

                double   lastPosition = allPointsTimeOrdered[0];
                TimeSpan lastEnd      = TimeSpan.Zero;
                for (var i = 1; i < allPointsTimeOrdered.Length; i++)
                {
                    double position = allPointsTimeOrdered[i];

                    LightingValue startValue;
                    LightingValue endValue;
                    if (color == null)
                    {
                        startValue = new LightingValue(ColorGradient.GetColorAt(lastPosition),
                                                       LevelCurve.GetValue(lastPosition * 100) / 100);
                        endValue = new LightingValue(ColorGradient.GetColorAt(position), LevelCurve.GetValue(position * 100) / 100);
                    }
                    else
                    {
                        startValue = new LightingValue((Color)color,
                                                       (ColorGradient.GetProportionOfColorAt(lastPosition, (Color)color) *
                                                        LevelCurve.GetValue(lastPosition * 100) / 100));
                        endValue = new LightingValue((Color)color,
                                                     (ColorGradient.GetProportionOfColorAt(position, (Color)color) *
                                                      LevelCurve.GetValue(position * 100) / 100));
                    }

                    TimeSpan startTime = lastEnd;
                    TimeSpan timeSpan  = TimeSpan.FromMilliseconds(TimeSpan.TotalMilliseconds * (position - lastPosition));
                    if (startValue.Intensity.Equals(0f) && endValue.Intensity.Equals(0f))
                    {
                        lastPosition = position;
                        lastEnd      = startTime + timeSpan;
                        continue;
                    }

                    IIntent intent = new LightingIntent(startValue, endValue, timeSpan);

                    _elementData.AddIntentForElement(element.Id, intent, startTime);

                    lastPosition = position;
                    lastEnd      = startTime + timeSpan;
                }
            }
        }
Example #10
0
        private bool CreateNewIntent(LightingIntent oldIntent, LightingIntent newIntent)
        {
            //We can only combine intents if they are truly linear. i.e. start and end values of both are the same.
            //Anything else we cannot tell because it can vary based on timespan and start and end values what linear is especially in ramps.
            bool returnValue = false;

            try {
                if (oldIntent.StartValue.Intensity.Equals(oldIntent.EndValue.Intensity) && oldIntent.EndValue.Intensity.Equals(newIntent.StartValue.Intensity) &&
                    oldIntent.EndValue.Intensity.Equals(newIntent.EndValue.Intensity))
                {
                    returnValue = true;
                }
            } catch (Exception e) {
                Logging.ErrorException(e.Message, e);
            }
            return(returnValue);
        }
Example #11
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)
 {
     foreach(Element element in node) {
         LightingValue lightingValue = new LightingValue(Color, (float)IntensityLevel);
         IIntent intent = new LightingIntent(lightingValue, lightingValue, TimeSpan);
         _elementData.AddIntentForElement(element.Id, intent, TimeSpan.Zero);
     }
     //// if this node is an RGB node, then it will know what to do with it (might render directly,
     //// might be broken down into sub-elements, etc.) So just pass it off to that instead.
     //if (node.Properties.Contains(SetLevelDescriptor._RGBPropertyId)) {
     //    RenderRGB(node);
     //} else {
     //    if (node.IsLeaf) {
     //        RenderMonochrome(node);
     //    } else {
     //        foreach (ElementNode child in node.Children)
     //            RenderNode(child);
     //    }
     //}
 }
Example #12
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)
 {
     foreach (Element element in node)
     {
         LightingValue lightingValue = new LightingValue(Color, (float)IntensityLevel);
         IIntent       intent        = new LightingIntent(lightingValue, lightingValue, TimeSpan);
         _elementData.AddIntentForElement(element.Id, intent, TimeSpan.Zero);
     }
     //// if this node is an RGB node, then it will know what to do with it (might render directly,
     //// might be broken down into sub-elements, etc.) So just pass it off to that instead.
     //if (node.Properties.Contains(SetLevelDescriptor._RGBPropertyId)) {
     //    RenderRGB(node);
     //} else {
     //    if (node.IsLeaf) {
     //        RenderMonochrome(node);
     //    } else {
     //        foreach (ElementNode child in node.Children)
     //            RenderNode(child);
     //    }
     //}
 }
Example #13
0
        private void _RenderCandleOnElement(Element element)
        {
            float startTime = 0;
            float endTime = (float) TimeSpan.TotalMilliseconds;

            float currentLevel = _GenerateStartingLevel();

            while (startTime < endTime) {
                // What will our new value be?
                float currentLevelChange = _GenerateLevelChange();
                float nextLevel = currentLevel + currentLevelChange;

                // Make sure we're still within our bounds.
                nextLevel = Math.Max(nextLevel, _data.MinLevel);
                nextLevel = Math.Min(nextLevel, _data.MaxLevel);

                // How long will this state last?
                float stateLength = _GenerateStateLength();

                // Make sure we don't exceed the end of the effect.
                stateLength = Math.Min(stateLength, endTime - startTime);

                // Add the intent.
                LightingValue startValue = new LightingValue(Color.White, currentLevel);
                LightingValue endValue = new LightingValue(Color.White, nextLevel);
                IIntent intent = new LightingIntent(startValue, endValue, TimeSpan.FromMilliseconds(stateLength));
                try {
                    _effectIntents.AddIntentForElement(element.Id, intent, TimeSpan.FromMilliseconds(startTime));
                }
                catch (Exception e) {
                    Console.WriteLine(e.ToString());
                    throw;
                }
                startTime += stateLength;
                currentLevel = nextLevel;
            }
        }
Example #14
0
		private void _RenderCandleOnElements(List<Element> elements)
		{
			TimeSpan startTime = TimeSpan.Zero;
			double currentLevel = _GenerateStartingLevel();

			while (startTime < TimeSpan)
			{
				// What will our new value be?
				double currentLevelChange = _GenerateLevelChange();
				double nextLevel = currentLevel + currentLevelChange;

				// Make sure we're still within our bounds.
				nextLevel = Math.Max(nextLevel, _data.MinLevel);
				nextLevel = Math.Min(nextLevel, _data.MaxLevel);

				// How long will this state last?
				double stateLength = _GenerateStateLength();
				
				// Make sure we don't exceed the end of the effect.
				stateLength = Math.Min(stateLength, (TimeSpan - startTime).TotalMilliseconds);
				var length = TimeSpan.FromMilliseconds(stateLength);
				if (length == TimeSpan.Zero)
				{
					length = TimeSpan.FromMilliseconds(1);
				}
				else
				{
					// Add the intent.
					LightingValue startValue = new LightingValue(Color, currentLevel);
					LightingValue endValue = new LightingValue(Color, nextLevel);

					IIntent intent = new LightingIntent(startValue, endValue, length);
					try
					{
						foreach (var element in elements)
						{
							if (element != null)
							{
								_effectIntents.AddIntentForElement(element.Id, intent, startTime);
							}
						}
					}
					catch (Exception e)
					{
						Logging.Error("Error generating Candle intents", e);
						throw;
					}
				}
				
				startTime += length;	
				currentLevel = nextLevel;
			}
		}
Example #15
0
        // renders the given node to the internal ChannelData dictionary. If the given node is
        // not a channel, will recursively descend until we render its channels.
        private void RenderNode(ChannelNode node)
        {
            foreach(Channel channel in node) {
                // this is probably always going to be a single channel 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(channel == null)
                    continue;

                double[] allPointsTimeOrdered = _GetAllSignificantDataPoints().ToArray();
                Debug.Assert(allPointsTimeOrdered.Length > 1);

                double lastPosition = allPointsTimeOrdered[0];
                for(int i=1; i<allPointsTimeOrdered.Length; i++) {
                    double position = allPointsTimeOrdered[i];

                    LightingValue startValue = new LightingValue(ColorGradient.GetColorAt(lastPosition), (float)LevelCurve.GetValue(lastPosition * 100) / 100);
                    LightingValue endValue = new LightingValue(ColorGradient.GetColorAt(position), (float)LevelCurve.GetValue(position * 100) / 100);

                    TimeSpan startTime = TimeSpan.FromMilliseconds(TimeSpan.TotalMilliseconds * lastPosition);
                    TimeSpan timeSpan = TimeSpan.FromMilliseconds(TimeSpan.TotalMilliseconds * (position - lastPosition));

                    IIntent intent = new LightingIntent(startValue, endValue, timeSpan);

                    _channelData.AddIntentForChannel(channel.Id, intent, startTime);

                    lastPosition = position;
                }
            }
        }
Example #16
0
 public static IIntent CreateIntent(Color color, double intensity, TimeSpan duration)
 {
     LightingValue lightingValue = new LightingValue(color, intensity);
     IIntent intent = new LightingIntent(lightingValue, lightingValue, duration);
     return intent;
 }
Example #17
0
		private void addIntentsToElement(Element element, double[] allPointsTimeOrdered, 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];

					LightingValue startValue;
					LightingValue endValue;
					if (color == null)
					{
						startValue = new LightingValue(ColorGradient.GetColorAt(lastPosition),
													   LevelCurve.GetValue(lastPosition * 100) / 100);
						endValue = new LightingValue(ColorGradient.GetColorAt(position), LevelCurve.GetValue(position * 100) / 100);
					}
					else
					{
						startValue = new LightingValue((Color)color,
													   (ColorGradient.GetProportionOfColorAt(lastPosition, (Color)color) *
														LevelCurve.GetValue(lastPosition * 100) / 100));
						endValue = new LightingValue((Color)color,
													 (ColorGradient.GetProportionOfColorAt(position, (Color)color) *
													  LevelCurve.GetValue(position * 100) / 100));
					}

					TimeSpan startTime = lastEnd;
					TimeSpan timeSpan = TimeSpan.FromMilliseconds(TimeSpan.TotalMilliseconds * (position - lastPosition));
					if (startValue.Intensity.Equals(0f) && endValue.Intensity.Equals(0f))
					{
						lastPosition = position;
						lastEnd = startTime + timeSpan;
						continue;
					}

					IIntent intent = new LightingIntent(startValue, endValue, timeSpan);

					_elementData.AddIntentForElement(element.Id, intent, startTime);

					lastPosition = position;
					lastEnd = startTime + timeSpan;
				}
			}
		}
Example #18
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)
		{
			foreach (ElementNode elementNode in node.GetLeafEnumerator()) {
				LightingValue lightingValue = new LightingValue(Color, (float) IntensityLevel);
				IIntent intent = new LightingIntent(lightingValue, lightingValue, TimeSpan);
				_elementData.AddIntentForElement(elementNode.Element.Id, intent, TimeSpan.Zero);
			}
		}