2 using System.Collections.Generic;
4 using DirectOutput.Cab;
5 using DirectOutput.Cab.Out;
6 using DirectOutput.Cab.Toys;
7 using DirectOutput.Cab.Toys.Layer;
8 using DirectOutput.Cab.Toys.LWEquivalent;
10 using DirectOutput.FX.AnalogToyFX;
11 using DirectOutput.FX.ConditionFX;
12 using DirectOutput.FX.MatrixFX;
13 using DirectOutput.FX.RGBAFX;
14 using DirectOutput.FX.TimmedFX;
15 using DirectOutput.FX.ValueFX;
16 using DirectOutput.General;
17 using DirectOutput.General.Analog;
18 using DirectOutput.General.Color;
19 using DirectOutput.LedControl.Loader;
21 namespace DirectOutput.LedControl.Setup
31 public int EffectMinDurationMs = 60;
35 public int EffectRGBMinDurationMs = 120;
48 string IniFilePath =
"";
49 if (LedControlConfigList.Count > 0)
51 IniFilePath = LedControlConfigList[0].LedControlIniFile.Directory.FullName;
54 Dictionary<int, Dictionary<int, IToy>> ToyAssignments = SetupCabinet(TableConfigDict, Cabinet);
58 SetupTable(Table, TableConfigDict, ToyAssignments, IniFilePath);
63 private void SetupTable(Table.Table Table, Dictionary<int, TableConfig> TableConfigDict, Dictionary<
int, Dictionary<int, IToy>> ToyAssignments,
string IniFilePath)
65 foreach (KeyValuePair<int, TableConfig> KV
in TableConfigDict)
67 int LedWizNr = KV.Key;
68 if (ToyAssignments.ContainsKey(LedWizNr))
76 if (ToyAssignments[LedWizNr].ContainsKey(TCC.
Number))
78 IToy Toy = ToyAssignments[LedWizNr][TCC.
Number];
80 int SettingNumber = 0;
86 int Layer = (TCS.
Layer.HasValue ? TCS.
Layer.Value : SettingNumber);
88 if (Toy is IMatrixToy<RGBAColor> || Toy is IMatrixToy<AnalogAlpha>)
98 if (Toy is IMatrixToy<RGBAColor>)
100 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 };
104 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 };
110 if (Toy is IMatrixToy<RGBAColor>)
112 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 };
116 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 };
123 if (Toy is IMatrixToy<RGBAColor>)
147 if (ActiveColor != null)
150 InactiveColor.
Alpha = 0;
184 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));
188 else if (Toy is IMatrixToy<AnalogAlpha>)
192 InactiveValue.
Alpha = 0;
245 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 }));
250 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 }));
255 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));
258 if (ActiveColor != null)
261 InactiveColor.
Alpha = 0;
262 Effect =
new RGBAColorEffect() { ToyName = Toy.
Name, LayerNr = Layer, ActiveColor = ActiveColor, InactiveColor = InactiveColor };
270 InactiveValue.
Alpha = 0;
271 Effect =
new AnalogToyValueEffect() { ToyName = Toy.
Name, LayerNr = Layer, ActiveValue = ActiveValue, InactiveValue = InactiveValue };
276 Effect.
Name =
"Ledwiz {0:00} Column {1:00} Setting {2:00} {3}".Build(
new object[] { LedWizNr, TCC.Number, SettingNumber, Effect.GetType().
Name });
277 MakeEffectNameUnique(Effect, Table);
279 Table.Effects.Add(Effect);
284 MakeEffectNameUnique(Effect, Table);
285 Table.Effects.Add(Effect);
290 MakeEffectNameUnique(Effect, Table);
291 Table.Effects.Add(Effect);
302 MakeEffectNameUnique(Effect, Table);
303 Table.Effects.Add(Effect);
309 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 };
310 MakeEffectNameUnique(Effect, Table);
311 Table.Effects.Add(Effect);
316 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 };
317 MakeEffectNameUnique(Effect, Table);
318 Table.Effects.Add(Effect);
322 if (TCS.
MinDurationMs > 0 || (Toy is IRGBAToy && EffectRGBMinDurationMs > 0) || (!(Toy is IRGBAToy) && EffectMinDurationMs > 0))
324 string N = (TCS.
MinDurationMs > 0 ?
"MinDuratonEffect" :
"DefaultMinDurationEffect");
326 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 };
327 MakeEffectNameUnique(Effect, Table);
328 Table.Effects.Add(Effect);
333 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 };
334 MakeEffectNameUnique(Effect, Table);
335 Table.Effects.Add(Effect);
341 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 };
342 MakeEffectNameUnique(Effect, Table);
343 Table.Effects.Add(Effect);
348 Effect =
new ValueInvertEffect() { Name =
"Ledwiz {0:00} Column {1:00} Setting {2:00} ValueInvertEffect".Build(LedWizNr, TCC.Number, SettingNumber), TargetEffectName = Effect.
Name };
349 MakeEffectNameUnique(Effect, Table);
350 Table.Effects.Add(Effect);
355 Effect =
new ValueMapFullRangeEffect() { Name =
"Ledwiz {0:00} Column {1:00} Setting {2:00} FullRangeEffect".Build(LedWizNr, TCC.Number, SettingNumber), TargetEffectName = Effect.
Name };
356 MakeEffectNameUnique(Effect, Table);
357 Table.Effects.Add(Effect);
366 MakeEffectNameUnique(Effect, Table);
367 Table.Effects.Add(Effect);
372 int TEN = Variable.Substring(1).ToInteger();
373 if (!Table.TableElements.Contains(TET, TEN))
375 Table.TableElements.UpdateState(TET, TEN, 0);
388 string[] ATE = TCS.
TableElement.Split(
new char[] {
'|' }, StringSplitOptions.RemoveEmptyEntries);
389 foreach (
string TE
in ATE)
392 int TEN = TE.Substring(1).ToInteger();
393 if (!Table.TableElements.Contains(TET, TEN))
395 Table.TableElements.UpdateState(TET, TEN, 0);
418 private void MakeEffectNameUnique(
IEffect Effect, Table.
Table Table)
420 if (Table.Effects.Contains(Effect.
Name))
423 while (Table.Effects.Contains(
"{0} {1}".Build(Effect.
Name, Cnt)))
427 Effect.
Name =
"{0} {1}".Build(Effect.
Name, Cnt);
435 private Dictionary<int, Dictionary<int, IToy>> SetupCabinet(Dictionary<int, TableConfig> TableConfigDict,
Cabinet Cabinet)
437 Dictionary<int, Dictionary<int, IToy>> ToyAssignments =
new Dictionary<int, Dictionary<int, IToy>>();
439 Dictionary<int, LedWizEquivalent> LedWizEquivalentDict =
new Dictionary<int, LedWizEquivalent>();
442 if (!LedWizEquivalentDict.Keys.Any(K => K == ((LedWizEquivalent)T).LedWizNumber))
444 LedWizEquivalentDict.Add(((LedWizEquivalent)T).LedWizNumber, (LedWizEquivalent)T);
448 Log.Warning(
"Found more than one ledwiz with number {0}.".Build(((LedWizEquivalent)T).LedWizNumber));
453 foreach (KeyValuePair<int, TableConfig> KV
in TableConfigDict)
455 int LedWizNr = KV.Key;
456 ToyAssignments.Add(LedWizNr,
new Dictionary<int, IToy>());
459 if (LedWizEquivalentDict.ContainsKey(LedWizNr))
461 LedWizEquivalent LWE = LedWizEquivalentDict[LedWizNr];
465 IToy TargetToy = null;
472 if (Cabinet.
Toys.Any(O => (O is IMatrixToy<RGBAColor> || O is IMatrixToy<AnalogAlpha>) && O.Name == OutputName))
476 TargetToy = (
IToy)Cabinet.
Toys.FirstOrDefault(O => (O is IMatrixToy<RGBAColor> || O is IMatrixToy<AnalogAlpha>) && O.Name == OutputName);
496 if (Cabinet.
Toys.Any(O => O is IRGBAToy && O.Name == OutputName))
498 TargetToy = (
IToy)Cabinet.
Toys.FirstOrDefault(O => O is IRGBAToy && O.Name == OutputName);
501 if (TargetToy == null)
515 string ToyName =
"LedWiz {0:00} Column {1:00}".Build(LedWizNr, TCC.
Number);
516 if (Cabinet.
Toys.Contains(ToyName))
519 while (Cabinet.
Toys.Contains(
"{0} {1}".Build(ToyName, Cnt)))
523 ToyName =
"{0} {1}".Build(ToyName, Cnt);
526 Cabinet.
Toys.Add(TargetToy);
542 if (Cabinet.
Toys.Any(O => O is IAnalogAlphaToy && O.Name == OutputName))
544 TargetToy = (
IToy)Cabinet.
Toys.FirstOrDefault(O => O is IAnalogAlphaToy && O.Name == OutputName);
547 if (TargetToy == null)
560 string ToyName =
"LedWiz {0:00} Column {1:00}".Build(LedWizNr, TCC.
Number);
562 if (Cabinet.
Toys.Contains(ToyName))
565 while (Cabinet.
Toys.Contains(
"{0} {1}".Build(ToyName, Cnt)))
569 ToyName =
"{0} {1}".Build(ToyName, Cnt);
572 Cabinet.
Toys.Add(TargetToy);
583 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));
588 if (TargetToy != null)
590 ToyAssignments[LedWizNr].Add(TCC.
Number, TargetToy);
595 return ToyAssignments;