@@ -174,20 +174,23 @@ export async function performTakeToNextedPart(
174
174
}
175
175
}
176
176
177
+ // If hold is COMPLETE, clear the hold state by this take
177
178
if ( playoutModel . playlist . holdState === RundownHoldState . COMPLETE ) {
178
179
playoutModel . setHoldState ( RundownHoldState . NONE )
179
180
180
- // If hold is active , then this take is to clear it
181
+ // If hold is ACTIVE , then this take is to complete it
181
182
} else if ( playoutModel . playlist . holdState === RundownHoldState . ACTIVE ) {
182
183
await completeHold ( context , playoutModel , await pShowStyle , currentPartInstance )
183
184
185
+ await updateTimeline ( context , playoutModel )
186
+
184
187
if ( span ) span . end ( )
185
188
186
189
return
187
190
}
188
191
189
192
const takePartInstance = nextPartInstance
190
- if ( ! takePartInstance ) throw new Error ( 'takePart not found!' )
193
+ if ( ! takePartInstance ) throw new Error ( 'takePartInstance not found!' )
191
194
const takeRundown = playoutModel . getRundown ( takePartInstance . partInstance . rundownId )
192
195
if ( ! takeRundown )
193
196
throw new Error ( `takeRundown: takeRundown not found! ("${ takePartInstance . partInstance . rundownId } ")` )
@@ -264,12 +267,10 @@ export async function performTakeToNextedPart(
264
267
// Once everything is synced, we can choose the next part
265
268
await setNextPart ( context , playoutModel , nextPart , false )
266
269
267
- // Setup the parts for the HOLD we are starting
268
- if (
269
- playoutModel . playlist . previousPartInfo &&
270
- ( playoutModel . playlist . holdState as RundownHoldState ) === RundownHoldState . ACTIVE
271
- ) {
272
- startHold ( context , currentPartInstance , nextPartInstance )
270
+ // If the Hold is PENDING, make it active
271
+ if ( playoutModel . playlist . holdState === RundownHoldState . PENDING ) {
272
+ // Setup the parts for the HOLD we are starting
273
+ activateHold ( context , playoutModel , currentPartInstance , takePartInstance )
273
274
}
274
275
await afterTake ( context , playoutModel , takePartInstance )
275
276
@@ -555,35 +556,39 @@ export async function afterTake(
555
556
/**
556
557
* A Hold starts by extending the "extendOnHold"-able pieces in the previous Part.
557
558
*/
558
- function startHold (
559
+ function activateHold (
559
560
context : JobContext ,
561
+ playoutModel : PlayoutModel ,
560
562
holdFromPartInstance : PlayoutPartInstanceModel | null ,
561
563
holdToPartInstance : PlayoutPartInstanceModel | undefined
562
564
) {
563
565
if ( ! holdFromPartInstance ) throw new Error ( 'previousPart not found!' )
564
566
if ( ! holdToPartInstance ) throw new Error ( 'currentPart not found!' )
565
- const span = context . startSpan ( 'startHold' )
567
+ const span = context . startSpan ( 'activateHold' )
568
+
569
+ playoutModel . setHoldState ( RundownHoldState . ACTIVE )
566
570
567
571
// Make a copy of any item which is flagged as an 'infinite' extension
568
572
const pieceInstancesToCopy = holdFromPartInstance . pieceInstances . filter ( ( p ) => ! ! p . pieceInstance . piece . extendOnHold )
569
- pieceInstancesToCopy . forEach ( ( instance ) => {
570
- if ( ! instance . pieceInstance . infinite ) {
571
- // mark current one as infinite
572
- instance . prepareForHold ( )
573
-
574
- // This gets deleted once the nextpart is activated, so it doesnt linger for long
575
- const extendedPieceInstance = holdToPartInstance . insertHoldPieceInstance ( instance )
576
-
577
- const content = clone ( instance . pieceInstance . piece . content ) as VTContent | undefined
578
- if ( content ?. fileName && content . sourceDuration && instance . pieceInstance . plannedStartedPlayback ) {
579
- content . seek = Math . min (
580
- content . sourceDuration ,
581
- getCurrentTime ( ) - instance . pieceInstance . plannedStartedPlayback
582
- )
583
- }
584
- extendedPieceInstance . updatePieceProps ( { content } )
573
+ for ( const instance of pieceInstancesToCopy ) {
574
+ // skip any infinites
575
+ if ( instance . pieceInstance . infinite ) continue
576
+
577
+ instance . prepareForHold ( )
578
+
579
+ // This gets deleted once the nextpart is activated, so it doesnt linger for long
580
+ const extendedPieceInstance = holdToPartInstance . insertHoldPieceInstance ( instance )
581
+
582
+ const content = clone ( instance . pieceInstance . piece . content ) as VTContent | undefined
583
+ if ( content ?. fileName && content . sourceDuration && instance . pieceInstance . plannedStartedPlayback ) {
584
+ content . seek = Math . min (
585
+ content . sourceDuration ,
586
+ getCurrentTime ( ) - instance . pieceInstance . plannedStartedPlayback
587
+ )
585
588
}
586
- } )
589
+ extendedPieceInstance . updatePieceProps ( { content } )
590
+ }
591
+
587
592
if ( span ) span . end ( )
588
593
}
589
594
@@ -595,19 +600,16 @@ async function completeHold(
595
600
) : Promise < void > {
596
601
playoutModel . setHoldState ( RundownHoldState . COMPLETE )
597
602
598
- if ( playoutModel . playlist . currentPartInfo ) {
599
- if ( ! currentPartInstance ) throw new Error ( 'currentPart not found!' )
600
-
601
- // Clear the current extension line
602
- innerStopPieces (
603
- context ,
604
- playoutModel ,
605
- showStyleCompound . sourceLayers ,
606
- currentPartInstance ,
607
- ( p ) => ! ! p . infinite ?. fromHold ,
608
- undefined
609
- )
610
- }
603
+ if ( ! playoutModel . playlist . currentPartInfo ) return
604
+ if ( ! currentPartInstance ) throw new Error ( 'currentPart not found!' )
611
605
612
- await updateTimeline ( context , playoutModel )
606
+ // Clear the current extension line
607
+ innerStopPieces (
608
+ context ,
609
+ playoutModel ,
610
+ showStyleCompound . sourceLayers ,
611
+ currentPartInstance ,
612
+ ( p ) => ! ! p . infinite ?. fromHold ,
613
+ undefined
614
+ )
613
615
}
0 commit comments