Skip to content

Commit cae23ff

Browse files
author
Balte de Wit
committed
feat: support v8
1 parent 40fef44 commit cae23ff

File tree

4 files changed

+135
-18
lines changed

4 files changed

+135
-18
lines changed

src/atemState.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { Commands } from 'atem-connection'
1+
import { Commands, Enums } from 'atem-connection'
22
import { State as StateObject } from '.'
33
import * as Resolvers from './resolvers'
44

55
export class AtemState {
6+
version: Enums.ProtocolVersion = Enums.ProtocolVersion.V7_2
7+
68
private _state: StateObject
79

810
setState (state: StateObject) {
@@ -20,7 +22,7 @@ export class AtemState {
2022
diffStates (oldState: StateObject, newState: StateObject): Array<Commands.AbstractCommand> {
2123
let commands: Array<Commands.AbstractCommand> = []
2224

23-
commands = commands.concat(Resolvers.videoState(oldState, newState))
25+
commands = commands.concat(Resolvers.videoState(oldState, newState, this.version))
2426

2527
return commands
2628
}

src/defaults.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,12 @@ export namespace Defaults {
105105
inTransition: false,
106106
transitionPreview: false,
107107
transitionPosition: 0,
108-
fadeToBlack: false,
108+
fadeToBlack: {
109+
isFullyBlack: false,
110+
remainingFrames: 0,
111+
rate: defaultRate,
112+
inTransition: false
113+
},
109114
transitionProperties: TransitionProperties as VideoState.TransitionProperties,
110115
transitionSettings: TransitionSettings,
111116
upstreamKeyers: []
@@ -245,7 +250,10 @@ export namespace Defaults {
245250
artPreMultiplied: false,
246251
artClip: 0,
247252
artGain: 0,
248-
artInvertKey: false,
253+
artInvertKey: false
254+
}
255+
256+
export const SuperSourceBorder: VideoState.SuperSourceBorder = {
249257
borderEnabled: false,
250258
borderBevel: Enums.BorderBevel.None,
251259
borderOuterWidth: 0,

src/resolvers/index.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import {
2-
Commands as AtemCommands } from 'atem-connection'
2+
Commands as AtemCommands,
3+
Enums } from 'atem-connection'
34
import { State as StateObject } from '../'
45

56
import { resolveMixEffectsState } from './mixEffect'
67
import { resolveDownstreamKeyerState } from './downstreamKeyer'
7-
import { resolveSupersourceBoxState, resolveSuperSourcePropertiesState } from './supersource'
8+
import { resolveSuperSourceState } from './supersource'
89
import { resolveAudioState } from './audio'
910

10-
export function videoState (oldState: StateObject, newState: StateObject): Array<AtemCommands.AbstractCommand> {
11+
export function videoState (oldState: StateObject, newState: StateObject, version: Enums.ProtocolVersion): Array<AtemCommands.AbstractCommand> {
1112
let commands: Array<AtemCommands.AbstractCommand> = []
1213

1314
commands = commands.concat(resolveMixEffectsState(oldState, newState))
1415
commands = commands.concat(resolveDownstreamKeyerState(oldState, newState))
15-
commands = commands.concat(resolveSupersourceBoxState(oldState, newState))
16-
commands = commands.concat(resolveSuperSourcePropertiesState(oldState, newState))
16+
commands = commands.concat(resolveSuperSourceState(oldState, newState, version))
1717
commands = commands.concat(resolveAudioState(oldState, newState))
1818

1919
// resolve auxilliaries:

src/resolvers/supersource.ts

+116-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
11
import {
2-
Commands as AtemCommands, VideoState
2+
Commands as AtemCommands, VideoState, Enums
33
} from 'atem-connection'
44
import { State as StateObject } from '..'
55

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> {
726
const commands: Array<AtemCommands.AbstractCommand> = []
827

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] || {}
1231
const props: Partial<VideoState.SuperSourceBox> = {}
1332

1433
for (let key in newBox) {
@@ -20,6 +39,7 @@ export function resolveSupersourceBoxState (oldState: StateObject, newState: Sta
2039

2140
if (Object.keys(props).length > 0) {
2241
const command = new AtemCommands.SuperSourceBoxParametersCommand()
42+
command.ssrcId = 0
2343
command.boxId = Number(index)
2444
command.updateProps(props)
2545
commands.push(command)
@@ -32,9 +52,69 @@ export function resolveSupersourceBoxState (oldState: StateObject, newState: Sta
3252
export function resolveSuperSourcePropertiesState (oldState: StateObject, newState: StateObject): Array<AtemCommands.AbstractCommand> {
3353
const commands: Array<AtemCommands.AbstractCommand> = []
3454

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
38118
const props: Partial<VideoState.SuperSourceProperties> = {}
39119

40120
for (let key in newSsProperties) {
@@ -45,7 +125,34 @@ export function resolveSuperSourcePropertiesState (oldState: StateObject, newSta
45125
}
46126

47127
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)
49156
command.updateProps(props)
50157
commands.push(command)
51158
}

0 commit comments

Comments
 (0)