Skip to content

Commit

Permalink
fix: restructure transitionPosition properties in the state
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Jul 31, 2020
1 parent d9d9a3f commit 2aa7d14
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 25 deletions.
16 changes: 16 additions & 0 deletions src/__tests__/tally.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ function loadRawState(file: string): AtemState {
videoState.mixEffects = videoState.ME
}

loadedState.video.mixEffects.forEach(me => {
// Lazy fix up moving some state properties
if (me) {
const me1 = me as any
if (typeof me.transitionPosition === 'number') {
me.transitionPosition = {
inTransition: me1.inTransition,
handlePosition: me1.transitionPosition,
remainingFrames: me1.transitionFramesLeft
}
delete me1.transitionFramesLeft
delete me1.inTransition
}
}
})

return loadedState
}
function loadTally(file: string): { program: number[]; preview: number[] } {
Expand Down
22 changes: 6 additions & 16 deletions src/commands/MixEffects/Transition/TransitionPositionCommand.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { BasicWritableCommand, DeserializedCommand } from '../../CommandBase'
import { AtemState, AtemStateUtil, InvalidIdError } from '../../../state'
import { TransitionPosition } from '../../../state/video'

export interface HandlePositionProps {
handlePosition: number // 0...10000
}

export class TransitionPositionCommand extends BasicWritableCommand<HandlePositionProps> {
export class TransitionPositionCommand extends BasicWritableCommand<Pick<TransitionPosition, 'handlePosition'>> {
public static readonly rawName = 'CTPs'

public readonly mixEffect: number
Expand All @@ -24,17 +21,12 @@ export class TransitionPositionCommand extends BasicWritableCommand<HandlePositi
}
}

export interface TransitionPositionProps extends HandlePositionProps {
inTransition: boolean
remainingFrames: number // 0...250
}

export class TransitionPositionUpdateCommand extends DeserializedCommand<TransitionPositionProps> {
export class TransitionPositionUpdateCommand extends DeserializedCommand<TransitionPosition> {
public static readonly rawName = 'TrPs'

public readonly mixEffect: number

constructor(mixEffect: number, properties: TransitionPositionProps) {
constructor(mixEffect: number, properties: TransitionPosition) {
super(properties)

this.mixEffect = mixEffect
Expand All @@ -57,9 +49,7 @@ export class TransitionPositionUpdateCommand extends DeserializedCommand<Transit
}

const mixEffect = AtemStateUtil.getMixEffect(state, this.mixEffect)
mixEffect.transitionFramesLeft = this.properties.remainingFrames
mixEffect.transitionPosition = this.properties.handlePosition
mixEffect.inTransition = this.properties.inTransition
return `video.ME.${this.mixEffect}.transition`
mixEffect.transitionPosition = this.properties
return `video.ME.${this.mixEffect}.transitionPosition`
}
}
7 changes: 4 additions & 3 deletions src/lib/tally.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function _calcActiveMeInputs(inputs: Set<number>, mode: 'program' | 'preview', s
const keyerMask = 1 << (usk.upstreamKeyerId + 1)
const isPartOfTransition = meRef.transitionProperties.selection & keyerMask
if (mode === 'program') {
if (meRef.inTransition) {
if (meRef.transitionPosition.inTransition) {
return usk.onAir || isPartOfTransition
}

Expand Down Expand Up @@ -77,8 +77,9 @@ function _calcActiveMeInputs(inputs: Set<number>, mode: 'program' | 'preview', s
}

// Compute what sources are currently participating in a transition.
const isTransitionInProgram = mode === 'program' && meRef.inTransition
const isTransitionInPreview = mode === 'preview' && meRef.transitionPreview && meRef.transitionPosition > 0
const isTransitionInProgram = mode === 'program' && meRef.transitionPosition.inTransition
const isTransitionInPreview =
mode === 'preview' && meRef.transitionPreview && meRef.transitionPosition.handlePosition > 0
if (isTransitionInProgram || isTransitionInPreview) {
if (meRef.transitionProperties.selection & 1) {
// Includes background
Expand Down
8 changes: 5 additions & 3 deletions src/state/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,12 @@ export function getMixEffect(state: AtemState, index: number, dontCreate?: boole
index,
programInput: 0,
previewInput: 0,
inTransition: false,
transitionPreview: false,
transitionPosition: 0,
transitionFramesLeft: 0,
transitionPosition: {
inTransition: false,
handlePosition: 0,
remainingFrames: 0
},
transitionProperties: {
style: Enums.TransitionStyle.MIX,
selection: 1,
Expand Down
10 changes: 7 additions & 3 deletions src/state/video/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,19 @@ export interface TransitionSettings {
wipe?: WipeTransitionSettings
}

export interface TransitionPosition {
inTransition: boolean
handlePosition: number
remainingFrames: number
}

export interface MixEffect {
readonly index: number
programInput: number
previewInput: number
inTransition: boolean
transitionPreview: boolean
transitionPosition: number
transitionFramesLeft: number
fadeToBlack?: FadeToBlackProperties
transitionPosition: TransitionPosition
transitionProperties: TransitionProperties
transitionSettings: TransitionSettings
readonly upstreamKeyers: Array<USK.UpstreamKeyer | undefined>
Expand Down

0 comments on commit 2aa7d14

Please sign in to comment.