Exemplo n.º 1
0
        private static void TurnOnElement(HttpRequestHead request, IHttpResponseDelegate response)
        {
            var status = new Status();
            NameValueCollection parms = GetParameters(request);

            if (!parms.HasKeys() && parms["id"] != null && parms["time"] != null && parms["color"]!=null)
            {
                HttpResponseHead headers = GetHeaders(0, HttpStatusCode.BadRequest.ToString());
                response.OnResponse(headers, new BufferedProducer(""));
                return;
            }

            if (parms["color"].Length != 7 || !parms["color"].StartsWith("#"))
            {
                status.Message = "Invalid color. Must be Hex.";
                SerializeResponse(status,response);
                return;
            }

            Guid elementId = Guid.Empty;
            bool allElements = false;
            int seconds;

            if ("all".Equals(parms["id"]))
            {
                allElements = true;
            } else
            {
                Guid.TryParse(parms["id"], out elementId);
            }
            if (!int.TryParse(parms["time"], out seconds))
            {
                status.Message = "Time must be numeric.";
                SerializeResponse(status,response);
                return;
            }

            Color elementColor = ColorTranslator.FromHtml(parms["color"]);

            //TODO the following logic for all does not properly deal with discrete color elements when turning all on
            //TODO they will not respond to turning on white if they are set up with a filter.
            //TODO enhance this to figure out what colors there are and turn them all on when we are turning all elements on.

            var effect = new SetLevel
            {
                TimeSpan = TimeSpan.FromSeconds(seconds),
                Color = elementColor,
                IntensityLevel = 1,
                TargetNodes =
                    allElements ? VixenSystem.Nodes.GetRootNodes().ToArray() : new[] {VixenSystem.Nodes.GetElementNode(elementId)}
            };

            Module.LiveSystemContext.Execute(new EffectNode(effect, TimeSpan.Zero));
            status.Message = string.Format("{0} element(s) turned on for {1} seconds at 100% intensity.",
                allElements?"All":VixenSystem.Nodes.GetElementNode(elementId).Name, seconds);

            SerializeResponse(status,response);
        }
Exemplo n.º 2
0
		public static Status TextOnElement(string id, string text, string color, int position, int direction, int seconds)
		{
			var status = new Status();
			if (string.IsNullOrEmpty(id))
			{
				throw new ArgumentException("id");
			}

			Guid elementId;
			if (!Guid.TryParse(id, out elementId))
			{
				throw new ArgumentException(@"Invalid element id", "id");
			}

			if (string.IsNullOrEmpty(text))
			{
				throw new ArgumentException(@"Text to display is null", "text");
			}

			if (string.IsNullOrEmpty(color))
			{
				throw new ArgumentException(@"Invalid color", "color");
			}

			if (color.Length != 7 || !color.StartsWith("#"))
			{
				throw new ArgumentException(@"Invalid color. Must be Hex.", "color");
			}
			Color elementColor = ColorTranslator.FromHtml(color);
			
			if (position > 100)
			{
				throw new ArgumentException(@"Position must be 0 - 100.", "position");
			}

			if (direction > 4)
			{
				throw new ArgumentException(@"Direction must be 0 - 4.", "direction");
			}

			var nutcrackerEffect = new Nutcracker
			{
				TimeSpan = TimeSpan.FromSeconds(seconds),
				NutcrackerData = new NutcrackerData
				{
					CurrentEffect = NutcrackerEffects.Effects.Text,
					Text_Top = position,
					Text_Direction = direction,
					Text_Line1 = text
				},

				TargetNodes = new[] { VixenSystem.Nodes.GetElementNode(elementId) }
			};
			nutcrackerEffect.NutcrackerData.Palette.SetColor(1, elementColor);

			Module.LiveContext.Execute(new EffectNode(nutcrackerEffect, TimeSpan.Zero));
			status.Message = string.Format("Text \"{0}\" applied to element {1} for {2} seconds.",
				VixenSystem.Nodes.GetElementNode(elementId).Name, text, seconds);

			return status;
		}
