-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclsAction.vb
More file actions
1210 lines (1062 loc) · 42.5 KB
/
clsAction.vb
File metadata and controls
1210 lines (1062 loc) · 42.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Imports System.Xml
Public Enum ActionType
actWait
actWaitRandom
actLoop
actHold
actRelease
actPress
actGroup
actInputVideo
actInputAudio
actInputRumble
actOutputAudio
End Enum
Public Class clsActionGroup
Public name As String
Public actions As List(Of clsAction)
Public Sub New(_name As String)
name = _name
actions = New List(Of clsAction)
End Sub
Public Function containsGroup(g As clsActionGroup) As Boolean
For Each a As clsAction In actions
If a.getActType = ActionType.actGroup Then
Dim ag As clsActionAGroup = a
If ag.target Is g Then Return True
If ag.target.containsGroup(g) Then Return True
End If
Next
Return False
End Function
Public Function getActions() As clsAction()
Dim tmp As New List(Of clsAction)
For Each action As clsAction In actions
tmp.Add(action.Clone)
Next
For Each action As clsAction In tmp
If action.getActType = ActionType.actLoop Then
Dim agLoop As clsActionLoop = action
agLoop.linkTarget(tmp)
End If
Next
Dim final As New List(Of clsAction)
For Each action As clsAction In tmp
final.Add(action)
If action.getActType = ActionType.actGroup Then
Dim agAction As clsActionAGroup = action
For i As Integer = 1 To agAction.repeat
final.AddRange(agAction.target.getActions())
Next
End If
Next
Return final.ToArray
End Function
Public Overrides Function ToString() As String
Return name
End Function
End Class
Public MustInherit Class clsAction
Public index As Integer
Public referrers As New List(Of clsActionLoop)
Public controllerNumber As Byte
Public group As clsActionGroup
Public comment As String
Public original As clsAction
Public MustOverride Function getDescription() As String
Public MustOverride Function getActType() As ActionType
Public MustOverride Function Clone() As clsAction
Public Overridable Function isInput() As Boolean
Return False
End Function
Public Overridable Function isOutput() As Boolean
Return False
End Function
Public Sub baseClone(orig As clsAction)
index = orig.index
referrers.Clear()
controllerNumber = orig.controllerNumber
group = orig.group
original = orig
End Sub
Public Sub refresh(lb As RefreshingListBox, Optional updateLB As Boolean = True)
If updateLB Then lb.RefreshItem(index)
For Each action In referrers
action.refresh(lb)
Next
End Sub
Public Overridable Sub delete()
For Each action In referrers
action.target = Nothing
Next
End Sub
Public Overridable Function serialize() As String
Return Nothing
End Function
Public MustOverride Function toXML(doc As XmlDocument) As XmlElement
Public Shared Function deSerialize(src As String, group As clsActionGroup) As clsAction
Dim type As String = Left(src, InStr(1, src, ",") - 1)
Select Case type
Case "Wait"
Return New clsActionWait(src, group)
Case "WaitRandom"
Return New clsActionWaitRandom(src, group)
Case "Loop"
Return New clsActionLoop(src, group)
Case "Hold"
Return New clsActionHold(src, group)
Case "Release"
Return New clsActionRelease(src, group)
Case "Press"
Return New clsActionPress(src, group)
Case Else
Return Nothing
End Select
End Function
Public Shared Function fromXML(node As XmlElement, version As Integer, group As clsActionGroup)
Dim a As clsAction
Select Case node.Name
Case "Wait"
a = New clsActionWait(node, version, group)
Case "WaitRandom"
a = New clsActionWaitRandom(node, version, group)
Case "Loop"
a = New clsActionLoop(node, version, group)
Case "Hold"
a = New clsActionHold(node, version, group)
Case "Release"
a = New clsActionRelease(node, version, group)
Case "Press"
a = New clsActionPress(node, version, group)
Case "Group"
a = New clsActionAGroup(node, version, group)
Case "VideoInput"
a = New clsActionInputVideo(node, version, group)
Case "AudioOutput"
a = New clsActionOutputAudio(node, version, group)
Case Else
Return Nothing
Stop
End Select
Dim comAtt As XmlAttribute = node.Attributes("Comment")
If Not comAtt Is Nothing Then a.comment = comAtt.Value
Return a
End Function
Public Overrides Function toString() As String
Return (index + 1) & ": " & getDescription() & IIf(comment <> vbNullString, " {" & comment & "}", "")
End Function
End Class
Public MustInherit Class clsActionInput
Inherits clsAction
Public interval As Integer
Public duration As Integer
Public startTime As Date
Public nextTest As Date
Public lastTest As Date
Protected MustOverride Function inputTest() As Boolean
Public Function test() As Boolean
If Now > lastTest OrElse inputTest() Then
Return True
Else
nextTest = nextTest.AddMilliseconds(interval)
Return False
End If
End Function
Public Sub start()
startTime = Now
nextTest = startTime.AddMilliseconds(interval)
lastTest = startTime.AddMilliseconds(duration)
End Sub
Public Overrides Function isInput() As Boolean
Return True
End Function
End Class
Public MustInherit Class clsActionOutput
Inherits clsAction
Public Overridable Sub init()
End Sub
Public MustOverride Sub activate()
Public Overridable Sub cleanup()
End Sub
Public Overrides Function isOutput() As Boolean
Return True
End Function
End Class
Public Class clsActionWait
Inherits clsAction
Public delay As Integer
Public Sub New(_delay As Integer, _group As clsActionGroup)
controllerNumber = 0
delay = _delay
group = _group
End Sub
Public Overrides Function getDescription() As String
Return "Wait for " & formatMS(delay)
End Function
Public Overrides Function getActType() As ActionType
Return ActionType.actWait
End Function
Public Overrides Function serialize() As String
Return "Wait," & delay
End Function
Public Overrides Function toXML(doc As XmlDocument) As XmlElement
Dim tmp As XmlElement = doc.CreateElement("Wait")
tmp.SetAttribute("Delay", delay)
If comment <> vbNullString Then tmp.SetAttribute("Comment", comment)
Return tmp
End Function
Public Sub New(serial As String, _group As clsActionGroup)
Dim toks() As String = serial.Split(",")
delay = toks(1)
group = _group
End Sub
Public Sub New(node As XmlNode, version As Integer, _group As clsActionGroup)
delay = node.Attributes("Delay").Value
group = _group
End Sub
Public Overrides Function clone() As clsAction
Dim tmp As New clsActionWait(delay, group)
tmp.baseClone(Me)
Return tmp
End Function
End Class
Public Class clsActionWaitRandom
Inherits clsAction
Public minDelay As Integer
Public maxDelay As Integer
Public Sub New(_minDelay As Integer, _maxDelay As Integer, _group As clsActionGroup)
controllerNumber = 0
minDelay = _minDelay
maxDelay = _maxDelay
group = _group
End Sub
Public Overrides Function getDescription() As String
Return "Wait for " & formatMS(minDelay) & " to " & formatMS(maxDelay)
End Function
Public Overrides Function getActType() As ActionType
Return ActionType.actWaitRandom
End Function
Public Overrides Function serialize() As String
Return "WaitRandom," & minDelay & "," & maxDelay
End Function
Public Overrides Function toXML(doc As XmlDocument) As XmlElement
Dim tmp As XmlElement = doc.CreateElement("WaitRandom")
tmp.SetAttribute("MinDelay", minDelay)
tmp.SetAttribute("MaxDelay", maxDelay)
If comment <> vbNullString Then tmp.SetAttribute("Comment", comment)
Return tmp
End Function
Public Sub New(serial As String, _group As clsActionGroup)
Dim toks() As String = serial.Split(",")
minDelay = toks(1)
maxDelay = toks(2)
group = _group
End Sub
Public Sub New(node As XmlNode, version As Integer, _group As clsActionGroup)
minDelay = node.Attributes("MinDelay").Value
maxDelay = node.Attributes("MaxDelay").Value
group = _group
End Sub
Public Overrides Function clone() As clsAction
Dim tmp As New clsActionWaitRandom(minDelay, maxDelay, group)
tmp.baseClone(Me)
Return tmp
End Function
End Class
Public Class clsActionLoop
Inherits clsAction
Public repeat As Integer
Public repeatLeft As Integer
Public target As clsAction
Private tgtIndex As Integer
Public Sub New(_target As clsAction, _repeat As Integer, _group As clsActionGroup)
controllerNumber = 0
repeat = _repeat
target = _target
target.referrers.Add(Me)
group = _group
End Sub
Public Overrides Sub delete()
MyBase.delete()
If Not target Is Nothing Then target.referrers.Remove(Me)
End Sub
Public Overrides Function getDescription() As String
If target Is Nothing Then
Return "Loop to N/A, " & repeat & " times"
Else
Return "Loop to " & (target.index + 1) & ", " & repeat & " times"
End If
End Function
Public Overrides Function getActType() As ActionType
Return ActionType.actLoop
End Function
Public Overrides Function serialize() As String
Return "Loop," & target.index & "," & repeat
End Function
Public Overrides Function toXML(doc As XmlDocument) As XmlElement
Dim tmp As XmlElement = doc.CreateElement("Loop")
tmp.SetAttribute("Target", target.index)
tmp.SetAttribute("Repeat", repeat)
If comment <> vbNullString Then tmp.SetAttribute("Comment", comment)
Return tmp
End Function
Public Sub linkTarget(l As List(Of clsAction))
target = l(Me.tgtIndex)
target.referrers.Add(Me)
End Sub
Public Sub New(serial As String, _group As clsActionGroup)
Dim toks() As String = serial.Split(",")
target = Nothing
tgtIndex = toks(1)
repeat = toks(2)
group = _group
End Sub
Public Sub New(node As XmlNode, version As Integer, _group As clsActionGroup)
target = Nothing
tgtIndex = node.Attributes("Target").Value
repeat = node.Attributes("Repeat").Value
group = _group
End Sub
Public Overrides Function clone() As clsAction
Dim tmp As New clsActionLoop(target, repeat, group)
tmp.tgtIndex = target.index
tmp.baseClone(Me)
Return tmp
End Function
End Class
Public Class clsActionAGroup
Inherits clsAction
Public repeat As Integer
Public repeatLeft As Integer
Public target As clsActionGroup
Private tgtName As String
Public Sub New(_target As clsActionGroup, _repeat As Integer, _group As clsActionGroup)
controllerNumber = 0
repeat = _repeat
target = _target
tgtName = target.name
group = _group
End Sub
Public Overrides Sub delete()
MyBase.delete()
End Sub
Public Overrides Function getDescription() As String
If target Is Nothing Then
Return "Do {Nothing}"
Else
If repeat = 1 Then
Return "Do {" & tgtName & "}"
Else
Return "Do {" & tgtName & "}, " & repeat & " times"
End If
End If
End Function
Public Overrides Function getActType() As ActionType
Return ActionType.actGroup
End Function
Public Overrides Function toXML(doc As XmlDocument) As XmlElement
Dim tmp As XmlElement = doc.CreateElement("Group")
tmp.SetAttribute("Name", target.name)
tmp.SetAttribute("Repeat", repeat)
If comment <> vbNullString Then tmp.SetAttribute("Comment", comment)
Return tmp
End Function
Public Sub linkTarget(l As Dictionary(Of String, clsActionGroup))
target = l(Me.tgtName)
End Sub
Public Sub New(node As XmlNode, version As Integer, _group As clsActionGroup)
group = _group
target = Nothing
tgtName = node.Attributes("Name").Value
repeat = node.Attributes("Repeat").Value
End Sub
Public Overrides Function clone() As clsAction
Dim tmp As New clsActionAGroup(target, repeat, group)
tmp.baseClone(Me)
Return tmp
End Function
End Class
Public Class clsActionHold
Inherits clsAction
Public buttonMask As Integer
Public LT As Integer
Public RT As Integer
Public LS As New Point
Public RS As New Point
Public ReadOnly Property LTDefined As Boolean
Get
Return LT >= 0
End Get
End Property
Public ReadOnly Property RTDefined As Boolean
Get
Return RT >= 0
End Get
End Property
Public ReadOnly Property LSDefined As Boolean
Get
Return LS.X > -32768 And LS.Y > -32768
End Get
End Property
Public ReadOnly Property RSDefined As Boolean
Get
Return RS.X > -32768 And RS.Y > -32768
End Get
End Property
Public Sub New(_controllerNumber As Byte, _buttonMask As Integer, _LT As Integer, _RT As Integer, _LS As Point, _RS As Point, _group As clsActionGroup)
controllerNumber = _controllerNumber
buttonMask = _buttonMask
LT = _LT
RT = _RT
If _LS.X > -32768 And _LS.Y > -32768 Then
LS.X = _LS.X
LS.Y = _LS.Y
Else
LS.X = -32768
LS.Y = -32768
End If
If _RS.X > -32768 And _RS.Y > -32768 Then
RS.X = _RS.X
RS.Y = _RS.Y
Else
RS.X = -32768
RS.Y = -32768
End If
group = _group
End Sub
Public Overrides Function getDescription() As String
Dim sb As New System.Text.StringBuilder("[" & controllerNumber & "] Hold ")
If buttonMask And clsController.XBButtons.btnGuide Then sb.Append("Guide,")
If buttonMask And clsController.XBButtons.btnStart Then sb.Append("Start,")
If buttonMask And clsController.XBButtons.btnBack Then sb.Append("Back,")
If buttonMask And clsController.XBButtons.btnUp Then sb.Append("Up,")
If buttonMask And clsController.XBButtons.btnDown Then sb.Append("Down,")
If buttonMask And clsController.XBButtons.btnLeft Then sb.Append("Left,")
If buttonMask And clsController.XBButtons.btnRight Then sb.Append("Right,")
If LTDefined Then sb.Append("LT(" & LT & "),")
If buttonMask And clsController.XBButtons.btnLB Then sb.Append("LB,")
If buttonMask And clsController.XBButtons.btnL3 Then sb.Append("LS,")
If LS.X > -32768 And LS.Y > -32768 Then sb.Append("LJ(" & LS.X / 256 & "," & LS.Y / 256 & "),")
If RTDefined Then sb.Append("RT(" & RT & "),")
If buttonMask And clsController.XBButtons.btnRB Then sb.Append("RB,")
If buttonMask And clsController.XBButtons.btnR3 Then sb.Append("RS,")
If RS.X > -32768 And RS.Y > -32768 Then sb.Append("RJ(" & RS.X / 256 & "," & RS.Y / 256 & "),")
If buttonMask And clsController.XBButtons.btnA Then sb.Append("A,")
If buttonMask And clsController.XBButtons.btnB Then sb.Append("B,")
If buttonMask And clsController.XBButtons.btnX Then sb.Append("X,")
If buttonMask And clsController.XBButtons.btnY Then sb.Append("Y,")
Dim tmp As String = sb.ToString
Return tmp.Substring(0, tmp.Length - 1)
End Function
Public Overrides Function getActType() As ActionType
Return ActionType.actHold
End Function
Public Overrides Function serialize() As String
Return "Hold," & controllerNumber & "," & buttonMask & "," & IIf(LTDefined, LT, -1) & "," & LS.X & "," & LS.Y & "," & IIf(RTDefined, RT, -1) & "," & RS.X & "," & RS.Y
End Function
Public Overrides Function toXML(doc As XmlDocument) As XmlElement
Dim tmp As XmlElement = doc.CreateElement("Hold")
tmp.SetAttribute("Controller", controllerNumber)
If buttonMask > 0 Then tmp.SetAttribute("ButtonMask", buttonMask)
If LTDefined Then tmp.SetAttribute("LT", LT)
If RTDefined Then tmp.SetAttribute("RT", RT)
If LS.X > -32768 And LS.Y > -32768 Then
tmp.SetAttribute("LSX", LS.X)
tmp.SetAttribute("LSY", LS.Y)
End If
If RS.X > -32768 And RS.Y > -32768 Then
tmp.SetAttribute("RSX", RS.X)
tmp.SetAttribute("RSY", RS.Y)
End If
If comment <> vbNullString Then tmp.SetAttribute("Comment", comment)
Return tmp
End Function
Public Sub New(serial As String, _group As clsActionGroup)
Dim toks() As String = serial.Split(",")
Select Case toks(1)
Case "10.100.8.51"
controllerNumber = 1
Case "10.100.8.52"
controllerNumber = 2
Case Else
Stop
End Select
buttonMask = toks(2)
LT = toks(3)
LS.X = toks(4)
LS.Y = toks(5)
RT = toks(6)
RS.X = toks(7)
RS.Y = toks(8)
group = _group
End Sub
Public Sub New(node As XmlNode, version As Integer, _group As clsActionGroup)
group = _group
controllerNumber = node.Attributes("Controller").Value
Dim att As XmlAttribute = node.Attributes("ButtonMask")
If att Is Nothing Then buttonMask = 0 Else buttonMask = att.Value
att = node.Attributes("LT")
If att Is Nothing Then LT = -1 Else LT = att.Value
att = node.Attributes("RT")
If att Is Nothing Then RT = -1 Else RT = att.Value
Select Case version
Case 1
att = node.Attributes("LSX")
If att Is Nothing Then LS.X = -32768 Else LS.X = att.Value * 256
att = node.Attributes("LSY")
If att Is Nothing Then LS.Y = -32768 Else LS.Y = att.Value * 256
att = node.Attributes("RSX")
If att Is Nothing Then RS.X = -32768 Else RS.X = att.Value * 256
att = node.Attributes("RSY")
If att Is Nothing Then RS.Y = -32768 Else RS.Y = att.Value * 256
Case 2
att = node.Attributes("LSX")
If att Is Nothing Then LS.X = -32768 Else LS.X = att.Value
att = node.Attributes("LSY")
If att Is Nothing Then LS.Y = -32768 Else LS.Y = att.Value
att = node.Attributes("RSX")
If att Is Nothing Then RS.X = -32768 Else RS.X = att.Value
att = node.Attributes("RSY")
If att Is Nothing Then RS.Y = -32768 Else RS.Y = att.Value
End Select
End Sub
Public Overrides Function clone() As clsAction
Dim tmp As New clsActionHold(controllerNumber, buttonMask, LT, RT, LS, RS, group)
tmp.baseClone(Me)
Return tmp
End Function
End Class
Public Class clsActionRelease
Inherits clsAction
Public buttonMask As Integer
Public LTDefined As Boolean
Public RTDefined As Boolean
Public LSDefined As Boolean
Public RSDefined As Boolean
Public Sub New(_controllerNumber As Byte, _buttonMask As Integer, _LT As Integer, _RT As Integer, _LS As Point, _RS As Point, _group As clsActionGroup)
controllerNumber = _controllerNumber
buttonMask = _buttonMask
LTDefined = _LT >= 0
RTDefined = _RT >= 0
LSDefined = _LS.X > -32768 And _LS.Y > -32768
RSDefined = _RS.X > -32768 And _RS.Y > -32768
group = _group
End Sub
Public Sub New(_controllerNumber As Byte, _buttonMask As Integer, _LTDefined As Boolean, _RTDefined As Boolean, _LSDefined As Boolean, _RSDefined As Boolean, _group As clsActionGroup)
controllerNumber = _controllerNumber
buttonMask = _buttonMask
LTDefined = _LTDefined
RTDefined = _RTDefined
LSDefined = _LSDefined
RSDefined = _RSDefined
group = _group
End Sub
Public Overrides Function getDescription() As String
Dim sb As New System.Text.StringBuilder("[" & controllerNumber & "] Release ")
If buttonMask And clsController.XBButtons.btnGuide Then sb.Append("Guide,")
If buttonMask And clsController.XBButtons.btnStart Then sb.Append("Start,")
If buttonMask And clsController.XBButtons.btnBack Then sb.Append("Back,")
If buttonMask And clsController.XBButtons.btnUp Then sb.Append("Up,")
If buttonMask And clsController.XBButtons.btnDown Then sb.Append("Down,")
If buttonMask And clsController.XBButtons.btnLeft Then sb.Append("Left,")
If buttonMask And clsController.XBButtons.btnRight Then sb.Append("Right,")
If buttonMask And clsController.XBButtons.btnLB Then sb.Append("LB,")
If buttonMask And clsController.XBButtons.btnL3 Then sb.Append("LS,")
If buttonMask And clsController.XBButtons.btnRB Then sb.Append("RB,")
If buttonMask And clsController.XBButtons.btnR3 Then sb.Append("RS,")
If buttonMask And clsController.XBButtons.btnA Then sb.Append("A,")
If buttonMask And clsController.XBButtons.btnB Then sb.Append("B,")
If buttonMask And clsController.XBButtons.btnX Then sb.Append("X,")
If buttonMask And clsController.XBButtons.btnY Then sb.Append("Y,")
If LTDefined Then sb.Append("LT(0),")
If RTDefined Then sb.Append("RT(0),")
Dim tmp As String = sb.ToString
Return tmp.Substring(0, tmp.Length - 1)
End Function
Public Overrides Function getActType() As ActionType
Return ActionType.actRelease
End Function
Public Overrides Function serialize() As String
Return "Release," & controllerNumber & "," & buttonMask & "," & (IIf(LTDefined, &H1, 0) Or IIf(RTDefined, &H2, 0) Or IIf(LSDefined, &H4, 0) Or IIf(RSDefined, &H8, 0))
End Function
Public Overrides Function toXML(doc As XmlDocument) As XmlElement
Dim tmp As XmlElement = doc.CreateElement("Release")
tmp.SetAttribute("Controller", controllerNumber)
If buttonMask > 0 Then tmp.SetAttribute("ButtonMask", buttonMask)
If LTDefined Or RTDefined Or LSDefined Or RSDefined Then tmp.SetAttribute("AnalogMask", (IIf(LTDefined, &H1, 0) Or IIf(RTDefined, &H2, 0) Or IIf(LSDefined, &H4, 0) Or IIf(RSDefined, &H8, 0)))
If comment <> vbNullString Then tmp.SetAttribute("Comment", comment)
Return tmp
End Function
Public Sub New(serial As String, _group As clsActionGroup)
Dim toks() As String = serial.Split(",")
Select Case toks(1)
Case "10.100.8.51"
controllerNumber = 1
Case "10.100.8.52"
controllerNumber = 2
Case Else
Stop
End Select
buttonMask = toks(2)
Dim mask2 As Integer = toks(3)
LTDefined = mask2 And &H1
RTDefined = mask2 And &H2
LSDefined = mask2 And &H4
RSDefined = mask2 And &H8
group = _group
End Sub
Public Sub New(node As XmlNode, version As Integer, _group As clsActionGroup)
group = _group
controllerNumber = node.Attributes("Controller").Value
Dim att As XmlAttribute = node.Attributes("ButtonMask")
If att Is Nothing Then buttonMask = 0 Else buttonMask = att.Value
att = node.Attributes("AnalogMask")
If att Is Nothing Then Exit Sub
Dim mask2 As Integer = att.Value
LTDefined = mask2 And &H1
RTDefined = mask2 And &H2
LSDefined = mask2 And &H4
RSDefined = mask2 And &H8
End Sub
Public Overrides Function clone() As clsAction
Dim tmp As New clsActionRelease(controllerNumber, buttonMask, LTDefined, RTDefined, LSDefined, RSDefined, group)
tmp.baseClone(Me)
Return tmp
End Function
End Class
Public Class clsActionPress
Inherits clsAction
Public holdTime As Integer
Public waitTime As Integer
Public repeat As Integer
Public buttonMask As Integer
Public LT As Integer
Public RT As Integer
Public LS As New Point
Public RS As New Point
Public ReadOnly Property LTDefined As Boolean
Get
Return LT >= 0
End Get
End Property
Public ReadOnly Property RTDefined As Boolean
Get
Return RT >= 0
End Get
End Property
Public ReadOnly Property LSDefined As Boolean
Get
Return LS.X > -32768 And LS.Y > -32768
End Get
End Property
Public ReadOnly Property RSDefined As Boolean
Get
Return RS.X > -32768 And RS.Y > -32768
End Get
End Property
Public Sub New(_controllerNumber As String, _buttonMask As Integer, _LT As Integer, _RT As Integer, _LS As Point, _RS As Point, _holdTime As Integer, _waitTime As Integer, _repeat As Integer, _group As clsActionGroup)
controllerNumber = _controllerNumber
buttonMask = _buttonMask
LT = _LT
RT = _RT
If _LS.X > -32768 And _LS.Y > -32768 Then
LS.X = _LS.X
LS.Y = _LS.Y
Else
LS.X = -32768
LS.Y = -32768
End If
If _RS.X > -32768 And _RS.Y > -32768 Then
RS.X = _RS.X
RS.Y = _RS.Y
Else
RS.X = -32768
RS.Y = -32768
End If
holdTime = _holdTime
waitTime = _waitTime
repeat = _repeat
group = _group
End Sub
Public Overrides Function getDescription() As String
Dim sb As New System.Text.StringBuilder("[" & controllerNumber & "] Press ")
If buttonMask And clsController.XBButtons.btnGuide Then sb.Append("Guide,")
If buttonMask And clsController.XBButtons.btnStart Then sb.Append("Start,")
If buttonMask And clsController.XBButtons.btnBack Then sb.Append("Back,")
If buttonMask And clsController.XBButtons.btnUp Then sb.Append("Up,")
If buttonMask And clsController.XBButtons.btnDown Then sb.Append("Down,")
If buttonMask And clsController.XBButtons.btnLeft Then sb.Append("Left,")
If buttonMask And clsController.XBButtons.btnRight Then sb.Append("Right,")
If LTDefined Then sb.Append("LT(" & LT & "),")
If buttonMask And clsController.XBButtons.btnLB Then sb.Append("LB,")
If buttonMask And clsController.XBButtons.btnL3 Then sb.Append("LS,")
If LS.X > -32768 And LS.Y > -32768 Then sb.Append("LJ(" & LS.X / 256 & "," & LS.Y / 256 & "),")
If RTDefined Then sb.Append("RT(" & RT & "),")
If buttonMask And clsController.XBButtons.btnRB Then sb.Append("RB,")
If buttonMask And clsController.XBButtons.btnR3 Then sb.Append("RS,")
If RS.X > -32768 And RS.Y > -32768 Then sb.Append("RJ(" & RS.X / 256 & "," & RS.Y / 256 & "),")
If buttonMask And clsController.XBButtons.btnA Then sb.Append("A,")
If buttonMask And clsController.XBButtons.btnB Then sb.Append("B,")
If buttonMask And clsController.XBButtons.btnX Then sb.Append("X,")
If buttonMask And clsController.XBButtons.btnY Then sb.Append("Y,")
Dim tmp As String = sb.ToString
tmp = tmp.Substring(0, tmp.Length - 1) & " for " & formatMS(holdTime) & ", wait " & formatMS(waitTime) & IIf(repeat > 1, ", " & repeat & " times", vbNullString)
Return tmp
End Function
Public Overrides Function getActType() As ActionType
Return ActionType.actPress
End Function
Public Overrides Function serialize() As String
Return "Press," & controllerNumber & "," & buttonMask & "," & IIf(LTDefined, LT, -1) & "," & LS.X & "," & LS.Y & "," & IIf(RTDefined, RT, -1) & "," & RS.X & "," & RS.Y & "," & holdTime & "," & waitTime & "," & repeat
End Function
Public Overrides Function toXML(doc As XmlDocument) As XmlElement
Dim tmp As XmlElement = doc.CreateElement("Press")
tmp.SetAttribute("Controller", controllerNumber)
If buttonMask > 0 Then tmp.SetAttribute("ButtonMask", buttonMask)
If LTDefined Then tmp.SetAttribute("LT", LT)
If RTDefined Then tmp.SetAttribute("RT", RT)
If LS.X > -32768 And LS.Y > -32768 Then
tmp.SetAttribute("LSX", LS.X)
tmp.SetAttribute("LSY", LS.Y)
End If
If RS.X > -32768 And RS.Y > -32768 Then
tmp.SetAttribute("RSX", RS.X)
tmp.SetAttribute("RSY", RS.Y)
End If
tmp.SetAttribute("Hold", holdTime)
tmp.SetAttribute("Wait", waitTime)
tmp.SetAttribute("Repeat", repeat)
If comment <> vbNullString Then tmp.SetAttribute("Comment", comment)
Return tmp
End Function
Public Sub New(serial As String, _group As clsActionGroup)
Dim toks() As String = serial.Split(",")
Select Case toks(1)
Case "10.100.8.51"
controllerNumber = 1
Case "10.100.8.52"
controllerNumber = 2
Case Else
Stop
End Select
buttonMask = toks(2)
LT = toks(3)
LS.X = toks(4)
LS.Y = toks(5)
RT = toks(6)
RS.X = toks(7)
RS.Y = toks(8)
holdTime = toks(9)
waitTime = toks(10)
repeat = toks(11)
group = _group
End Sub
Public Sub New(node As XmlNode, version As Integer, _group As clsActionGroup)
group = _group
controllerNumber = node.Attributes("Controller").Value
Dim att As XmlAttribute = node.Attributes("ButtonMask")
If att Is Nothing Then buttonMask = 0 Else buttonMask = att.Value
att = node.Attributes("LT")
If att Is Nothing Then LT = -1 Else LT = att.Value
att = node.Attributes("RT")
If att Is Nothing Then RT = -1 Else RT = att.Value
Select Case version
Case 1
att = node.Attributes("LSX")
If att Is Nothing Then LS.X = -32768 Else LS.X = att.Value * 256
att = node.Attributes("LSY")
If att Is Nothing Then LS.Y = -32768 Else LS.Y = att.Value * 256
att = node.Attributes("RSX")
If att Is Nothing Then RS.X = -32768 Else RS.X = att.Value * 256
att = node.Attributes("RSY")
If att Is Nothing Then RS.Y = -32768 Else RS.Y = att.Value * 256
Case 2
att = node.Attributes("LSX")
If att Is Nothing Then LS.X = -32768 Else LS.X = att.Value
att = node.Attributes("LSY")
If att Is Nothing Then LS.Y = -32768 Else LS.Y = att.Value
att = node.Attributes("RSX")
If att Is Nothing Then RS.X = -32768 Else RS.X = att.Value
att = node.Attributes("RSY")
If att Is Nothing Then RS.Y = -32768 Else RS.Y = att.Value
End Select
holdTime = node.Attributes("Hold").Value
waitTime = node.Attributes("Wait").Value
repeat = node.Attributes("Repeat").Value
End Sub
Public Overrides Function clone() As clsAction
Dim tmp As New clsActionPress(controllerNumber, buttonMask, LT, RT, LS, RS, holdTime, waitTime, repeat, group)
tmp.baseClone(Me)
Return tmp
End Function
End Class
Public Class clsActionInputVideo
Inherits clsActionInput
Public pixel As Point
Public minColor As Color
Public maxColor As Color
Public capture As clsSnapshot
Public Sub New(_interval As Integer, _duration As Integer, _pixel As Point, _minColor As Color, _maxColor As Color, _group As clsActionGroup)
interval = _interval
duration = _duration
pixel = _pixel
minColor = _minColor
maxColor = _maxColor
group = _group
End Sub
Public Sub New(node As XmlNode, version As Integer, _group As clsActionGroup)
group = _group
interval = node.Attributes("Interval").Value
duration = node.Attributes("Duration").Value
pixel = New Point(node.Attributes("X").Value, node.Attributes("Y").Value)
minColor = Color.FromArgb(node.Attributes("minColor").Value)
maxColor = Color.FromArgb(node.Attributes("maxColor").Value)
End Sub
Public Overrides Function Clone() As clsAction
Dim tmp As New clsActionInputVideo(interval, duration, pixel, minColor, maxColor, group)
tmp.baseClone(Me)
Return tmp
End Function
Public Overrides Function getActType() As ActionType
Return ActionType.actInputVideo
End Function
Public Overrides Function getDescription() As String
Return String.Format("Check [{0},{1}] for colors between {2} and {3} every {4} stop after {5}", pixel.X, pixel.Y, System.Drawing.ColorTranslator.ToHtml(minColor), System.Drawing.ColorTranslator.ToHtml(maxColor), formatMS(interval), formatMS(duration))
End Function
Protected Overrides Function inputTest() As Boolean
Dim bmp As Bitmap = capture.capture
Dim c As Color = bmp.GetPixel(pixel.X, pixel.Y)
bmp.Dispose()
If c.R >= minColor.R AndAlso c.R <= maxColor.R AndAlso c.G >= minColor.G AndAlso c.G <= maxColor.G AndAlso c.B >= minColor.B AndAlso c.B <= maxColor.B Then
Return True
Else
Return False
End If
End Function
Public Overrides Function toXML(doc As System.Xml.XmlDocument) As System.Xml.XmlElement
Dim tmp As XmlElement = doc.CreateElement("VideoInput")
tmp.SetAttribute("Interval", interval)
tmp.SetAttribute("Duration", duration)
tmp.SetAttribute("X", pixel.X)
tmp.SetAttribute("Y", pixel.Y)
tmp.SetAttribute("minColor", minColor.ToArgb)
tmp.SetAttribute("maxColor", maxColor.ToArgb)
If comment <> vbNullString Then tmp.SetAttribute("Comment", comment)
Return tmp
End Function
End Class
Public Class clsActionOutputAudio
Inherits clsActionOutput
Public paths As New List(Of String)
Public skipMS As Integer
Private spInputs As List(Of NAudio.Wave.IWaveProvider)
Private wOut As NAudio.Wave.WasapiOut
Private aOut As NAudio.Wave.AsioOut
Private readers As List(Of NAudio.Wave.MediaFoundationReader)
Public Sub New(_path As String, _skipMS As Integer, _group As clsActionGroup)
paths.Add(_path)
skipMS = _skipMS
group = _group
End Sub
Public Sub New(_paths As List(Of String), _skipMS As Integer, _group As clsActionGroup)
paths.AddRange(_paths)
skipMS = _skipMS
group = _group
End Sub
Public Sub skip(ms As Integer)
For Each r As NAudio.Wave.MediaFoundationReader In readers
Debug.Print(r.CurrentTime.TotalMilliseconds)
r.CurrentTime = r.CurrentTime.Add(New TimeSpan(0, 0, 0, 0, ms))
Debug.Print(r.CurrentTime.TotalMilliseconds)
Next
End Sub
Public Overrides Sub init()