Skip to content

Commit 938cb38

Browse files
committed
chore: skip keyer transitions if ME doesn't diff
1 parent 454d19e commit 938cb38

File tree

5 files changed

+33
-15
lines changed

5 files changed

+33
-15
lines changed

src/resolvers/__tests__/downstreamKeyer.spec.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { resolveDownstreamKeyerState } from '../downstreamKeyer'
22
import { Commands, VideoState } from 'atem-connection'
33
import * as Defaults from '../../defaults'
44
import { jsonClone } from '../../util'
5-
import { DiffDownstreamKeyer } from '../../diff'
5+
import { DiffDownstreamKeyer, SectionsToDiff } from '../../diff'
66

77
function setupDSK(props?: Partial<VideoState.DSK.DownstreamKeyer>): Required<VideoState.DSK.DownstreamKeyer> {
88
return jsonClone({
@@ -19,11 +19,13 @@ function setupDSK(props?: Partial<VideoState.DSK.DownstreamKeyer>): Required<Vid
1919
const DSK1 = [setupDSK(), setupDSK()]
2020
const DSK2 = [setupDSK(), setupDSK()]
2121

22-
const fullDiff: Required<DiffDownstreamKeyer> = {
23-
sources: true,
24-
onAir: true,
25-
properties: true,
26-
mask: true,
22+
const fullDiff: SectionsToDiff['video'] & { downstreamKeyers: Required<DiffDownstreamKeyer> } = {
23+
downstreamKeyers: {
24+
sources: true,
25+
onAir: true,
26+
properties: true,
27+
mask: true,
28+
},
2729
}
2830

2931
test('Unit: Downstream keyer: same state gives no commands', function () {
@@ -164,3 +166,14 @@ test('Unit: Downstream keyer: mask', function () {
164166
right: 0,
165167
}
166168
})
169+
170+
test('Unit: Downstream keyer: onAir with tie returns doTransition', function () {
171+
DSK2[0].properties.tie = true
172+
DSK2[0].onAir = true
173+
const { commands, doTransition } = resolveDownstreamKeyerState(DSK1, DSK2, {
174+
...fullDiff,
175+
mixEffects: { programPreview: true },
176+
})
177+
expect(doTransition).toBe(true)
178+
expect(commands.filter((c) => c.constructor.name === 'DownstreamKeyOnAirCommand')).toHaveLength(0)
179+
})

src/resolvers/__tests__/mixEffect.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ test('Unit: mix effect: program + preview', function () {
8989
ME2.programInput = 1
9090
ME2.transition = Enums.TransitionStyle.CUT
9191
const commands = ME.resolveMixEffectsState([ME1], [ME2], fullDiffObject) as Array<
92-
Commands.PreviewInputCommand | Commands.PreviewInputCommand
92+
Commands.ProgramInputCommand | Commands.PreviewInputCommand
9393
>
9494
expect(commands).toHaveLength(2)
9595

src/resolvers/downstreamKeyer.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,23 @@ import { Commands as AtemCommands, VideoState } from 'atem-connection'
22
import { PartialDeep } from 'type-fest'
33
import * as Defaults from '../defaults'
44
import { getAllKeysNumber, diffObject, fillDefaults } from '../util'
5-
import { DiffDownstreamKeyer } from '../diff'
5+
import { SectionsToDiff } from '../diff'
66

77
export function resolveDownstreamKeyerState(
88
oldDsks: Array<PartialDeep<VideoState.DSK.DownstreamKeyer> | undefined> | undefined,
99
newDsks: Array<PartialDeep<VideoState.DSK.DownstreamKeyer> | undefined> | undefined,
10-
diffOptions: DiffDownstreamKeyer | DiffDownstreamKeyer[]
10+
diffOptions: SectionsToDiff['video']
1111
): { commands: Array<AtemCommands.ISerializableCommand>; doTransition: boolean } {
12+
const canUseMixEffectTransition =
13+
(Array.isArray(diffOptions?.mixEffects) ? diffOptions?.mixEffects[0] : diffOptions?.mixEffects)?.programPreview ??
14+
false
1215
const commands: Array<AtemCommands.ISerializableCommand> = []
1316
let doTransition = false
1417

1518
for (const index of getAllKeysNumber(oldDsks, newDsks)) {
16-
const thisDiffOptions = Array.isArray(diffOptions) ? diffOptions[index] : diffOptions
19+
const thisDiffOptions = Array.isArray(diffOptions?.downstreamKeyers)
20+
? diffOptions?.downstreamKeyers[index]
21+
: diffOptions?.downstreamKeyers
1722

1823
if (thisDiffOptions) {
1924
const oldDsk = fillDefaults(Defaults.Video.DownstreamKeyer, oldDsks?.[index])
@@ -42,7 +47,7 @@ export function resolveDownstreamKeyerState(
4247
if (!oldDsk.isAuto && newDsk.isAuto) {
4348
commands.push(new AtemCommands.DownstreamKeyAutoCommand(index))
4449
} else if (oldDsk.onAir !== newDsk.onAir) {
45-
if (newDsk.properties?.tie) {
50+
if (newDsk.properties?.tie && canUseMixEffectTransition) {
4651
doTransition = true
4752
} else {
4853
const command = new AtemCommands.DownstreamKeyOnAirCommand(index, newDsk.onAir)

src/resolvers/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function diffState(
2626
const dskDiff = resolveDownstreamKeyerState(
2727
oldState.video?.downstreamKeyers,
2828
newState.video?.downstreamKeyers,
29-
diffOptions.video.downstreamKeyers
29+
diffOptions.video
3030
)
3131

3232
commands.push(...dskDiff.commands)

src/resolvers/mixEffect.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ export function resolveMixEffectsState(
4848
mixEffectId,
4949
oldMixEffect?.upstreamKeyers,
5050
newMixEffect?.upstreamKeyers,
51-
newMixEffect?.transitionProperties?.nextSelection,
51+
thisDiffOptions.programPreview ? newMixEffect?.transitionProperties?.nextSelection : undefined,
5252
thisDiffOptions.upstreamKeyers
5353
)
5454
commands.push(...uskDiff.commands)
55-
doTransition = uskDiff.doTransition
55+
doTransition = uskDiff.doTransition || dskTransition
5656
}
5757

5858
if (thisDiffOptions.programPreview) {
@@ -63,7 +63,7 @@ export function resolveMixEffectsState(
6363
const nextSelection =
6464
newMixEffect?.transitionProperties?.nextSelection ?? Defaults.Video.TransitionProperties.nextSelection
6565
const transitionIsBg =
66-
nextSelection.length === 0 ||
66+
nextSelection.length === 0 || // note - can't set empty array in atem so use defaults anyway
6767
!!nextSelection?.find((layer) => layer === ConnectionEnums.TransitionSelection.Background)
6868
doTransition = doTransition || (programInput !== oldProgramInput && transition !== Enums.TransitionStyle.CUT)
6969

0 commit comments

Comments
 (0)