1
1
import {
2
- Commands as AtemCommands , VideoState
2
+ Commands as AtemCommands , VideoState , Enums
3
3
} from 'atem-connection'
4
4
import { State as StateObject } from '..'
5
5
6
- export function resolveSupersourceBoxState ( oldState : StateObject , newState : StateObject ) : Array < AtemCommands . AbstractCommand > {
6
+ export function resolveSuperSourceState ( oldState : StateObject , newState : StateObject , version : Enums . ProtocolVersion ) : Array < AtemCommands . AbstractCommand > {
7
+ let commands : Array < AtemCommands . AbstractCommand > = [ ]
8
+
9
+ if ( ! newState . video . superSources ) return commands
10
+
11
+ if ( version < Enums . ProtocolVersion . V8_0 ) {
12
+ commands = commands . concat (
13
+ resolveSuperSourceBoxState ( oldState , newState ) ,
14
+ resolveSuperSourcePropertiesState ( oldState , newState ) )
15
+ } else {
16
+ commands = commands . concat (
17
+ resolveSuperSourceBoxState ( oldState , newState ) ,
18
+ resolveSuperSourcePropertiesV8State ( oldState , newState ) ,
19
+ resolveSuperSourceBorderV8State ( oldState , newState ) )
20
+ }
21
+
22
+ return commands
23
+ }
24
+
25
+ export function resolveSuperSourceBoxState ( oldState : StateObject , newState : StateObject ) : Array < AtemCommands . AbstractCommand > {
7
26
const commands : Array < AtemCommands . AbstractCommand > = [ ]
8
27
9
- for ( const index in newState . video . superSourceBoxes ) {
10
- const newBox = newState . video . superSourceBoxes [ index ] || { }
11
- const oldBox = oldState . video . superSourceBoxes [ index ] || { }
28
+ for ( const index in newState . video . superSources [ 0 ] . boxes ) {
29
+ const newBox = newState . video . superSources [ 0 ] . boxes [ index ] || { }
30
+ const oldBox = oldState . video . superSources [ 0 ] . boxes [ index ] || { }
12
31
const props : Partial < VideoState . SuperSourceBox > = { }
13
32
14
33
for ( let key in newBox ) {
@@ -20,6 +39,7 @@ export function resolveSupersourceBoxState (oldState: StateObject, newState: Sta
20
39
21
40
if ( Object . keys ( props ) . length > 0 ) {
22
41
const command = new AtemCommands . SuperSourceBoxParametersCommand ( )
42
+ command . ssrcId = 0
23
43
command . boxId = Number ( index )
24
44
command . updateProps ( props )
25
45
commands . push ( command )
@@ -32,9 +52,69 @@ export function resolveSupersourceBoxState (oldState: StateObject, newState: Sta
32
52
export function resolveSuperSourcePropertiesState ( oldState : StateObject , newState : StateObject ) : Array < AtemCommands . AbstractCommand > {
33
53
const commands : Array < AtemCommands . AbstractCommand > = [ ]
34
54
35
- if ( newState . video . superSourceProperties ) {
36
- const newSsProperties = newState . video . superSourceProperties
37
- const oldSsProperties = oldState . video . superSourceProperties
55
+ if ( newState . video . superSources [ 0 ] ) {
56
+ const newSsProperties : VideoState . SuperSourceProperties & VideoState . SuperSourceBorder = {
57
+ ...newState . video . superSources [ 0 ] . properties ,
58
+ ...newState . video . superSources [ 0 ] . border
59
+ }
60
+ const oldSsProperties : VideoState . SuperSourceProperties & VideoState . SuperSourceBorder = {
61
+ ...oldState . video . superSources [ 0 ] . properties ,
62
+ ...oldState . video . superSources [ 0 ] . border
63
+ }
64
+ const props : Partial < VideoState . SuperSourceProperties & VideoState . SuperSourceBorder > = { }
65
+
66
+ for ( let key in newSsProperties ) {
67
+ const typedKey = key as keyof ( VideoState . SuperSourceProperties & VideoState . SuperSourceBorder )
68
+ if ( newSsProperties [ typedKey ] !== oldSsProperties [ typedKey ] ) {
69
+ props [ typedKey ] = newSsProperties [ typedKey ]
70
+ }
71
+ }
72
+
73
+ if ( Object . keys ( props ) . length > 0 ) {
74
+ const command = new AtemCommands . SuperSourcePropertiesCommand ( )
75
+ command . updateProps ( props )
76
+ commands . push ( command )
77
+ }
78
+ }
79
+
80
+ return commands
81
+ }
82
+
83
+ export function resolveSuperSourceBoxV8State ( oldState : StateObject , newState : StateObject ) : Array < AtemCommands . AbstractCommand > {
84
+ const commands : Array < AtemCommands . AbstractCommand > = [ ]
85
+
86
+ for ( const ssrc in newState . video . superSources ) {
87
+ for ( const index in newState . video . superSources [ ssrc ] . boxes ) {
88
+ const newBox = newState . video . superSources [ ssrc ] . boxes [ index ] || { }
89
+ const oldBox = oldState . video . superSources [ ssrc ] . boxes [ index ] || { }
90
+ const props : Partial < VideoState . SuperSourceBox > = { }
91
+
92
+ for ( let key in newBox ) {
93
+ const typedKey = key as keyof VideoState . SuperSourceBox
94
+ if ( newBox [ typedKey ] !== oldBox [ typedKey ] ) {
95
+ props [ typedKey ] = newBox [ typedKey ]
96
+ }
97
+ }
98
+
99
+ if ( Object . keys ( props ) . length > 0 ) {
100
+ const command = new AtemCommands . SuperSourceBoxParametersCommand ( )
101
+ command . ssrcId = Number ( ssrc )
102
+ command . boxId = Number ( index )
103
+ command . updateProps ( props )
104
+ commands . push ( command )
105
+ }
106
+ }
107
+ }
108
+
109
+ return commands
110
+ }
111
+
112
+ export function resolveSuperSourcePropertiesV8State ( oldState : StateObject , newState : StateObject ) : Array < AtemCommands . AbstractCommand > {
113
+ const commands : Array < AtemCommands . AbstractCommand > = [ ]
114
+
115
+ for ( const ssrc in newState . video . superSources ) {
116
+ const newSsProperties = newState . video . superSources [ ssrc ] . properties
117
+ const oldSsProperties = oldState . video . superSources [ ssrc ] . properties
38
118
const props : Partial < VideoState . SuperSourceProperties > = { }
39
119
40
120
for ( let key in newSsProperties ) {
@@ -45,7 +125,34 @@ export function resolveSuperSourcePropertiesState (oldState: StateObject, newSta
45
125
}
46
126
47
127
if ( Object . keys ( props ) . length > 0 ) {
48
- const command = new AtemCommands . SuperSourcePropertiesCommand ( )
128
+ const command = new AtemCommands . SuperSourcePropertiesV8Command ( )
129
+ command . ssrcId = Number ( ssrc )
130
+ command . updateProps ( props )
131
+ commands . push ( command )
132
+ }
133
+ }
134
+
135
+ return commands
136
+ }
137
+
138
+ export function resolveSuperSourceBorderV8State ( oldState : StateObject , newState : StateObject ) : Array < AtemCommands . AbstractCommand > {
139
+ const commands : Array < AtemCommands . AbstractCommand > = [ ]
140
+
141
+ for ( const ssrc in newState . video . superSources ) {
142
+ const newSsProperties = newState . video . superSources [ ssrc ] . border
143
+ const oldSsProperties = oldState . video . superSources [ ssrc ] . border
144
+ const props : Partial < VideoState . SuperSourceBorder > = { }
145
+
146
+ for ( let key in newSsProperties ) {
147
+ const typedKey = key as keyof VideoState . SuperSourceBorder
148
+ if ( newSsProperties [ typedKey ] !== oldSsProperties [ typedKey ] ) {
149
+ props [ typedKey ] = newSsProperties [ typedKey ]
150
+ }
151
+ }
152
+
153
+ if ( Object . keys ( props ) . length > 0 ) {
154
+ const command = new AtemCommands . SuperSourceBorderCommand ( )
155
+ command . ssrcId = Number ( ssrc )
49
156
command . updateProps ( props )
50
157
commands . push ( command )
51
158
}
0 commit comments