Skip to content

Commit

Permalink
feat(EAV-343): support index (list, photo, virtual set) in vMix
Browse files Browse the repository at this point in the history
  • Loading branch information
ianshade committed Nov 26, 2024
1 parent 3e5de55 commit 02db182
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export enum VMixCommand {
LIST_ADD = 'LIST_ADD',
LIST_REMOVE_ALL = 'LIST_REMOVE_ALL',
RESTART_INPUT = 'RESTART_INPUT',
SELECT_INDEX = 'SELECT_INDEX',
}

export type TimelineContentVMixAny =
Expand Down Expand Up @@ -188,6 +189,13 @@ export interface TimelineContentVMixInput extends TimelineContentVMixBase {

/** If media should start from the beginning or resume from where it left off */
restart?: boolean

/**
* Photos, List: Selects item in List
* Virtual Set: Zooms to selected preset using the current speed settings
* starts from 1
*/
index?: number
}

export interface TimelineContentVMixOutput extends TimelineContentVMixBase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,19 @@ describe('VMixCommandSender', () => {
value: 1.5,
})
})

it('selects index', async () => {
const { sender, mockConnection } = createTestee()
await sender.sendCommand({
command: VMixCommand.SELECT_INDEX,
input: 5,
value: 3,
})

expect(mockConnection.sendCommandFunction).toHaveBeenCalledTimes(1)
expect(mockConnection.sendCommandFunction).toHaveBeenLastCalledWith('SelectIndex', {
input: 5,
value: 3,
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,26 @@ describe('VMixStateDiffer', () => {
cropBottom: 0.8,
})
})

it('sets index', () => {
const differ = createTestee()

const oldState = makeMockFullState()
const newState = makeMockFullState()

oldState.reportedState.existingInputs['99'] = differ.getDefaultInputState(99)

newState.reportedState.existingInputs['99'] = differ.getDefaultInputState(99)
const index = 3
newState.reportedState.existingInputs['99'].index = index

const commands = differ.getCommandsToAchieveState(Date.now(), oldState, newState)

expect(commands.length).toBe(1)
expect(commands[0].command).toMatchObject({
command: VMixCommand.SELECT_INDEX,
input: '99',
value: index,
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,27 @@ describe('VMixTimelineStateConverter', () => {
expect(result.reportedState.inputsAddedByUsAudio[prefixAddedInput(filePath)]).toBeUndefined()
})

it('supports index', () => {
const converter = createTestee()
const index = 3
const result = converter.getVMixStateFromTimelineState(
wrapInTimelineState({
inp0: wrapInTimelineObject('inp0', {
deviceType: DeviceType.VMIX,
index,
type: TimelineContentTypeVMix.INPUT,
}),
}),
{
inp0: wrapInMapping({
mappingType: MappingVmixType.Input,
index: '1',
}),
}
)
expect(result.reportedState.existingInputs['1'].index).toEqual(index)
})

// TODO: maybe we can't trust the defaults when adding an input? Make this test pass eventually
// it('tracks audio state for mapped inputs added by us', () => {
// const converter = createTestee()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ export class VMixCommandSender {
return this.listRemoveAll(command.input)
case VMixCommand.RESTART_INPUT:
return this.restart(command.input)
case VMixCommand.SELECT_INDEX:
return this.selectIndex(command.input, command.value)
default:
throw new Error(`vmixAPI: Command ${((command || {}) as any).command} not implemented`)
}
Expand Down Expand Up @@ -467,6 +469,10 @@ export class VMixCommandSender {
return this.sendCommandFunction(`Restart`, { input })
}

public async selectIndex(input: string | number, value: number): Promise<any> {
return this.sendCommandFunction(`SelectIndex`, { input, value })
}

private async sendCommandFunction(func: string, args: SentCommandArgs) {
return this.vMixConnection.sendCommandFunction(func, args)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ export interface VMixStateCommandRestart extends VMixStateCommandBase {
command: VMixCommand.RESTART_INPUT
input: string | number
}
export interface VMixStateCommanSelectIndex extends VMixStateCommandBase {
command: VMixCommand.SELECT_INDEX
input: string | number
value: number
}
export type VMixStateCommand =
| VMixStateCommandPreviewInput
| VMixStateCommandTransition
Expand Down Expand Up @@ -248,6 +253,7 @@ export type VMixStateCommand =
| VMixStateCommandListAdd
| VMixStateCommandListRemoveAll
| VMixStateCommandRestart
| VMixStateCommanSelectIndex

export enum CommandContext {
None = 'none',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export interface VMixInput {
layers?: VMixLayers
listFilePaths?: string[]
restart?: boolean
index?: number
}

export interface VMixInputAudio {
Expand Down Expand Up @@ -583,6 +584,17 @@ export class VMixStateDiffer {
timelineId: '',
})
}
if (input.index !== undefined && oldInput.index !== input.index) {
commands.push({
command: {
command: VMixCommand.SELECT_INDEX,
input: key,
value: input.index,
},
context: CommandContext.None,
timelineId: '',
})
}
return { preTransitionCommands, postTransitionCommands }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export class VMixTimelineStateConverter {
(content.overlays ? this._convertDeprecatedInputOverlays(content.overlays) : undefined),
listFilePaths: content.listFilePaths,
restart: content.restart,
index: content.index,
},
{ key: mapping.options.index, filePath: content.filePath },
layerName
Expand Down

0 comments on commit 02db182

Please sign in to comment.