Exemplo n.º 3
0
		/// <summary>
		/// Experimental method to attempt to execute any type of effect. Unused at the moment and needs work.
		/// </summary>
		/// <param name="elementEffect"></param>
		/// <returns></returns>
		public static Status Effect(ElementEffect elementEffect)
		{
			if (elementEffect == null)
			{
				throw new ArgumentNullException("elementEffect");
			}

			ElementNode node = VixenSystem.Nodes.GetElementNode(elementEffect.Id);
			if ( node == null)
			{
				throw new ArgumentException(@"Invalid element id", @"elementEffect");
			}
			var status = new Status();

			IModuleDescriptor effectDescriptor = ApplicationServices.GetModuleDescriptors<IEffectModuleInstance>().Cast<IEffectModuleDescriptor>().FirstOrDefault(x => x.EffectName.Equals(elementEffect.EffectName));

			if (effectDescriptor != null)
			{
				var effect = ApplicationServices.Get<IEffectModuleInstance>(effectDescriptor.TypeId);
				EffectNode effectNode = CreateEffectNode(effect, node, TimeSpan.FromMilliseconds(elementEffect.Duration));

				Object[] newValues = effectNode.Effect.ParameterValues;
				int index = 0;
				foreach (var sig in effectNode.Effect.Parameters)
				{
					if (sig.Type == typeof(Color))
					{
						newValues[index] = ColorTranslator.FromHtml(elementEffect.Color.First().Key);
					}
					else
					{
						if (sig.Type == typeof(ColorGradient))
						{
							var cg = new ColorGradient();
							cg.Colors.Clear();
							foreach (var d in elementEffect.Color)
							{
								cg.Colors.Add(new ColorPoint(ColorTranslator.FromHtml(d.Key), d.Value));	
							}				
							newValues[index] = cg;
						}
						else
						{
							if (sig.Type == typeof(Curve))
							{

								var pointPairList = new PointPairList();
								foreach (KeyValuePair<double, double> keyValuePair in elementEffect.LevelCurve)
								{
									pointPairList.Add(keyValuePair.Key, keyValuePair.Value);
								}
								var curve = new Curve(pointPairList);
								newValues[index] = curve;
							}

						}
					}
					index++;
				}
				effectNode.Effect.ParameterValues = newValues;
				ApplyOptionParameters(effectNode, elementEffect.Options);
				Module.LiveContext.Execute(effectNode);
				status.Message = string.Format("{0} element(s) turned effect {1} for {2} milliseconds.",
				VixenSystem.Nodes.GetElementNode(elementEffect.Id).Name, elementEffect.EffectName, elementEffect.Duration);
			}
			
			return status;
		}
Exemplo n.º 4
0
		/// <summary>
		/// Turns on a given element with a SetLevel effect given the parameters. If the seconds are zero, the 
		/// effect will be given a duration of 30 days to simulate the element staying on. 
		/// </summary>
		/// <param name="id"></param>
		/// <param name="seconds"></param>
		/// <param name="intensity"></param>
		/// <param name="color"></param>
		/// <returns></returns>
		public static Status TurnOnElement(Guid id, int seconds, double intensity, string color)
		{
			ElementNode node = VixenSystem.Nodes.GetElementNode(id);
			if (node == null)
			{
				throw new ArgumentException(@"Invalid element id.", "id");
			}

			var status = new Status();

			if (!string.IsNullOrEmpty(color) && (color.Length != 7 || !	color.StartsWith("#")))
			{
				throw new ArgumentException(@"Invalid color", color);
			}

			if (intensity > 100 || intensity < 0)
			{
				intensity = 100;
			}
			
			var effect = new SetLevel
			{
				TimeSpan = seconds>0?TimeSpan.FromSeconds(seconds):TimeSpan.FromDays(30),
				IntensityLevel = intensity/100,
				TargetNodes = new[] { node }
			};

			//TODO check the passed color against the element to see if the element supports it
			if (!string.IsNullOrEmpty(color))
			{
				Color elementColor = ColorTranslator.FromHtml(color);
				effect.Color = elementColor;	
			}
			
			Module.LiveContext.Execute(new EffectNode(effect, TimeSpan.Zero));
			if (seconds == 0)
			{
				status.Message = string.Format("{0} turned on at {1}% intensity.",
				node.Name, intensity);	
			}
			else
			{
				status.Message = string.Format("{0} turned on for {1} seconds at {2}% intensity.",
				node.Name, seconds, intensity);	
			}
			

			return status;
		}
