Skip to content

Commit 425a245

Browse files
committed
fix: update to newer atem-connection api
1 parent 43f7bb8 commit 425a245

21 files changed

+115
-115
lines changed

src/__tests__/atemState.spec.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { AtemState, State as StateObject } from '../'
1+
import { AtemState } from '../'
2+
import { AtemStateUtil } from 'atem-connection'
23

34
test('Unit test: Atem State: Set State', function () {
45
const state = new AtemState()
56

6-
const newObj = new StateObject()
7+
const newObj = AtemStateUtil.Create()
78
;(newObj.video.auxilliaries as number[]) = [0, 0, 1]
89
state.setState(newObj)
910

@@ -13,11 +14,11 @@ test('Unit test: Atem State: Set State', function () {
1314
test('Unit test: Atem State: Diff State', function () {
1415
const state = new AtemState()
1516

16-
const newObj = new StateObject()
17+
const newObj = AtemStateUtil.Create()
1718
;(newObj.video.auxilliaries as number[]) = [0, 0, 1]
1819
state.setState(newObj)
1920

20-
const newObj2 = new StateObject()
21+
const newObj2 = AtemStateUtil.Create()
2122
;(newObj2.video.auxilliaries as number[]) = [0, 0, 2]
2223
const commands = state.diffState(newObj2)
2324

src/atemState.ts

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

@@ -8,7 +8,7 @@ export class AtemState {
88
private _state: StateObject
99

1010
public constructor () {
11-
this._state = new StateObject()
11+
this._state = AtemStateUtil.Create()
1212
}
1313

1414
setState (state: StateObject) {

src/defaults.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ export namespace Defaults {
173173
}
174174
}
175175

176-
export const SuperSourceBox: VideoState.SuperSourceBox = {
176+
export const SuperSourceBox: VideoState.SuperSource.SuperSourceBox = {
177177
enabled: false,
178178
source: defaultInput,
179179
x: 0,
@@ -186,7 +186,7 @@ export namespace Defaults {
186186
cropRight: 0
187187
}
188188

189-
export const SuperSourceProperties: VideoState.SuperSourceProperties = {
189+
export const SuperSourceProperties: VideoState.SuperSource.SuperSourceProperties = {
190190
artFillSource: defaultInput,
191191
artCutSource: defaultInput,
192192
artOption: Enums.SuperSourceArtOption.Background,
@@ -196,7 +196,7 @@ export namespace Defaults {
196196
artInvertKey: false
197197
}
198198

199-
export const SuperSourceBorder: VideoState.SuperSourceBorder = {
199+
export const SuperSourceBorder: VideoState.SuperSource.SuperSourceBorder = {
200200
borderEnabled: false,
201201
borderBevel: Enums.BorderBevel.None,
202202
borderOuterWidth: 0,

src/resolvers/__tests__/audio.spec.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { State as StateObject } from '../../'
21
import * as audio from '../audio'
32
import * as _ from 'underscore'
43
import { jsonClone } from '../../util'
5-
import { AudioState, Commands } from 'atem-connection'
4+
import { AudioState, Commands, AtemStateUtil } from 'atem-connection'
65

76
function literal<T> (o: T) { return o }
87

9-
const STATE1 = new StateObject()
8+
const STATE1 = AtemStateUtil.Create()
109
STATE1.audio.channels = [
1110
literal<AudioState.AudioChannel>({
1211
sourceType: 0,
@@ -23,7 +22,7 @@ STATE1.audio.channels = [
2322
balance: 4
2423
})
2524
]
26-
const STATE2 = new StateObject()
25+
const STATE2 = AtemStateUtil.Create()
2726
STATE2.audio.channels = jsonClone(STATE1.audio.channels)
2827
STATE2.audio.master = {
2928
gain: 0,

src/resolvers/__tests__/auxiliaries.spec.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import * as video from '../index'
2-
import { State as StateObject } from '../../'
3-
import { Commands, Enums } from 'atem-connection'
2+
import { Commands, Enums, AtemStateUtil } from 'atem-connection'
43

5-
const STATE1 = new StateObject()
4+
const STATE1 = AtemStateUtil.Create()
65
;(STATE1.video.auxilliaries as number[]) = [ 0, 0, 0, 2 ]
76

8-
const STATE2 = new StateObject()
7+
const STATE2 = AtemStateUtil.Create()
98
;(STATE2.video.auxilliaries as number[]) = [ 1, 0, 2, 0 ]
109

1110
test('Unit: auxiliaries: same state gives no commands', function () {

src/resolvers/__tests__/downstreamKeyer.spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import * as DSK from '../downstreamKeyer'
22
import { State as StateObject } from '../../'
3-
import { Commands } from 'atem-connection'
3+
import { Commands, AtemStateUtil } from 'atem-connection'
44
import * as _ from 'underscore'
55
import { Defaults } from '../../defaults'
66
import { jsonClone } from '../../util'
77

88
function setupDSK (state: StateObject, index: number) {
9-
const dsk = state.video.getDownstreamKeyer(index)
9+
const dsk = AtemStateUtil.getDownstreamKeyer(state, index)
1010
dsk.properties = jsonClone(Defaults.Video.DownstreamerKeyerProperties)
1111
dsk.sources = jsonClone(Defaults.Video.DownstreamerKeyerSources)
1212
return dsk
1313
}
1414

15-
const STATE1 = new StateObject()
15+
const STATE1 = AtemStateUtil.Create()
1616
setupDSK(STATE1, 0)
1717
setupDSK(STATE1, 1)
1818

19-
const STATE2 = new StateObject()
19+
const STATE2 = AtemStateUtil.Create()
2020
const DSK1 = setupDSK(STATE2, 0)
2121
const DSK2 = setupDSK(STATE2, 1)
2222

src/resolvers/__tests__/macro.spec.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
import * as video from '../index'
2-
import { State as StateObject } from '../../'
3-
import { Commands, Enums } from 'atem-connection'
2+
import { Commands, Enums, AtemStateUtil } from 'atem-connection'
43

5-
const STATE1 = new StateObject()
4+
const STATE1 = AtemStateUtil.Create()
65
STATE1.macro.macroPlayer = {
76
isRunning: true,
87
isWaiting: false,
98
loop: true,
109
macroIndex: 12
1110
}
1211

13-
const STATE2 = new StateObject()
12+
const STATE2 = AtemStateUtil.Create()
1413
STATE2.macro.macroPlayer = {
1514
isRunning: true,
1615
isWaiting: false,
1716
loop: true,
1817
macroIndex: 10
1918
}
2019

21-
const STATE3 = new StateObject()
20+
const STATE3 = AtemStateUtil.Create()
2221
STATE3.macro.macroPlayer = {
2322
isRunning: false,
2423
isWaiting: false,

src/resolvers/__tests__/media.spec.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import * as media from '../media'
2-
import { State as StateObject } from '../../'
3-
import { Commands, Enums, MediaState } from 'atem-connection'
2+
import { Commands, Enums, MediaState, AtemStateUtil } from 'atem-connection'
43

5-
const STATE1 = new StateObject()
4+
const STATE1 = AtemStateUtil.Create()
65
;(STATE1.media.players as MediaState.MediaPlayerState[]) = [
76
{
87
playing: false,
@@ -23,7 +22,7 @@ const STATE1 = new StateObject()
2322
clipIndex: 0
2423
}
2524
]
26-
const STATE2 = new StateObject()
25+
const STATE2 = AtemStateUtil.Create()
2726
;(STATE2.media.players as MediaState.MediaPlayerState[]) = [
2827
{
2928
playing: true,

src/resolvers/__tests__/mixEffect.spec.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import * as ME from '../mixEffect'
2-
import { State as StateObject, Enums, MixEffect, Defaults } from '../../'
3-
import { Commands, Enums as AtemEnums } from 'atem-connection'
2+
import { Enums, MixEffect, Defaults } from '../../'
3+
import { Commands, Enums as AtemEnums, AtemStateUtil } from 'atem-connection'
44
import { jsonClone } from '../../util'
55

6-
const STATE1 = new StateObject()
7-
const ME1 = STATE1.video.getMe(0) as MixEffect
8-
const STATE2 = new StateObject()
9-
const ME2 = STATE2.video.getMe(0) as MixEffect
6+
const STATE1 = AtemStateUtil.Create()
7+
const ME1 = AtemStateUtil.getMixEffect(STATE1, 0) as MixEffect
8+
const STATE2 = AtemStateUtil.Create()
9+
const ME2 = AtemStateUtil.getMixEffect(STATE2, 0) as MixEffect
1010

1111
test('Unit: mix effect: same state gives no commands', function () {
1212
// same state gives no commands:

src/resolvers/__tests__/supersourceBox.spec.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import * as supersource from '../supersource'
2-
import { State as StateObject, Defaults } from '../../'
3-
import { Commands, Enums } from 'atem-connection'
2+
import { Defaults } from '../../'
3+
import { Commands, Enums, AtemStateUtil } from 'atem-connection'
44
import * as _ from 'underscore'
55
import { jsonClone } from '../../util'
66

7-
const STATE1 = new StateObject()
8-
const SSRC1 = STATE1.video.getSuperSource(0)
7+
const STATE1 = AtemStateUtil.Create()
8+
const SSRC1 = AtemStateUtil.getSuperSource(STATE1, 0)
99
SSRC1.boxes[0] = jsonClone(Defaults.Video.SuperSourceBox)
1010
SSRC1.boxes[1] = jsonClone(Defaults.Video.SuperSourceBox)
1111
SSRC1.boxes[2] = jsonClone(Defaults.Video.SuperSourceBox)
1212
SSRC1.boxes[3] = jsonClone(Defaults.Video.SuperSourceBox)
1313
SSRC1.border = jsonClone(Defaults.Video.SuperSourceBorder)
1414
SSRC1.properties = jsonClone(Defaults.Video.SuperSourceProperties)
1515

16-
const STATE2 = new StateObject()
17-
const SSRC2 = STATE2.video.getSuperSource(0)
16+
const STATE2 = AtemStateUtil.Create()
17+
const SSRC2 = AtemStateUtil.getSuperSource(STATE2, 0)
1818
SSRC2.boxes[0] = {
1919
enabled: true,
2020
source: 1,
@@ -70,7 +70,7 @@ test('Unit: super source boxes: box removed', function () {
7070
})
7171

7272
test('Unit: super source boxes: new box', function () {
73-
STATE1.video.getSuperSource(0).boxes[0] = jsonClone(Defaults.Video.SuperSourceBox)
73+
AtemStateUtil.getSuperSource(STATE1, 0).boxes[0] = jsonClone(Defaults.Video.SuperSourceBox)
7474
const commands = supersource.resolveSuperSourceState(STATE1, STATE2, Enums.ProtocolVersion.V7_2) as Array<Commands.SuperSourceBoxParametersCommand>
7575

7676
expect(commands[0].constructor.name).toEqual('SuperSourceBoxParametersCommand')
@@ -89,7 +89,7 @@ test('Unit: super source boxes: new box', function () {
8989
cropRight: 1
9090
})
9191

92-
STATE1.video.getSuperSource(0).boxes[0] = STATE2.video.getSuperSource(0).boxes[0]
92+
AtemStateUtil.getSuperSource(STATE1, 0).boxes[0] = AtemStateUtil.getSuperSource(STATE2, 0).boxes[0]
9393
})
9494

9595
test('Unit: super source properties: same state gives no commands', function () {
@@ -155,8 +155,8 @@ test('Unit: super source border v8: some properties changed', function () {
155155
})
156156

157157
test('Unit: super source box v8: 2 super sources', function () {
158-
STATE1.video.superSources[1] = jsonClone(STATE1.video.getSuperSource(0))
159-
const newSSrc = STATE2.video.superSources[1] = jsonClone(STATE1.video.getSuperSource(0))
158+
STATE1.video.superSources[1] = jsonClone(AtemStateUtil.getSuperSource(STATE1, 0))
159+
const newSSrc = STATE2.video.superSources[1] = jsonClone(AtemStateUtil.getSuperSource(STATE1, 0))
160160
newSSrc.boxes[0]!.cropped = false
161161

162162
const commands = supersource.resolveSuperSourceBoxState(STATE1, STATE2, Enums.ProtocolVersion.V8_0) as Array<Commands.SuperSourceBoxParametersCommand>

src/resolvers/downstreamKeyer.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
Commands as AtemCommands, VideoState
2+
Commands as AtemCommands, VideoState, AtemStateUtil
33
} from 'atem-connection'
44
import { State as StateObject, Defaults } from '../'
55
import { getAllKeysNumber, diffObject } from '../util'
@@ -8,8 +8,8 @@ export function resolveDownstreamKeyerState (oldState: StateObject, newState: St
88
const commands: Array<AtemCommands.ISerializableCommand> = []
99

1010
for (const index of getAllKeysNumber(oldState.video.downstreamKeyers, newState.video.downstreamKeyers)) {
11-
const oldDsk = oldState.video.getDownstreamKeyer(index, true)
12-
const newDsk = newState.video.getDownstreamKeyer(index, true)
11+
const oldDsk = AtemStateUtil.getDownstreamKeyer(newState, index, true)
12+
const newDsk = AtemStateUtil.getDownstreamKeyer(oldState, index, true)
1313

1414
commands.push(...resolveDownstreamKeyerPropertiesState(index, oldDsk, newDsk))
1515
commands.push(...resolveDownstreamKeyerMaskState(index, oldDsk, newDsk))

src/resolvers/media.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
Commands as AtemCommands
2+
Commands as AtemCommands, AtemStateUtil
33
} from 'atem-connection'
44
import { State as StateObject } from '../'
55
import { diffObject, getAllKeysNumber } from '../util'
@@ -8,8 +8,8 @@ export function resolveMediaPlayerState (oldState: StateObject, newState: StateO
88
const commands: Array<AtemCommands.ISerializableCommand> = []
99

1010
for (const index of getAllKeysNumber(oldState.media.players, newState.media.players)) {
11-
const newPlayer = newState.media.getMediaPlayer(index, true)
12-
const oldPlayer = oldState.media.getMediaPlayer(index, true)
11+
const newPlayer = AtemStateUtil.getMediaPlayer(newState, index, true)
12+
const oldPlayer = AtemStateUtil.getMediaPlayer(oldState, index, true)
1313

1414
const props = diffObject(oldPlayer, newPlayer)
1515
const command = new AtemCommands.MediaPlayerStatusCommand(index)

src/resolvers/mixEffect.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
Commands as AtemCommands,
3-
Enums as ConnectionEnums
3+
Enums as ConnectionEnums,
4+
AtemStateUtil
45
} from 'atem-connection'
56
import { Enums, State as StateObject, Defaults } from '../'
67
import { getAllKeysNumber, diffObject } from '../util'
@@ -12,9 +13,9 @@ import { resolveUpstreamKeyerState } from './upstreamKeyers'
1213
export function resolveMixEffectsState (oldState: StateObject, newState: StateObject): Array<AtemCommands.ISerializableCommand> {
1314
const commands: Array<AtemCommands.ISerializableCommand> = []
1415

15-
for (const mixEffectId of getAllKeysNumber(oldState.video.ME, newState.video.ME)) {
16-
const oldMixEffect: MixEffect = oldState.video.getMe(mixEffectId, true)
17-
const newMixEffect: MixEffect = newState.video.getMe(mixEffectId, true)
16+
for (const mixEffectId of getAllKeysNumber(oldState.video.mixEffects, newState.video.mixEffects)) {
17+
const oldMixEffect: MixEffect = AtemStateUtil.getMixEffect(oldState, mixEffectId, true)
18+
const newMixEffect: MixEffect = AtemStateUtil.getMixEffect(newState, mixEffectId, true)
1819

1920
commands.push(...resolveTransitionPropertiesState(mixEffectId, oldMixEffect, newMixEffect))
2021
commands.push(...resolveTransitionSettingsState(mixEffectId, oldMixEffect, newMixEffect))

src/resolvers/supersource.ts

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import {
2-
Commands as AtemCommands, VideoState, Enums
2+
Commands as AtemCommands, VideoState, Enums, AtemStateUtil
33
} from 'atem-connection'
44
import { State as StateObject } from '..'
55
import { diffObject, getAllKeysNumber } from '../util'
66
import { Defaults } from '../defaults'
77

8+
type SuperSourceCombinedProperties = VideoState.SuperSource.SuperSourceProperties & VideoState.SuperSource.SuperSourceBorder
9+
810
export function resolveSuperSourceState (oldState: StateObject, newState: StateObject, version: Enums.ProtocolVersion): Array<AtemCommands.ISerializableCommand> {
911
const commands: Array<AtemCommands.ISerializableCommand> = []
1012

@@ -29,8 +31,8 @@ export function resolveSuperSourceBoxState (oldState: StateObject, newState: Sta
2931
continue
3032
}
3133

32-
const newSSrc = newState.video.getSuperSource(ssrc, true)
33-
const oldSSrc = oldState.video.getSuperSource(ssrc, true)
34+
const newSSrc = AtemStateUtil.getSuperSource(newState, ssrc, true)
35+
const oldSSrc = AtemStateUtil.getSuperSource(oldState, ssrc, true)
3436
for (const index in newSSrc.boxes) {
3537
const props = diffObject(oldSSrc.boxes[index] || Defaults.Video.SuperSourceBox, newSSrc.boxes[index] || Defaults.Video.SuperSourceBox)
3638
const command = new AtemCommands.SuperSourceBoxParametersCommand(ssrc, Number(index))
@@ -47,14 +49,14 @@ export function resolveSuperSourcePropertiesState (oldState: StateObject, newSta
4749
const commands: Array<AtemCommands.ISerializableCommand> = []
4850

4951
if (!newState.video.superSources[0] && !oldState.video.superSources[0]) return commands
50-
const newSSrc = newState.video.getSuperSource(0, true)
51-
const oldSSrc = oldState.video.getSuperSource(0, true)
52+
const newSSrc = AtemStateUtil.getSuperSource(newState, 0, true)
53+
const oldSSrc = AtemStateUtil.getSuperSource(oldState, 0, true)
5254

53-
const newSsProperties: Partial<VideoState.SuperSourceProperties & VideoState.SuperSourceBorder> = {
55+
const newSsProperties: Partial<SuperSourceCombinedProperties> = {
5456
...newSSrc.properties,
5557
...newSSrc.border
5658
}
57-
const oldSsProperties: Partial<VideoState.SuperSourceProperties & VideoState.SuperSourceBorder> = {
59+
const oldSsProperties: Partial<SuperSourceCombinedProperties> = {
5860
...oldSSrc.properties,
5961
...oldSSrc.border
6062
}
@@ -72,8 +74,8 @@ export function resolveSuperSourcePropertiesV8State (oldState: StateObject, newS
7274
const commands: Array<AtemCommands.ISerializableCommand> = []
7375

7476
for (const ssrc of getAllKeysNumber(oldState.video.superSources, newState.video.superSources).sort()) {
75-
const newSSrc = newState.video.getSuperSource(ssrc, true)
76-
const oldSSrc = oldState.video.getSuperSource(ssrc, true)
77+
const newSSrc = AtemStateUtil.getSuperSource(newState, ssrc, true)
78+
const oldSSrc = AtemStateUtil.getSuperSource(oldState, ssrc, true)
7779

7880
const props = diffObject(oldSSrc.properties || Defaults.Video.SuperSourceProperties, newSSrc.properties || Defaults.Video.SuperSourceProperties)
7981
const command = new AtemCommands.SuperSourcePropertiesV8Command(ssrc)
@@ -89,8 +91,8 @@ export function resolveSuperSourceBorderV8State (oldState: StateObject, newState
8991
const commands: Array<AtemCommands.ISerializableCommand> = []
9092

9193
for (const ssrc of getAllKeysNumber(oldState.video.superSources, newState.video.superSources).sort()) {
92-
const newSSrc = newState.video.getSuperSource(ssrc, true)
93-
const oldSSrc = oldState.video.getSuperSource(ssrc, true)
94+
const newSSrc = AtemStateUtil.getSuperSource(newState, ssrc, true)
95+
const oldSSrc = AtemStateUtil.getSuperSource(oldState, ssrc, true)
9496

9597
const props = diffObject(oldSSrc.border || Defaults.Video.SuperSourceBorder, newSSrc.border || Defaults.Video.SuperSourceBorder)
9698
const command = new AtemCommands.SuperSourceBorderCommand(ssrc)

0 commit comments

Comments
 (0)