From 39349411fb1db9993a03d15ea4598cf36a647ff0 Mon Sep 17 00:00:00 2001 From: Julian Waller Date: Thu, 1 Feb 2024 12:59:17 +0000 Subject: [PATCH] fix: mixer tween parameters #199 --- src/__tests__/serializers.spec.ts | 46 ++++++++++++++++++++++++++++++- src/serializers.ts | 3 +- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/__tests__/serializers.spec.ts b/src/__tests__/serializers.spec.ts index 96ac6c71..15d576c6 100644 --- a/src/__tests__/serializers.spec.ts +++ b/src/__tests__/serializers.spec.ts @@ -6,10 +6,11 @@ import { InfoCommand, InfoLayerCommand, LoadbgDecklinkCommand, + MixerFillCommand, PlayCommand, PlayHtmlCommand, } from '../commands' -import { TransitionType } from '../enums' +import { TransitionTween, TransitionType } from '../enums' describe('serializers', () => { it('should have serializers for every command', () => { @@ -207,4 +208,47 @@ describe('serializers', () => { expect(result).toBe(`INFO 1-10`) }) + + it('should serialize a MIXER FILL with tweening properties', () => { + const command: MixerFillCommand = { + command: Commands.MixerFill, + params: { + channel: 1, + layer: 10, + x: 0.1, + y: 0.2, + xScale: 0.7, + yScale: 0.8, + + duration: 20, + tween: TransitionTween.IN_CIRC, + }, + } + const serialized = serializers[Commands.MixerFill].map((fn) => fn(command.command, command.params)) + expect(serialized).toHaveLength(serializers[Commands.MixerFill].length) + const result = serialized.filter((l) => l !== '').join(' ') + + expect(result).toBe(`MIXER 1-10 FILL 0.1 0.2 0.7 0.8 20 EASEINCIRC`) + }) + + it('should serialize a MIXER FILL with duration', () => { + const command: MixerFillCommand = { + command: Commands.MixerFill, + params: { + channel: 1, + layer: 10, + x: 0.1, + y: 0.2, + xScale: 0.7, + yScale: 0.8, + + duration: 20, + }, + } + const serialized = serializers[Commands.MixerFill].map((fn) => fn(command.command, command.params)) + expect(serialized).toHaveLength(serializers[Commands.MixerFill].length) + const result = serialized.filter((l) => l !== '').join(' ') + + expect(result).toBe(`MIXER 1-10 FILL 0.1 0.2 0.7 0.8 20`) + }) }) diff --git a/src/serializers.ts b/src/serializers.ts index 8f062561..ce842d92 100755 --- a/src/serializers.ts +++ b/src/serializers.ts @@ -109,7 +109,8 @@ const cgDataSerializer = (_: Commands, { data }: CgUpdateParameters | CgAddParam } } -const mixerTweenSerializer = (_: Commands, { tween, duration }: MixerTween) => (tween ? tween + ' ' + duration : '') +const mixerTweenSerializer = (_: Commands, { tween, duration }: MixerTween) => + (duration || '') + (tween ? ' ' + tween : '') const mixerSimpleValueSerializer = (_: Commands, { value }: { value: number | boolean | string }) => value !== undefined ? (typeof value === 'boolean' ? (value ? '1' : '0') : value + '') : ''