@@ -13,65 +13,34 @@ import { assertNever, literal } from '@sofie-automation/corelib/dist/lib'
1313import { getPartGroupId , getPartFirstObjectId } from '@sofie-automation/corelib/dist/playout/ids'
1414import { PieceInstanceWithTimings } from '@sofie-automation/corelib/dist/playout/processAndPrune'
1515import { PieceTimelineMetadata } from './pieceGroup'
16- import { PartCalculatedTimings } from '@sofie-automation/corelib/dist/playout/timings'
1716import { JobContext } from '../../jobs'
1817import { ReadonlyDeep } from 'type-fest'
1918import { getPieceEnableInsidePart , transformPieceGroupAndObjects } from './piece'
2019import { PlayoutChangedType } from '@sofie-automation/shared-lib/dist/peripheralDevice/peripheralDeviceAPI'
20+ import { SelectedPartInstanceTimelineInfo } from './generate'
21+ import { PartCalculatedTimings } from '@sofie-automation/corelib/dist/playout/timings'
2122
2223export function transformPartIntoTimeline (
2324 context : JobContext ,
2425 playlistId : RundownPlaylistId ,
2526 pieceInstances : ReadonlyDeep < Array < PieceInstanceWithTimings > > ,
2627 pieceGroupFirstObjClasses : string [ ] ,
2728 parentGroup : TimelineObjGroupPart & OnGenerateTimelineObjExt ,
28- nowInParentGroup : number ,
29- partTimings : PartCalculatedTimings ,
30- isInHold : boolean ,
31- outTransition : IBlueprintPartOutTransition | null
29+ partInfo : SelectedPartInstanceTimelineInfo ,
30+ isInHold : boolean
3231) : Array < TimelineObjRundown & OnGenerateTimelineObjExt > {
3332 const span = context . startSpan ( 'transformPartIntoTimeline' )
33+
34+ const nowInParentGroup = partInfo . nowInPart
35+ const partTimings = partInfo . calculatedTimings
36+ const outTransition = partInfo . partInstance . part . outTransition ?? null
37+
3438 const timelineObjs : Array < TimelineObjRundown & OnGenerateTimelineObjExt > = [ ]
3539
3640 for ( const pieceInstance of pieceInstances ) {
3741 if ( pieceInstance . disabled ) continue
3842
39- let pieceEnable : TSR . Timeline . TimelineEnable | undefined
40- switch ( pieceInstance . piece . pieceType ) {
41- case IBlueprintPieceType . InTransition :
42- if ( typeof partTimings . inTransitionStart === 'number' ) {
43- // Respect the start time of the piece, in case there is a reason for it being non-zero
44- const startOffset =
45- typeof pieceInstance . piece . enable . start === 'number' ? pieceInstance . piece . enable . start : 0
46-
47- pieceEnable = {
48- start : partTimings . inTransitionStart + startOffset ,
49- duration : pieceInstance . piece . enable . duration ,
50- }
51- }
52- break
53- case IBlueprintPieceType . OutTransition :
54- if ( outTransition ) {
55- pieceEnable = {
56- start : `#${ parentGroup . id } .end - ${ outTransition . duration } ` ,
57- }
58- if ( partTimings . toPartPostroll ) {
59- pieceEnable . start += ' - ' + partTimings . toPartPostroll
60- }
61- }
62- break
63- case IBlueprintPieceType . Normal :
64- pieceEnable = getPieceEnableInsidePart (
65- pieceInstance ,
66- partTimings ,
67- parentGroup . id ,
68- parentGroup . enable . duration !== undefined || parentGroup . enable . end !== undefined
69- )
70- break
71- default :
72- assertNever ( pieceInstance . piece . pieceType )
73- break
74- }
43+ const pieceEnable = getPieceEnableForPieceInstance ( partTimings , outTransition , parentGroup , pieceInstance )
7544
7645 // Not able to enable this piece
7746 if ( ! pieceEnable ) continue
@@ -94,6 +63,49 @@ export function transformPartIntoTimeline(
9463 return timelineObjs
9564}
9665
66+ function getPieceEnableForPieceInstance (
67+ partTimings : PartCalculatedTimings ,
68+ outTransition : IBlueprintPartOutTransition | null ,
69+ parentGroup : TimelineObjGroupPart & OnGenerateTimelineObjExt ,
70+ pieceInstance : ReadonlyDeep < PieceInstanceWithTimings >
71+ ) : TSR . Timeline . TimelineEnable | undefined {
72+ switch ( pieceInstance . piece . pieceType ) {
73+ case IBlueprintPieceType . InTransition : {
74+ if ( typeof partTimings . inTransitionStart !== 'number' ) return undefined
75+ // Respect the start time of the piece, in case there is a reason for it being non-zero
76+ const startOffset =
77+ typeof pieceInstance . piece . enable . start === 'number' ? pieceInstance . piece . enable . start : 0
78+
79+ return {
80+ start : partTimings . inTransitionStart + startOffset ,
81+ duration : pieceInstance . piece . enable . duration ,
82+ }
83+ }
84+ case IBlueprintPieceType . OutTransition : {
85+ if ( ! outTransition ) return undefined
86+
87+ const pieceEnable : TSR . Timeline . TimelineEnable = {
88+ start : `#${ parentGroup . id } .end - ${ outTransition . duration } ` ,
89+ }
90+ if ( partTimings . toPartPostroll ) {
91+ pieceEnable . start += ' - ' + partTimings . toPartPostroll
92+ }
93+
94+ return pieceEnable
95+ }
96+ case IBlueprintPieceType . Normal :
97+ return getPieceEnableInsidePart (
98+ pieceInstance ,
99+ partTimings ,
100+ parentGroup . id ,
101+ parentGroup . enable . duration !== undefined || parentGroup . enable . end !== undefined
102+ )
103+ default :
104+ assertNever ( pieceInstance . piece . pieceType )
105+ return undefined
106+ }
107+ }
108+
97109export interface PartEnable {
98110 start : number | 'now' | string
99111 duration ?: number
0 commit comments