Exemplo n.º 5
0
		/// <summary>
		/// Turns off the element for a given node id. Looks for any active effects in the Live Context we 
		/// are using and clears them on that node. Does not distinguish between effects or who originated them.
		/// </summary>
		/// <param name="id"></param>
		/// <returns>Status</returns>
		public static Status TurnOffElement(Guid id)
		{
			var status = new Status();
			ElementNode node = VixenSystem.Nodes.GetElementNode(id);
			if (node != null)
			{
				Module.LiveContext.TerminateNode(node.Id);
				status.Message = string.Format("{0} turned off.", node.Name);
			}
			else
			{
				throw new ArgumentException(@"Element id is invalid", "id");
			}
			
			return status;
		}
Exemplo n.º 6
0
        private void PlaySequence(HttpRequestHead request, IHttpResponseDelegate response)
        {
            HttpResponseHead headers;
            var status = new Status();
            NameValueCollection parms = GetParameters(request);

            if(!parms.HasKeys() && parms["name"] != null)
            {
                headers = GetHeaders(0, HttpStatusCode.BadRequest.ToString());
                response.OnResponse(headers,new BufferedProducer(""));
                return;
            }

            string fileName = HttpUtility.UrlDecode(parms["name"]);
            if (_context != null && (_context.IsRunning))
            {
                status.Message = string.Format("Already playing {0}", _context.Sequence.Name);
            }
            else
            {
                ISequence sequence = SequenceService.Instance.Load(fileName);
                if (sequence == null)
                {
                    headers = GetOkHeaders(0);
                    headers.Status = HttpStatusCode.NotFound.ToString();
                    response.OnResponse(headers, new BufferedProducer(""));
                    return;
                }
                Logging.Info(string.Format("Web - Prerendering effects for sequence: {0}", sequence.Name));
                Parallel.ForEach(sequence.SequenceData.EffectData.Cast<IEffectNode>(), effectNode  => effectNode.Effect.PreRender());

                _context = VixenSystem.Contexts.CreateSequenceContext(new ContextFeatures(ContextCaching.NoCaching), sequence);
                _context.ContextEnded += context_ContextEnded;
                _context.Play(TimeSpan.Zero, sequence.Length);
                status.Message = string.Format("Playing sequence {0} of length {1}", sequence.Name, sequence.Length);
            }

            SerializeResponse(status,response);
        }
Exemplo n.º 7
0
 private void StopSequence(HttpRequestHead request, IHttpResponseDelegate response)
 {
     var status = new Status();
     if (_context != null && _context.IsRunning)
     {
         status.Message = string.Format("Stopping {0}", _context.Sequence.Name);
         _context.Stop();
     }
     else
     {
         status.Message = "Nothing playing.";
     }
     SerializeResponse(status,response);
 }
Exemplo n.º 8
0
        private void Status(HttpRequestHead request, IHttpResponseDelegate response)
        {
            var status = new Status();
            if (_context != null && _context.IsRunning)
            {
                status.Message = string.Format("{0} sequence is playing at position {1}", _context.Sequence.Name,
                    _context.GetTimeSnapshot());
            }
            else
            {
                status.Message = "Nothing playing.";
            }

            SerializeResponse(status,response);
        }