Inheritance: EffectModuleInstanceBase
Beispiel #1
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;
		}
Beispiel #2
0
        // renders the given node to the internal ElementData dictionary. If the given node is
        // not a element, will recursively descend until we render its elements.
        private void RenderNode(ElementNode node)
        {
            EffectIntents result;
            LipSyncMapData mapData = null;
            List<ElementNode> renderNodes = TargetNodes.SelectMany(x => x.GetNodeEnumerator()).ToList();

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

                PhonemeType phoneme = (PhonemeType)System.Enum.Parse(typeof(PhonemeType), _data.StaticPhoneme);
                if (_library.Library.TryGetValue(_data.PhonemeMapping, out mapData))
                {

                    renderNodes.ForEach(delegate(ElementNode element)
                    {
                        LipSyncMapItem item = mapData.FindMapItem(element.Name);
                        if (item != null)
                        {
                            if (mapData.PhonemeState(element.Name, _data.StaticPhoneme, item))
                            {
                                var level = new SetLevel.SetLevel();
                                level.TargetNodes = new ElementNode[] { element };
                                level.Color = mapData.ConfiguredColor(element.Name, phoneme, item);
                                level.IntensityLevel = mapData.ConfiguredIntensity(element.Name, phoneme, item);
                                level.TimeSpan = TimeSpan;
                                result = level.Render();
                                _elementData.Add(result);
                            }

                        }
                    });

                }

            }
        }
Beispiel #3
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);
        }