WIP
DirectOutput framework for virtual pinball cabinets WIP
Go to:
Overview 
Configurator.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using DirectOutput.Cab;
5 using DirectOutput.Cab.Out;
6 using DirectOutput.Cab.Toys;
9 using DirectOutput.FX;
13 using DirectOutput.FX.RGBAFX;
15 using DirectOutput.FX.ValueFX;
16 using DirectOutput.General;
20 using DirectOutput.Table;
21 
22 namespace DirectOutput.LedControl.Setup
23 {
27  public class Configurator
28  {
32  public int EffectMinDurationMs = 60;
36  public int EffectRGBMinDurationMs = 120;
37 
46  {
47  Dictionary<int, TableConfig> TableConfigDict = LedControlConfigList.GetTableConfigDictonary(RomName);
48 
49  string IniFilePath = "";
50  if (LedControlConfigList.Count > 0)
51  {
52  IniFilePath = LedControlConfigList[0].LedControlIniFile.Directory.FullName;
53  }
54 
55  Dictionary<int, Dictionary<int, IToy>> ToyAssignments = SetupCabinet(TableConfigDict, Cabinet);
56 
57 
58 
59  SetupTable(Table, TableConfigDict, ToyAssignments, IniFilePath);
60 
61 
62  }
63 
64  private void SetupTable(Table.Table Table, Dictionary<int, TableConfig> TableConfigDict, Dictionary<int, Dictionary<int, IToy>> ToyAssignments, string IniFilePath)
65  {
66  foreach (KeyValuePair<int, TableConfig> KV in TableConfigDict)
67  {
68  int LedWizNr = KV.Key;
69  if (ToyAssignments.ContainsKey(LedWizNr))
70  {
71  TableConfig TC = KV.Value;
72 
73 
74  foreach (TableConfigColumn TCC in TC.Columns)
75  {
76 
77  if (ToyAssignments[LedWizNr].ContainsKey(TCC.Number))
78  {
79  IToy Toy = ToyAssignments[LedWizNr][TCC.Number];
80 
81  int SettingNumber = 0;
82  foreach (TableConfigSetting TCS in TCC)
83  {
84  SettingNumber++;
85  IEffect Effect = null;
86 
87  int Layer = (TCS.Layer.HasValue ? TCS.Layer.Value : SettingNumber);
88 
90  {
91 
92  if (!TCS.ShapeName.IsNullOrWhiteSpace())
93  {
94  if (Toy is IMatrixToy<RGBAColor>)
95  {
96  RGBAColor ActiveColor = null;
97  if (TCS.ColorConfig != null)
98  {
99  ActiveColor = TCS.ColorConfig.GetCabinetColor().GetRGBAColor();
100  }
101  else
102  {
103  if (!TCS.ColorName.IsNullOrWhiteSpace())
104  {
105  if (TCS.ColorName.StartsWith("#"))
106  {
107  ActiveColor = new RGBAColor();
108  if (!ActiveColor.SetColor(TCS.ColorName))
109  {
110  ActiveColor = null;
111  }
112  }
113  }
114  }
115 
116  Log.Debug("Setting up shape effect for area. L: {0}, T: {1}, W: {2}, H: {3}".Build(new object[] { TCS.AreaLeft, TCS.AreaTop, TCS.AreaWidth, TCS.AreaHeight }));
117  if (ActiveColor != null)
118  {
119  RGBAColor InactiveColor = ActiveColor.Clone();
120  InactiveColor.Alpha = 0;
121 
122  //Color defined. Use color scale effect
123 
124  Effect = new RGBAMatrixColorScaleShapeEffect() { ActiveColor = ActiveColor, InactiveColor = InactiveColor, LayerNr = Layer, ShapeName = TCS.ShapeName, Height = TCS.AreaHeight, Width = TCS.AreaWidth, Top = TCS.AreaTop, Left = TCS.AreaLeft, ToyName = Toy.Name };
125  }
126  else
127  {
128  //No color defined. Use org color effects
129  Effect = new RGBAMatrixShapeEffect() { LayerNr = Layer, ShapeName = TCS.ShapeName, Height = TCS.AreaHeight, Width = TCS.AreaWidth, Top = TCS.AreaTop, Left = TCS.AreaLeft, ToyName = Toy.Name };
130 
131  }
132 
133  }
134 
135  }
136  else if (TCS.IsBitmap)
137  {
138  FilePattern P = new FilePattern("{0}\\{1}.*".Build(IniFilePath, TC.ShortRomName));
139 
140  if (TCS.AreaBitmapAnimationStepCount > 1)
141  {
142  //it is a animation
143  if (Toy is IMatrixToy<RGBAColor>)
144  {
145 
146  Effect = new RGBAMatrixBitmapAnimationEffect() { BitmapFilePattern = P, BitmapLeft = TCS.AreaBitmapLeft, BitmapTop = TCS.AreaBitmapTop, BitmapHeight = TCS.AreaBitmapHeight, BitmapWidth = TCS.AreaBitmapWidth, BitmapFrameNumber = TCS.AreaBitmapFrame, AnimationStepDirection = TCS.AreaBitmapAnimationDirection, AnimationFrameDurationMs = TCS.AreaBitmapAnimationFrameDuration, AnimationFrameCount = TCS.AreaBitmapAnimationStepCount, AnimationStepSize = TCS.AreaBitmapAnimationStepSize, AnimationBehaviour = TCS.AreaBitmapAnimationBehaviour, Height = TCS.AreaHeight, Width = TCS.AreaWidth, Top = TCS.AreaTop, Left = TCS.AreaLeft, LayerNr = Layer, ToyName = Toy.Name };
147  }
148  else
149  {
150  Effect = new AnalogAlphaMatrixBitmapAnimationEffect() { BitmapFilePattern = P, BitmapLeft = TCS.AreaBitmapLeft, BitmapTop = TCS.AreaBitmapTop, BitmapHeight = TCS.AreaBitmapHeight, BitmapWidth = TCS.AreaBitmapWidth, BitmapFrameNumber = TCS.AreaBitmapFrame, AnimationStepDirection = TCS.AreaBitmapAnimationDirection, AnimationFrameDurationMs = TCS.AreaBitmapAnimationFrameDuration, AnimationFrameCount = TCS.AreaBitmapAnimationStepCount, AnimationStepSize = TCS.AreaBitmapAnimationStepSize, AnimationBehaviour = TCS.AreaBitmapAnimationBehaviour, Height = TCS.AreaHeight, Width = TCS.AreaWidth, Top = TCS.AreaTop, Left = TCS.AreaLeft, LayerNr = Layer, ToyName = Toy.Name };
151  }
152  }
153  else
154  {
155  //its a static bitmap
156  if (Toy is IMatrixToy<RGBAColor>)
157  {
158  Effect = new RGBAMatrixBitmapEffect() { BitmapFilePattern = P, BitmapLeft = TCS.AreaBitmapLeft, BitmapTop = TCS.AreaBitmapTop, BitmapHeight = TCS.AreaBitmapHeight, BitmapWidth = TCS.AreaBitmapWidth, BitmapFrameNumber = TCS.AreaBitmapFrame, Height = TCS.AreaHeight, Width = TCS.AreaWidth, Top = TCS.AreaTop, Left = TCS.AreaLeft, LayerNr = Layer, ToyName = Toy.Name };
159  }
160  else
161  {
162  Effect = new AnalogAlphaMatrixBitmapEffect() { BitmapFilePattern = P, BitmapLeft = TCS.AreaBitmapLeft, BitmapTop = TCS.AreaBitmapTop, BitmapHeight = TCS.AreaBitmapHeight, BitmapWidth = TCS.AreaBitmapWidth, BitmapFrameNumber = TCS.AreaBitmapFrame, Height = TCS.AreaHeight, Width = TCS.AreaWidth, Top = TCS.AreaTop, Left = TCS.AreaLeft, LayerNr = Layer, ToyName = Toy.Name };
163  }
164  }
165  }
166  else if (TCS.IsPlasma)
167  {
168  if (Toy is IMatrixToy<RGBAColor>)
169  {
170  RGBAColor InactiveColor = null;
171  RGBAColor ActiveColor1 = null;
172  RGBAColor ActiveColor2 = null;
173  if (TCS.ColorConfig != null)
174  {
175  ActiveColor1 = TCS.ColorConfig.GetCabinetColor().GetRGBAColor();
176  }
177  else
178  {
179  if (!TCS.ColorName.IsNullOrWhiteSpace())
180  {
181  if (TCS.ColorName.StartsWith("#"))
182  {
183  ActiveColor1 = new RGBAColor();
184  if (!ActiveColor1.SetColor(TCS.ColorName))
185  {
186  ActiveColor1 = null;
187  }
188  }
189  }
190  }
191 
192  if (TCS.ColorConfig2 != null)
193  {
194  ActiveColor2 = TCS.ColorConfig2.GetCabinetColor().GetRGBAColor();
195  }
196  else
197  {
198  if (!TCS.ColorName2.IsNullOrWhiteSpace())
199  {
200  if (TCS.ColorName2.StartsWith("#"))
201  {
202  ActiveColor2 = new RGBAColor();
203  if (!ActiveColor2.SetColor(TCS.ColorName2))
204  {
205  ActiveColor2 = null;
206  }
207  }
208  }
209  }
210 
211 
212  if (ActiveColor1 != null)
213  {
214  InactiveColor = ActiveColor1.Clone();
215  InactiveColor.Alpha = 0;
216  }
217  else if (ActiveColor2 != null)
218  {
219  InactiveColor = ActiveColor2.Clone();
220  InactiveColor.Alpha = 0;
221  }
222 
223  if (ActiveColor1 == null)
224  {
225  ActiveColor1 = new RGBAColor(0xff, 0, 0, 0xff);
226  }
227 
228  if (ActiveColor2 == null)
229  {
230  ActiveColor2 = new RGBAColor(0, 0xff, 0, 0xff);
231  }
232 
233 
234  Effect = new RGBAMatrixPlasmaEffect() { ActiveColor1 = ActiveColor1, ActiveColor2 = ActiveColor2, InactiveColor = InactiveColor, Height = TCS.AreaHeight, Width = TCS.AreaWidth, Top = TCS.AreaTop, Left = TCS.AreaLeft, LayerNr = Layer, PlasmaSpeed = TCS.PlasmaSpeed, PlasmaDensity = TCS.PlasmaDensity, ToyName = Toy.Name };
235  }
236  else
237  {
238 
239  }
240  }
241  else
242  {
243  //Non bitmap area effects
244  if (Toy is IMatrixToy<RGBAColor>)
245  {
246  //RGBAMatrix toy
247 
248  RGBAColor ActiveColor = null;
249  if (TCS.ColorConfig != null)
250  {
251  ActiveColor = TCS.ColorConfig.GetCabinetColor().GetRGBAColor();
252  }
253  else
254  {
255  if (!TCS.ColorName.IsNullOrWhiteSpace())
256  {
257  if (TCS.ColorName.StartsWith("#"))
258  {
259  ActiveColor = new RGBAColor();
260  if (!ActiveColor.SetColor(TCS.ColorName))
261  {
262  ActiveColor = null;
263  }
264  }
265  }
266  }
267 
268  if (ActiveColor != null)
269  {
270  RGBAColor InactiveColor = ActiveColor.Clone();
271  InactiveColor.Alpha = 0;
272  if (TCS.AreaDirection.HasValue)
273  {
274  //shift effect
275  Effect = new RGBAMatrixShiftEffect() { ShiftDirection = TCS.AreaDirection.Value, ShiftAcceleration = TCS.AreaAcceleration, ActiveColor = ActiveColor, InactiveColor = InactiveColor, Height = TCS.AreaHeight, Width = TCS.AreaWidth, Top = TCS.AreaTop, Left = TCS.AreaLeft, LayerNr = Layer, ToyName = Toy.Name };
276  if (TCS.AreaSpeed > 0)
277  {
278  ((RGBAMatrixShiftEffect)Effect).ShiftSpeed = TCS.AreaSpeed;
279  }
280 
281  }
282  else if (TCS.AreaFlickerDensity > 0)
283  {
284  //flicker effect
285  Effect = new RGBAMatrixFlickerEffect() { Density = TCS.AreaFlickerDensity.Limit(1, 99), ActiveColor = ActiveColor, InactiveColor = InactiveColor, Height = TCS.AreaHeight, Width = TCS.AreaWidth, Top = TCS.AreaTop, Left = TCS.AreaLeft, LayerNr = Layer, ToyName = Toy.Name };
286  if (TCS.AreaFlickerMinDurationMs > 0)
287  {
288  ((RGBAMatrixFlickerEffect)Effect).MinFlickerDurationMs = TCS.AreaFlickerMinDurationMs;
289  }
290  if (TCS.AreaFlickerMaxDurationMs > 0)
291  {
292  ((RGBAMatrixFlickerEffect)Effect).MaxFlickerDurationMs = TCS.AreaFlickerMaxDurationMs;
293  }
294  if (TCS.AreaFlickerFadeDurationMs > 0)
295  {
296  ((RGBAMatrixFlickerEffect)Effect).FlickerFadeDownDurationMs = TCS.AreaFlickerFadeDurationMs;
297  ((RGBAMatrixFlickerEffect)Effect).FlickerFadeUpDurationMs = TCS.AreaFlickerFadeDurationMs;
298  }
299  }
300  else
301  {
302  //Color effect
303  Effect = new RGBAMatrixColorEffect() { ActiveColor = ActiveColor, InactiveColor = InactiveColor, Height = TCS.AreaHeight, Width = TCS.AreaWidth, Top = TCS.AreaTop, Left = TCS.AreaLeft, LayerNr = Layer, ToyName = Toy.Name };
304  }
305 
306  }
307  else
308  {
309  Log.Warning("No color valid color definition found for area effect. Skipped setting {0} in column {1} for LedWizEqivalent number {2}.".Build(SettingNumber, TCC.Number, LedWizNr));
310 
311  }
312  }
313  else if (Toy is IMatrixToy<AnalogAlpha>)
314  {
315  AnalogAlpha ActiveValue = new AnalogAlpha(TCS.Intensity.Limit(0, 255), 255);
316  AnalogAlpha InactiveValue = ActiveValue.Clone();
317  InactiveValue.Alpha = 0;
318 
319 
320  if (TCS.AreaDirection.HasValue)
321  {
322  //shift effect
323  Effect = new AnalogAlphaMatrixShiftEffect() { ShiftDirection = TCS.AreaDirection.Value, ShiftAcceleration = TCS.AreaAcceleration, ActiveValue = ActiveValue, InactiveValue = InactiveValue, Height = TCS.AreaHeight, Width = TCS.AreaWidth, Top = TCS.AreaTop, Left = TCS.AreaLeft, LayerNr = Layer, ToyName = Toy.Name };
324  if (TCS.AreaSpeed > 0)
325  {
326  ((AnalogAlphaMatrixShiftEffect)Effect).ShiftSpeed = TCS.AreaSpeed;
327  }
328 
329  }
330  else if (TCS.AreaFlickerDensity > 0)
331  {
332  //flicker effect
333  Effect = new AnalogAlphaMatrixFlickerEffect() { Density = TCS.AreaFlickerDensity.Limit(1, 99), ActiveValue = ActiveValue, InactiveValue = InactiveValue, Height = TCS.AreaHeight, Width = TCS.AreaWidth, Top = TCS.AreaTop, Left = TCS.AreaLeft, LayerNr = Layer, ToyName = Toy.Name };
334  if (TCS.AreaFlickerMinDurationMs > 0)
335  {
336  ((AnalogAlphaMatrixFlickerEffect)Effect).MinFlickerDurationMs = TCS.AreaFlickerMinDurationMs;
337  }
338  if (TCS.AreaFlickerMaxDurationMs > 0)
339  {
340  ((AnalogAlphaMatrixFlickerEffect)Effect).MaxFlickerDurationMs = TCS.AreaFlickerMaxDurationMs;
341  }
342  if (TCS.AreaFlickerFadeDurationMs > 0)
343  {
344  ((AnalogAlphaMatrixFlickerEffect)Effect).FlickerFadeDownDurationMs = TCS.AreaFlickerFadeDurationMs;
345  ((AnalogAlphaMatrixFlickerEffect)Effect).FlickerFadeUpDurationMs = TCS.AreaFlickerFadeDurationMs;
346  }
347 
348  }
349  else
350  {
351  //Color effect
352  Effect = new AnalogAlphaMatrixValueEffect() { ActiveValue = ActiveValue, InactiveValue = InactiveValue, Height = TCS.AreaHeight, Width = TCS.AreaWidth, Top = TCS.AreaTop, Left = TCS.AreaLeft, LayerNr = Layer, ToyName = Toy.Name };
353  }
354 
355  }
356  }
357  }
358  else if (Toy is IRGBAToy)
359  {
360  RGBAColor ActiveColor = null;
361  if (TCS.ColorConfig != null)
362  {
363  ActiveColor = TCS.ColorConfig.GetCabinetColor().GetRGBAColor();
364  }
365  else
366  {
367  if (!TCS.ColorName.IsNullOrWhiteSpace())
368  {
369  if (TCS.ColorName.StartsWith("#"))
370  {
371  ActiveColor = new RGBAColor();
372  if (!ActiveColor.SetColor(TCS.ColorName))
373  {
374  ActiveColor = null;
375  Log.Warning("Skipped setting {0} in column {1} for LedWizEqivalent number {2} since {3} is not a valid color specification.".Build(new object[] { SettingNumber, TCC.Number, LedWizNr, TCS.ColorName }));
376  }
377  }
378  else
379  {
380  Log.Warning("Skipped setting {0} in column {1} for LedWizEqivalent number {2} since {3} is not a valid color specification.".Build(new object[] { SettingNumber, TCC.Number, LedWizNr, TCS.ColorName }));
381  }
382  }
383  else
384  {
385  Log.Warning("Skipped setting {0} in column {1} for LedWizEqivalent number {2} since it does not contain a color specification.".Build(SettingNumber, TCC.Number, LedWizNr));
386  }
387  }
388  if (ActiveColor != null)
389  {
390  RGBAColor InactiveColor = ActiveColor.Clone();
391  InactiveColor.Alpha = 0;
392  Effect = new RGBAColorEffect() { ToyName = Toy.Name, LayerNr = Layer, ActiveColor = ActiveColor, InactiveColor = InactiveColor };
393  }
394 
395  }
396  else if (Toy is IAnalogAlphaToy)
397  {
398  AnalogAlpha ActiveValue = new AnalogAlpha(TCS.Intensity.Limit(0, 255), 255);
399  AnalogAlpha InactiveValue = ActiveValue.Clone();
400  InactiveValue.Alpha = 0;
401  Effect = new AnalogToyValueEffect() { ToyName = Toy.Name, LayerNr = Layer, ActiveValue = ActiveValue, InactiveValue = InactiveValue };
402 
403  }
404  if (Effect != null)
405  {
406  Effect.Name = "Ledwiz {0:00} Column {1:00} Setting {2:00} {3}".Build(new object[] { LedWizNr, TCC.Number, SettingNumber, Effect.GetType().Name });
407  MakeEffectNameUnique(Effect, Table);
408 
409  Table.Effects.Add(Effect);
410 
411  if (TCS.FadingUpDurationMs > 0 || TCS.FadingDownDurationMs > 0)
412  {
413  Effect = new FadeEffect() { Name = "Ledwiz {0:00} Column {1:00} Setting {2:00} FadeEffect".Build(LedWizNr, TCC.Number, SettingNumber), TargetEffectName = Effect.Name, FadeDownDuration = TCS.FadingDownDurationMs, FadeUpDuration = TCS.FadingUpDurationMs };
414  MakeEffectNameUnique(Effect, Table);
415  Table.Effects.Add(Effect);
416  }
417  if (TCS.Blink != 0 && TCS.BlinkIntervalMsNested > 0)
418  {
419  Effect = new BlinkEffect() { Name = "Ledwiz {0:00} Column {1:00} Setting {2:00} BlinkEffect Inner".Build(LedWizNr, TCC.Number, SettingNumber), TargetEffectName = Effect.Name, LowValue = TCS.BlinkLow, DurationActiveMs = (int)((double)TCS.BlinkIntervalMsNested * (double)TCS.BlinkPulseWidthNested / 100), DurationInactiveMs = (int)((double)TCS.BlinkIntervalMsNested * (100 - (double)TCS.BlinkPulseWidthNested) / 100) };
420  MakeEffectNameUnique(Effect, Table);
421  Table.Effects.Add(Effect);
422  }
423 
424 
425  if (TCS.Blink != 0)
426  {
427  Effect = new BlinkEffect() { Name = "Ledwiz {0:00} Column {1:00} Setting {2:00} BlinkEffect".Build(LedWizNr, TCC.Number, SettingNumber), TargetEffectName = Effect.Name, DurationActiveMs = (int)((double)TCS.BlinkIntervalMs * (double)TCS.BlinkPulseWidth / 100), DurationInactiveMs = (int)((double)TCS.BlinkIntervalMs * (100 - (double)TCS.BlinkPulseWidth) / 100) };
428  if (TCS.BlinkIntervalMsNested == 0)
429  {
430  ((BlinkEffect)Effect).LowValue = TCS.BlinkLow;
431  }
432  MakeEffectNameUnique(Effect, Table);
433  Table.Effects.Add(Effect);
434  }
435 
436  if (TCS.DurationMs > 0 || TCS.Blink > 0)
437  {
438  int Duration = (TCS.DurationMs > 0 ? TCS.DurationMs : (TCS.Blink * 2 - 1) * TCS.BlinkIntervalMs / 2 + 1);
439  Effect = new DurationEffect() { Name = "Ledwiz {0:00} Column {1:00} Setting {2:00} DurationEffect".Build(LedWizNr, TCC.Number, SettingNumber), TargetEffectName = Effect.Name, DurationMs = Duration, RetriggerBehaviour = RetriggerBehaviourEnum.Restart };
440  MakeEffectNameUnique(Effect, Table);
441  Table.Effects.Add(Effect);
442  }
443  if (TCS.MaxDurationMs > 0)
444  {
445 
446  Effect = new MaxDurationEffect() { Name = "Ledwiz {0:00} Column {1:00} Setting {2:00} MaxDurationEffect".Build(new object[] { LedWizNr, TCC.Number, SettingNumber }), TargetEffectName = Effect.Name, MaxDurationMs = TCS.MaxDurationMs };
447  MakeEffectNameUnique(Effect, Table);
448  Table.Effects.Add(Effect);
449  }
450 
451 
452  if (TCS.MinDurationMs > 0 || (Toy is IRGBAToy && EffectRGBMinDurationMs > 0) || (!(Toy is IRGBAToy) && EffectMinDurationMs > 0))
453  {
454  string N = (TCS.MinDurationMs > 0 ? "MinDuratonEffect" : "DefaultMinDurationEffect");
455  int Min = (TCS.MinDurationMs > 0 ? TCS.MinDurationMs : (Toy is IRGBAToy ? EffectRGBMinDurationMs : EffectMinDurationMs));
456  Effect = new MinDurationEffect() { Name = "Ledwiz {0:00} Column {1:00} Setting {2:00} {3}".Build(new object[] { LedWizNr, TCC.Number, SettingNumber, N }), TargetEffectName = Effect.Name, MinDurationMs = Min };
457  MakeEffectNameUnique(Effect, Table);
458  Table.Effects.Add(Effect);
459  }
460 
461  if (TCS.ExtDurationMs > 0)
462  {
463  Effect = new ExtendDurationEffect() { Name = "Ledwiz {0:00} Column {1:00} Setting {2:00} ExtDurationEffect".Build(LedWizNr, TCC.Number, SettingNumber), TargetEffectName = Effect.Name, DurationMs = TCS.ExtDurationMs };
464  MakeEffectNameUnique(Effect, Table);
465  Table.Effects.Add(Effect);
466 
467  }
468 
469  if (TCS.WaitDurationMs > 0)
470  {
471  Effect = new DelayEffect() { Name = "Ledwiz {0:00} Column {1:00} Setting {2:00} DelayEffect".Build(LedWizNr, TCC.Number, SettingNumber), TargetEffectName = Effect.Name, DelayMs = TCS.WaitDurationMs };
472  MakeEffectNameUnique(Effect, Table);
473  Table.Effects.Add(Effect);
474  }
475 
476  if (TCS.Invert)
477  {
478  Effect = new ValueInvertEffect() { Name = "Ledwiz {0:00} Column {1:00} Setting {2:00} ValueInvertEffect".Build(LedWizNr, TCC.Number, SettingNumber), TargetEffectName = Effect.Name };
479  MakeEffectNameUnique(Effect, Table);
480  Table.Effects.Add(Effect);
481  }
482  if (!TCS.NoBool)
483  {
484 
485  Effect = new ValueMapFullRangeEffect() { Name = "Ledwiz {0:00} Column {1:00} Setting {2:00} FullRangeEffect".Build(LedWizNr, TCC.Number, SettingNumber), TargetEffectName = Effect.Name };
486  MakeEffectNameUnique(Effect, Table);
487  Table.Effects.Add(Effect);
488 
489 
490  }
491  switch (TCS.OutputControl)
492  {
493  case OutputControlEnum.Condition:
494 
495  Effect = new TableElementConditionEffect() { Name = "Ledwiz {0:00} Column {1:00} Setting {2:00} TableElementConditionEffect".Build(LedWizNr, TCC.Number, SettingNumber), TargetEffectName = Effect.Name, Condition = TCS.Condition };
496  MakeEffectNameUnique(Effect, Table);
497  Table.Effects.Add(Effect);
498 
499  AssignEffectToTableElements(Table, ((TableElementConditionEffect)Effect).GetVariables().ToArray(), Effect);
500 
501  break;
502 
503 
504  case OutputControlEnum.FixedOn:
506  break;
507  case OutputControlEnum.Controlled:
508 
509  string[] ATE = TCS.TableElement.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Select(A => A.Trim()).ToArray();
510  AssignEffectToTableElements(Table, ATE, Effect);
511 
512  break;
513  case OutputControlEnum.FixedOff:
514  default:
515  break;
516  }
517  }
518  }
519 
520 
521  }
522  }
523  }
524  }
525  }
526 
527 
528  private void AssignEffectToTableElements(Table.Table Table, string[] TableElementDescriptors, IEffect Effect)
529  {
530  foreach (string D in TableElementDescriptors)
531  {
532  TableElement TE = null;
533  if (D[0] == (char)TableElementTypeEnum.NamedElement)
534  {
535  //Log.Write("Adding table element: " + D);
536  Table.TableElements.UpdateState(new Table.TableElementData(D.Substring(1), 0));
537  TE = Table.TableElements[D.Substring(1)];
538  }
539  else if (Enum.IsDefined(typeof(TableElementTypeEnum), (int)D[0]) && D.Substring(1).IsInteger())
540  {
541  Table.TableElements.UpdateState(new Table.TableElementData((TableElementTypeEnum)D[0], D.Substring(1).ToInteger(), 0));
542  TE = Table.TableElements[(TableElementTypeEnum)D[0], D.Substring(1).ToInteger()];
543  }
544  TE.AssignedEffects.Add(new AssignedEffect(Effect.Name));
545  }
546  }
547 
548 
549 
550  private void MakeEffectNameUnique(IEffect Effect, Table.Table Table)
551  {
552  if (Table.Effects.Contains(Effect.Name))
553  {
554  int Cnt = 1;
555  while (Table.Effects.Contains("{0} {1}".Build(Effect.Name, Cnt)))
556  {
557  Cnt++;
558  }
559  Effect.Name = "{0} {1}".Build(Effect.Name, Cnt);
560  }
561  }
562 
563 
564 
565 
566 
567  private Dictionary<int, Dictionary<int, IToy>> SetupCabinet(Dictionary<int, TableConfig> TableConfigDict, Cabinet Cabinet)
568  {
569  Dictionary<int, Dictionary<int, IToy>> ToyAssignments = new Dictionary<int, Dictionary<int, IToy>>();
570 
571  Dictionary<int, LedWizEquivalent> LedWizEquivalentDict = new Dictionary<int, LedWizEquivalent>();
572  foreach (IToy T in Cabinet.Toys.Where(Toy => Toy is LedWizEquivalent).ToList())
573  {
574  if (!LedWizEquivalentDict.Keys.Any(K => K == ((LedWizEquivalent)T).LedWizNumber))
575  {
576  LedWizEquivalentDict.Add(((LedWizEquivalent)T).LedWizNumber, (LedWizEquivalent)T);
577  }
578  else
579  {
580  Log.Warning("Found more than one ledwiz with number {0}.".Build(((LedWizEquivalent)T).LedWizNumber));
581 
582  }
583  }
584 
585  foreach (KeyValuePair<int, TableConfig> KV in TableConfigDict)
586  {
587  int LedWizNr = KV.Key;
588  ToyAssignments.Add(LedWizNr, new Dictionary<int, IToy>());
589 
590  TableConfig TC = KV.Value;
591  if (LedWizEquivalentDict.ContainsKey(LedWizNr))
592  {
593  LedWizEquivalent LWE = LedWizEquivalentDict[LedWizNr];
594 
595  foreach (TableConfigColumn TCC in TC.Columns)
596  {
597  IToy TargetToy = null;
598 
599  if (TCC.IsArea)
600  {
601  if (LWE.Outputs.Any(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber))
602  {
603  string OutputName = LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber).OutputName;
604  if (Cabinet.Toys.Any(O => (O is IMatrixToy<RGBAColor> || O is IMatrixToy<AnalogAlpha>) && O.Name == OutputName))
605  {
606 
607 
608  TargetToy = (IToy)Cabinet.Toys.FirstOrDefault(O => (O is IMatrixToy<RGBAColor> || O is IMatrixToy<AnalogAlpha>) && O.Name == OutputName);
609 
610 
611  }
612  else
613  {
614  Log.Warning("Unknown toyname {0} defined for column {1} of LedwizEquivalent {2} (must be a matrix toy).".Build(OutputName, TCC.FirstOutputNumber, LWE.Name));
615  }
616  }
617  }
618  else
619  {
620 
621  switch (TCC.RequiredOutputCount)
622  {
623  case 3:
624  //RGB Led
625 
626  if (LWE.Outputs.Any(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber))
627  {
628  string OutputName = LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber).OutputName;
629  if (Cabinet.Toys.Any(O => O is IRGBAToy && O.Name == OutputName))
630  {
631  TargetToy = (IToy)Cabinet.Toys.FirstOrDefault(O => O is IRGBAToy && O.Name == OutputName);
632  }
633  }
634  if (TargetToy == null)
635  {
636  if (LWE.Outputs.Any(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber) && LWE.Outputs.Any(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber + 1) && LWE.Outputs.Any(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber + 2))
637  {
638  //Try to get the toy
639  try
640  {
641  //Toy does already exist
642  TargetToy = (IToy)Cabinet.Toys.First(Toy => Toy is IRGBOutputToy && ((IRGBOutputToy)Toy).OutputNameRed == LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber).OutputName && ((IRGBOutputToy)Toy).OutputNameGreen == LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber + 1).OutputName && ((IRGBOutputToy)Toy).OutputNameBlue == LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber + 2).OutputName);
643 
644  }
645  catch
646  {
647  //Toy does not exist. Create toyname and toy
648  string ToyName = "LedWiz {0:00} Column {1:00}".Build(LedWizNr, TCC.Number);
649  if (Cabinet.Toys.Contains(ToyName))
650  {
651  int Cnt = 1;
652  while (Cabinet.Toys.Contains("{0} {1}".Build(ToyName, Cnt)))
653  {
654  Cnt++;
655  }
656  ToyName = "{0} {1}".Build(ToyName, Cnt);
657  }
658  // if (Cabinet.Outputs.Contains(LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber).OutputName) && Cabinet.Outputs.Contains(LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber + 1).OutputName) && Cabinet.Outputs.Contains(LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber + 2).OutputName))
659  // {
660  TargetToy = (IToy)new RGBAToy() { Name = ToyName, OutputNameRed = LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber).OutputName, OutputNameGreen = LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber + 1).OutputName, OutputNameBlue = LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber + 2).OutputName };
661  Cabinet.Toys.Add(TargetToy);
662  // }
663  // else
664  // {
665  // Log.Warning("Unknown OutputName or ToyName defined for columns {0}-{1} (at least one of the 3) of LedWizEquivalent {2}.".Build(TCC.FirstOutputNumber, TCC.FirstOutputNumber + 3, LWE.Name));
666  // }
667  }
668 
669 
670  }
671  }
672 
673  break;
674  case 1:
675  //Single output
676 
677  //Analog output
678 
679  if (LWE.Outputs.Any(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber))
680  {
681  string OutputName = LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber).OutputName;
682  if (Cabinet.Toys.Any(O => O is IAnalogAlphaToy && O.Name == OutputName))
683  {
684  TargetToy = (IToy)Cabinet.Toys.FirstOrDefault(O => O is IAnalogAlphaToy && O.Name == OutputName);
685  }
686  }
687  if (TargetToy == null)
688  {
689 
690 
691  if (LWE.Outputs.Any(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber))
692  {
693  try
694  {
695  TargetToy = Cabinet.Toys.First(Toy => Toy is ISingleOutputToy && ((ISingleOutputToy)Toy).OutputName == LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber).OutputName);
696  }
697  catch
698  {
699  //Toy does not exist. Create toyname and toy
700  string ToyName = "LedWiz {0:00} Column {1:00}".Build(LedWizNr, TCC.Number);
701 
702  if (Cabinet.Toys.Contains(ToyName))
703  {
704  int Cnt = 1;
705  while (Cabinet.Toys.Contains("{0} {1}".Build(ToyName, Cnt)))
706  {
707  Cnt++;
708  }
709  ToyName = "{0} {1}".Build(ToyName, Cnt);
710  }
711  // if (Cabinet.Outputs.Contains(LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber).OutputName))
712  // {
713  TargetToy = (IToy)new AnalogAlphaToy() { Name = ToyName, OutputName = LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber).OutputName };
714  Cabinet.Toys.Add(TargetToy);
715  // }
716  // else
717  // {
718  // Log.Warning("Unknow ToyName or OutputName {0} defined for column {1} of LedwizEquivalent {2}.".Build(LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber).OutputName, TCC.FirstOutputNumber, LWE.Name));
719  // }
720  }
721 
722  }
723 
724  }
725 
726  break;
727 
728  default:
729  //Unknow value
730  Log.Warning("A illegal number ({0}) of required outputs has been found in a table config colum {0} for ledcontrol nr. {2}. Cant configure toy.".Build(TCC.RequiredOutputCount, TCC.Number, LedWizNr));
731  break;
732  }
733  }
734 
735  if (TargetToy != null)
736  {
737 
738  ToyAssignments[LedWizNr].Add(TCC.Number, TargetToy);
739  }
740  }
741  }
742  }
743  return ToyAssignments;
744  }
745 
746 
747  }
748 }
bool Invert
Gets or sets a value indicating whether the trigger value for the effect is inverted.
Namespace for effects controlling AnalogToy objects.
Definition: AnalogToyFX.cs:5
This effect fades towards the value passed to the effect in the TableElementData of the trigger metho...
Definition: FadeEffect.cs:12
Namespace for effects which trigger target effects based on conditions.
Definition: ConditionFX.cs:5
The Cabinet object describes the parts of a pinball cabinet (toys, outputcontrollers, outputs and more).
Definition: Cabinet.cs:17
Does create random flickering with a defineable density, durations and color within the spefied area ...
This class stores information on colors used for toys and effects (e.g. RGBLed).
Definition: RGBAColor.cs:14
AssignedEffectList AssignedEffects
List of effects which are assigned to the table element.
A single setting from a LedControl.ini file.
string OutputNameRed
Gets or sets the output name for red.
A table config from a ini file.
Definition: TableConfig.cs:9
The namespace DirectOutput.Cab.Toys contains all toy related classes.
The effects sets the color of a RGBAToy based on the trigger value.
int ExtDurationMs
Gets or sets the extended duration for the effect in milliseconds.
This effect controlls sets the value and alpha channel of a analog alpha toy based on the trigger val...
AnalogAlpha Clone()
Clones this instance.
Definition: AnalogAlpha.cs:27
Common interface for toys supporting analog alpha layers.
LedWizEquivalentOutputList Outputs
Gets or sets the outputs of the LedWizEquivalent toy.
Common interface for RGB toys supporting several layers of color with alpha value.
Definition: IRGBAToy.cs:9
Duration effect which triggers a specified target effect for a specified duration. When this effect is triggered it triggers the target effect immediately with the same data it has received. After the specified duration it calls trigger on the target effect again with data for the same table elmenet, but with the value changed to 0.
bool Contains(string Name)
Checks if a INamedItem object with the specified name exists in the list.
Same kind of effect like the RGBAMatrixShift effect, but for AnalogAlpha elements (just about everyth...
AssignedEffectList AssignedStaticEffects
Gets or sets the static effects list for the table. AssignedEffects contained in AssignedStaticEffec...
Definition: Table.cs:201
Common interface for RGB toys supporting several layers of color with alpha value.
Definition: IRGBOutputToy.cs:9
Does create random flickering with a defineable density, durations and value within the spefied area ...
This effect evaluates the condition specified in the Condition property.
int Layer
Gets or sets the layer for the settings.
int BlinkIntervalMs
Gets or sets the blink interval in milliseconds.
OutputControlEnum
Used the specify how the output for a setting is controled.
DirectOutput.Cab.Toys.ToyList Toys
List of IToy objects describing the toys in the cabinet.
Definition: Cabinet.cs:107
Object containing a analog value (0-255) and a alpha value (0-255).
Definition: AnalogAlpha.cs:11
TableElementTypeEnum
Enum for the different TableElement types.
string ColorName
Gets or sets the name of the color of the setting. This should only be set for RGB outputs...
Sets the spefied area of matrix to the specified colors depending on the trigger value.
int DurationMs
Gets or sets the duration in milliseconds.
Displays a shape on a RGBA matrix (typically a ledstrip matrix). The color of the displayed shape is ...
Column in a LedControl.ini file. Is a list of TableConfigSettingObjects for that column...
new string Name
Name of the effect.
Definition: IEffect.cs:53
string ShortRomName
Gets or sets the short name of the rom.
Definition: TableConfig.cs:18
Limits the max duration of the effect to the specified number of milliseconds.
Displays a shape on a RGBA matrix (typically a ledstrip array). The color of the displayed shape is c...
void Setup(LedControlConfigList LedControlConfigList, DirectOutput.Table.Table Table, Cabinet Cabinet, string RomName)
Configures the system based on the data loaded from ini files.
Definition: Configurator.cs:45
RGBAColor GetRGBAColor()
Gets a new RGBAColor instance with the same color values.
Definition: RGBAColor.cs:99
Common interface for all toy implementations. The abstract class ToyBase implements this interface...
Definition: IToy.cs:9
int Alpha
The alpha value (0-255).
Definition: AnalogAlpha.cs:20
RGBAColorNamed GetCabinetColor()
Gets a cabinet RGBAColor object representing the values in the ColorConfig object-.
Definition: ColorConfig.cs:18
Dictionary< int, TableConfig > GetTableConfigDictonary(string RomName)
Gets a dictionary of table configs for a specific romname from the loaded ini file data...
bool NoBool
Indicates the the trigger value of the effect is not to be treated as a boolean value resp...
The extend duration effect triggers another effect for a duration which is extebnded by the number of...
Namespace for timmed effects (e.g. delay, duration)
Definition: BlinkEffect.cs:7
Displayes a classical plasma effect on a RGBA matrix/ledstrip array. For more details on the math of ...
string TableElement
The table element triggering the effect (if available)
Common interface for all effects. If a new effect is implemented it is best to inherit from the abst...
Definition: IEffect.cs:13
The namespace DirectOutput.Cab contains all cabinet related classes like the Cabinet class itself...
Definition: Cab.cs:16
Has a condition (e.g. (S48=1 and S49=0)
DirectOutput.Cab.Out is the namespace for all output controller related classes like different output...
RetriggerBehaviourEnum
This enum describes the different retrigger behaviours for the effects. Retriggering means that a ef...
This toy handles analog values (0-255) in a layer structure including alpha value (0=completely trans...
int MinDurationMs
Gets or sets the minimum duration in milliseconds.
The DirectOutput.LedControl namespace contains the classes to read and understand the classical LedCo...
Definition: ColorConfig.cs:6
Sets the spefied area of matrix to the specified values depending on the trigger value.
Displays parts of a bitmap as a animation on a matrix of AnalogAlpha elements. Check the docu on the ...
TableElementList TableElements
Lists the TableElement objects for the Table. This list is automaticaly extend with new TableElement...
Definition: Table.cs:27
int Alpha
Alpha value for the color.
Definition: RGBAColor.cs:64
EffectList Effects
List of table specific effects.
Definition: Table.cs:187
RGBAColor Clone()
Clones this instance.
Definition: RGBAColor.cs:74
int Intensity
Gets or sets the intensity. If the property ColorName is set, this property will always return -1...
int BlinkPulseWidth
Gets or sets the width of the blink pulse. Value must be between 1 and 99 (defaults to 50)...
The RGBAMatrixBitmapEffect displays a defined part of a bitmap on a area of a RGBAtoy Matrix...
int BlinkPulseWidthNested
Gets or sets the width of the blink pulse for nested blinking. Value must be between 1 and 99 (defaul...
int FirstOutputNumber
Gets or sets the number of the first ouput for this column.
The RGBAMatrixBitmapAnimationEffect displays a anmation which is based on a image file on the definea...
The LEDWizEquivalent toy is only used by the framework when ini files are used for the configuration ...
int Number
Gets or sets the number of the column.
void UpdateState(TableElementData Data)
Method to update the state and/or add a entry to the list
new string Name
Gets or sets the Name of the IToy.
Definition: IToy.cs:17
void Add(string EffectName)
Adds the specified effect to the list.
TableConfigColumnList Columns
Gets or sets the columns in the table table config.
Definition: TableConfig.cs:31
List of LedControlConfig objects loaded from LedControl.ini files.
string Condition
The condition if available.
bool SetColor(int Red, int Green, int Blue, int Alpha)
Sets the RGBA components of the Color.
Definition: RGBAColor.cs:115
This namespace contains effects which deal with RGBA toys. /summary>
Namespace for objects dealing with layers
MatrixAnimationStepDirectionEnum AreaBitmapAnimationDirection
int RequiredOutputCount
Gets the number of required outputs for the column.
Thie RGBAToy controls RGB leds and other gadgets displaying RGB colors. The RGBAToy has multilayer ...
Definition: RGBAToy.cs:19
int FadingDownDurationMs
Gets or sets the duration for fading down in milliseconds.
The Table namespace contains all table specific classes like the Table class itself, TableElement and effect assigment classes.
Definition: Table.cs:14
int BlinkIntervalMsNested
Gets or sets the blink interval in milliseconds for nested blinking.
This effects maps the trigger value to the full range of 0 - 255. If the trigger value is 0...
Configures the system based on data from ini files (either directoutputconfig.ini or ledcontrol...
Definition: Configurator.cs:27
This effect enforces a minimum duration on the effect calls. Calls which are setting a effect to act...
Holds all table specific information and handles all TableElements
Definition: Table.cs:20
ColorConfig ColorConfig
Gets or sets the color config.
The namespace FX contains effect related classes. Effects can be assigned directly to a Table and wi...
Represents a element (e.g. Switch, Solenoid) of a pinball table
Definition: TableElement.cs:12
Inverts the trigger value of the effect before the target effect is called (e.g. 0 becomes 255...
Table()
Initializes a new instance of the Table class.
Definition: Table.cs:388
The namespace DirectOutput.General contains classes for general use.
int FadingUpDurationMs
Gets or sets the duration for fading up in milliseconds.
Effects in this namespace are controlling toys which implement the IMatrix interface ...
A file pattern class used to lookup files matching a specified pattern.
Definition: FilePattern.cs:12
int MaxDurationMs
Gets or sets the max duration for the effect in milliseconds.
int WaitDurationMs
Gets or sets the wait duration before the effect is triggered.
Displays a defined part of a bitmap on a area of a AnalogAlpha Matrix.
The effect fires a assigned target effect after a specified delay. The original values supplied when...
Definition: DelayEffect.cs:14
bool IsArea
Gets a value indicating whether any setting in the column has area values.
Handles the assignemt of a effect to a AssignedEffectList.
string Name
Name of the named item. Triggers BeforeNameChange before a new Name is set. Triggers AfterNameChang...
Effects which influence the trigger value, before a target effect is called.
Definition: ValueFX.cs:5
Basic IOutput implementation.
Definition: Output.cs:14
OutputControlEnum OutputControl
Defines the control mode for a output. It can be constantly on, off or it can be controlled by a elem...