Skip to content

Commit

Permalink
fix(vmix): account for the fact that some mixes may temporarily be un…
Browse files Browse the repository at this point in the history
…defined in the state
  • Loading branch information
Alex Van Camp committed Jun 6, 2023
1 parent e4e380e commit 50ffe80
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions packages/timeline-state-resolver/src/integrations/vmix/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export class VMixDevice extends DeviceWithState<VMixStateExtended, DeviceOptions
}

const previousStateTime = Math.max(this.getCurrentTime() + 0.1, newState.time)
const oldState: VMixStateExtended = (this.getStateBefore(previousStateTime) || { state: this._getDefaultState() })
const oldState: VMixStateExtended = (this.getStateBefore(previousStateTime) ?? { state: this._getDefaultState() })
.state

const newVMixState = this.convertStateToVMix(newState, newMappings)
Expand Down Expand Up @@ -577,17 +577,20 @@ export class VMixDevice extends DeviceWithState<VMixStateExtended, DeviceOptions
): Array<VMixStateCommandWithContext> {
const commands: Array<VMixStateCommandWithContext> = []
for (let i = 0; i < 4; i++) {
const oldMixState = oldVMixState.reportedState.mixes[i]
const newMixState = newVMixState.reportedState.mixes[i]
if (newMixState.program !== undefined) {
/**
* It is *not* guaranteed to have all 4 mixes present in the vMix state, for reasons unknown.
*/
const oldMixState = oldVMixState.reportedState.mixes[i] as VMixMix | undefined
const newMixState = newVMixState.reportedState.mixes[i] as VMixMix | undefined
if (newMixState?.program !== undefined) {
let nextInput = newMixState.program
let changeOnLayer = false
if (newMixState.layerToProgram) {
nextInput = newVMixState.inputLayers[newMixState.program]
changeOnLayer =
newVMixState.inputLayers[newMixState.program] !== oldVMixState.inputLayers[newMixState.program]
}
if (oldMixState.program !== newMixState.program || changeOnLayer) {
if (oldMixState?.program !== newMixState.program || changeOnLayer) {
commands.push({
command: {
command: VMixCommand.TRANSITION,
Expand All @@ -603,9 +606,9 @@ export class VMixDevice extends DeviceWithState<VMixStateExtended, DeviceOptions
}

if (
oldMixState.program === newMixState.program && // if we're not switching what is on program, because it could break a transition
newMixState.preview !== undefined &&
newMixState.preview !== oldMixState.preview
oldMixState?.program === newMixState?.program && // if we're not switching what is on program, because it could break a transition
newMixState?.preview !== undefined &&
newMixState.preview !== oldMixState?.preview
) {
commands.push({
command: {
Expand Down

0 comments on commit 50ffe80

Please sign in to comment.