@@ -13,65 +13,34 @@ import { assertNever, literal } from '@sofie-automation/corelib/dist/lib'
13
13
import { getPartGroupId , getPartFirstObjectId } from '@sofie-automation/corelib/dist/playout/ids'
14
14
import { PieceInstanceWithTimings } from '@sofie-automation/corelib/dist/playout/processAndPrune'
15
15
import { PieceTimelineMetadata } from './pieceGroup'
16
- import { PartCalculatedTimings } from '@sofie-automation/corelib/dist/playout/timings'
17
16
import { JobContext } from '../../jobs'
18
17
import { ReadonlyDeep } from 'type-fest'
19
18
import { getPieceEnableInsidePart , transformPieceGroupAndObjects } from './piece'
20
19
import { PlayoutChangedType } from '@sofie-automation/shared-lib/dist/peripheralDevice/peripheralDeviceAPI'
20
+ import { SelectedPartInstanceTimelineInfo } from './generate'
21
+ import { PartCalculatedTimings } from '@sofie-automation/corelib/dist/playout/timings'
21
22
22
23
export function transformPartIntoTimeline (
23
24
context : JobContext ,
24
25
playlistId : RundownPlaylistId ,
25
26
pieceInstances : ReadonlyDeep < Array < PieceInstanceWithTimings > > ,
26
27
pieceGroupFirstObjClasses : string [ ] ,
27
28
parentGroup : TimelineObjGroupPart & OnGenerateTimelineObjExt ,
28
- nowInParentGroup : number ,
29
- partTimings : PartCalculatedTimings ,
30
- isInHold : boolean ,
31
- outTransition : IBlueprintPartOutTransition | null
29
+ partInfo : SelectedPartInstanceTimelineInfo ,
30
+ isInHold : boolean
32
31
) : Array < TimelineObjRundown & OnGenerateTimelineObjExt > {
33
32
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
+
34
38
const timelineObjs : Array < TimelineObjRundown & OnGenerateTimelineObjExt > = [ ]
35
39
36
40
for ( const pieceInstance of pieceInstances ) {
37
41
if ( pieceInstance . disabled ) continue
38
42
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 )
75
44
76
45
// Not able to enable this piece
77
46
if ( ! pieceEnable ) continue
@@ -94,6 +63,49 @@ export function transformPartIntoTimeline(
94
63
return timelineObjs
95
64
}
96
65
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
+
97
109
export interface PartEnable {
98
110
start : number | 'now' | string
99
111
duration ?: number
0 commit comments