Skip to content

Commit

Permalink
fix: some command tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Dec 7, 2019
1 parent 1ac7da8 commit 0086eee
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 32 deletions.
1 change: 0 additions & 1 deletion src/commands/DeviceProfile/topologyCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export class TopologyCommand extends DeserializedCommand<AtemCapabilites> {
maxHyperdecks: rawCommand[7],
DVEs: rawCommand[8],
stingers: rawCommand[9],
hasSuperSources: rawCommand[10] !== 0,
superSources: rawCommand[10],
talkbackOverSDI: rawCommand[13]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class MixEffectKeyFlyKeyframeGetCommand extends DeserializedCommand<Upstr
lightSourceDirection: Util.parseNumberBetween(rawCommand.readUInt16BE(40), 0, 65535),
lightSourceAltitude: Util.parseNumberBetween(rawCommand.readUInt8(42), 0, 254),

maskEnabled: rawCommand[43] === 1,
// maskEnabled: rawCommand[43] === 1,
maskTop: Util.parseNumberBetween(rawCommand.readInt16BE(44), -9000, 9000),
maskBottom: Util.parseNumberBetween(rawCommand.readInt16BE(46), -9000, 9000),
maskLeft: Util.parseNumberBetween(rawCommand.readInt16BE(48), -16000, 16000),
Expand Down
48 changes: 28 additions & 20 deletions src/commands/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,24 +227,27 @@ const commandConverters: CommandTestConverterSet = {
'index': 'index'
},
propertyAliases: {
'balance': (v: number) => ({ val: Math.round(v * 10) / 10 }),
'balance': (v: number) => ({ val: Math.round(v) }),
'gain': (v: number) => ({ val: Math.round(v * 100) / 100 })
},
processDeserialized: props => {
props.gain = Math.round(props.gain * 100) / 100
}
},
'CAMI': {
idAliases: {
'index': 'index'
},
propertyAliases: {
'balance': (v: number) => ({ val: Math.round(v * 10) / 10 }),
'gain': (v: number) => ({ val: Math.round(v * 100) / 100 })
'balance': (v: number) => ({ val: Math.round(v * 200) / 200 })
// 'gain': (v: number) => ({ val: Math.round(v * 100) / 100 })
}
},
'AMMO': {
idAliases: {},
propertyAliases: {
'programOutFollowFadeToBlack': (val: any) => ({ val, name: 'followFadeToBlack' }),
'balance': (v: number) => ({ val: Math.round(v * 10) / 10 }),
'balance': (v: number) => ({ val: Math.round(v) }),
'gain': (v: number) => ({ val: Math.round(v * 100) / 100 })
}
},
Expand All @@ -259,10 +262,6 @@ const commandConverters: CommandTestConverterSet = {
'videoSources': (val: any) => ({ val, name: 'sources' }),
'superSource': (val: any) => ({ val, name: 'superSources' }),
'talkbackOverSDI': () => ({ val: 0 }) // @todo: should be fixed in atem-connection
},
customMutate: (obj: any) => {
obj.hasSuperSources = obj.superSources !== 0
return obj
}
},
'FTCD': {
Expand Down Expand Up @@ -771,21 +770,34 @@ const commandConverters: CommandTestConverterSet = {
},
'KKFP': {
idAliases: {
'keyerIndex': 'upstreamKeyerId',
'mixEffectIndex': 'mixEffect'
'upstreamKeyerId': 'keyerIndex',
'mixEffect': 'mixEffectIndex'
},
propertyAliases: {
'bevelPosition': (val: any) => ({ val, name: 'borderBevelPosition' }),
'bevelSoftness': (val: any) => ({ val, name: 'borderBevelSoftness' }),
'innerSoftness': (val: any) => ({ val, name: 'borderInnerSoftness' }),
'innerWidth': (val: any) => ({ val, name: 'borderInnerWidth' }),
'innerWidth': (val: any) => ({ val: Math.round(val * 100), name: 'borderInnerWidth' }),
'keyFrame': (val: any) => ({ val, name: 'keyFrameId' }),
'outerSoftness': (val: any) => ({ val, name: 'borderOuterSoftness' }),
'outerWidth': (val: any) => ({ val, name: 'borderOuterWidth' }),
'xPosition': (val: any) => ({ val, name: 'positionX' }),
'xSize': (val: any) => ({ val, name: 'sizeX' }),
'yPosition': (val: any) => ({ val, name: 'positionY' }),
'ySize': (val: any) => ({ val, name: 'sizeY' })
'outerWidth': (val: any) => ({ val: Math.round(val * 100), name: 'borderOuterWidth' }),
'xPosition': (val: any) => ({ val: Math.round(val * 1000), name: 'positionX' }),
'xSize': (val: any) => ({ val: Math.round(val * 1000), name: 'sizeX' }),
'yPosition': (val: any) => ({ val: Math.round(val * 1000), name: 'positionY' }),
'ySize': (val: any) => ({ val: Math.round(val * 1000), name: 'sizeY' }),
'rotation': (val: any) => ({ val: Math.round(val * 10) }),
'borderHue': (val: any) => ({ val: Math.round(val * 10) }),
'borderLuma': (val: any) => ({ val: Math.round(val * 10) }),
'borderSaturation': (val: any) => ({ val: Math.round(val * 10) }),
'lightSourceDirection': (val: any) => ({ val: Math.round(val * 10) }),
'maskBottom': (val: any) => ({ val: Math.round(val * 1000) }),
'maskTop': (val: any) => ({ val: Math.round(val * 1000) }),
'maskLeft': (val: any) => ({ val: Math.round(val * 1000) }),
'maskRight': (val: any) => ({ val: Math.round(val * 1000) })
},
customMutate: (obj: any) => {
delete obj.maskEnabled
return obj
}
},
'MPCE': {
Expand Down Expand Up @@ -823,10 +835,6 @@ describe('Commands v7.2', () => {
const testCase = TestCases[i]
switch (testCase.name) {
// Temporarily ignore the failures
case 'AMMO':
case 'KKFP': // LibAtem incorrectly(?) uses doubles
case 'CAMI': // floating point errors I think
case 'AMIP': // floating point errors I think
case 'FTSU': // Unkown props getting overwritten by generator: https://github.com/LibAtem/LibAtem/blob/master/LibAtem/Commands/DataTransfer/DataTransferDownloadRequestCommand.cs
case 'TDpP': // Range validation errors
continue
Expand Down
14 changes: 13 additions & 1 deletion src/commands/__tests__/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import { IDeserializedCommand, ISerializableCommand } from '../CommandBase'

export type CommandTestConverterSet = { [key: string]: CommandTestConverter }
export interface CommandTestConverter {
idAliases: { [key: string]: string }
/** Internal name to LibAtem name */
idAliases: { [internalName: string]: string }
/** LibAtem name to Internal name & mutated value */
propertyAliases: { [key: string]: (v: any) => { name?: string, val: any } }
customMutate?: (v: any) => any
/** pre-process deserialized command */
processDeserialized?: (v: any) => void
}

export interface TestCase {
Expand All @@ -19,6 +23,10 @@ export function runTestForCommand (commandParser: CommandParser, commandConverte
const cmdConstructor = commandParser.commandFromRawName(testCase.name)
if (!cmdConstructor && allowUnknown) return

// if (i !== 1121) {
// return
// }

let matchedCase = false
if (cmdConstructor) {
const buffer = Buffer.from(testCase.bytes.replace(/-/g, ''), 'hex')
Expand Down Expand Up @@ -48,6 +56,10 @@ export function runTestForCommand (commandParser: CommandParser, commandConverte
// delete (cmd as any).rawCommand

if (converter) {
if (converter.processDeserialized) {
converter.processDeserialized(cmd.properties)
}

for (const key in cmd) {
const newName = converter.idAliases[key]
if (cmd.hasOwnProperty(key) && newName) {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/__tests__/v8.0.1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('Commands v8.0.1', () => {
switch (testCase.name) {
// Not parsed
// case '_MvC':
// return
// continue
}

runTestForCommand(commandParser, commandConverters, i, testCase)
Expand Down
10 changes: 6 additions & 4 deletions src/commands/__tests__/v8.0.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const commandConverters: CommandTestConverterSet = {
'index': 'index'
},
propertyAliases: {
'balance': (v: number) => ({ val: Math.round(v * 10) / 10 }),
'balance': (v: number) => ({ val: Math.round(v) }),
'gain': (v: number) => ({ val: Math.round(v * 100) / 100 })
}
},
Expand All @@ -30,7 +30,8 @@ const commandConverters: CommandTestConverterSet = {
'hyperDecks': (val: any) => ({ val, name: 'maxHyperdecks' }),
'mixEffectBlocks': (val: any) => ({ val, name: 'MEs' }),
'serialPort': (val: any) => ({ val, name: 'serialPorts' }),
'videoSources': (val: any) => ({ val, name: 'sources' })
'videoSources': (val: any) => ({ val, name: 'sources' }),
'superSource': (val: any) => ({ val, name: 'superSources' })
}
},
'SSrc': {
Expand Down Expand Up @@ -129,8 +130,9 @@ describe('Commands v8.0', () => {

switch (testCase.name) {
// Not parsed
case '_MvC':
return
case '_MvC': // Not parsed
case 'AMIP': // portType max value
continue
}

runTestForCommand(commandParser, commandConverters, i, testCase)
Expand Down
4 changes: 2 additions & 2 deletions src/lib/atemUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ export namespace Util {
}

export function DecibelToUInt16BE (input: number) {
return parseInt(Math.pow(10, input / 20) * 32768 + '', 10)
return Math.floor(Math.pow(10, input / 20) * 32768)
}

export function IntToBalance (input: number): number {
// -100000 = -50, 0x0000 = 0, 0x2710 = +50
return Math.round((input / 200) * 10) / 10
return Math.round(input / 200)
}
export function BalanceToInt (input: number): number {
return Math.round(input * 200)
Expand Down
1 change: 0 additions & 1 deletion src/state/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export interface AtemCapabilites {
readonly maxHyperdecks: number
readonly DVEs: number
readonly stingers: number
readonly hasSuperSources: boolean
readonly superSources: number
readonly talkbackOverSDI: number
}
Expand Down
2 changes: 1 addition & 1 deletion src/state/video/upstreamKeyers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export interface UpstreamKeyerDVESettings extends UpstreamKeyerDVEBase {
rate: number
}

export interface UpstreamKeyerFlyKeyframe extends UpstreamKeyerDVEBase {
export interface UpstreamKeyerFlyKeyframe extends Omit<UpstreamKeyerDVEBase, 'maskEnabled'> {
readonly keyFrameId: number
}

Expand Down

0 comments on commit 0086eee

Please sign in to comment.