示例#1
0
		public Status Effect(ElementEffect effect)
		{
			return ElementsHelper.Effect(effect);
		}
示例#2
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;
		}