@@ -178,20 +178,23 @@ export async function performTakeToNextedPart(
178178 }
179179 }
180180
181+ // If hold is COMPLETE, clear the hold state by this take
181182 if ( playoutModel . playlist . holdState === RundownHoldState . COMPLETE ) {
182183 playoutModel . setHoldState ( RundownHoldState . NONE )
183184
184- // If hold is active , then this take is to clear it
185+ // If hold is ACTIVE , then this take is to complete it
185186 } else if ( playoutModel . playlist . holdState === RundownHoldState . ACTIVE ) {
186187 await completeHold ( context , playoutModel , await pShowStyle , currentPartInstance )
187188
189+ await updateTimeline ( context , playoutModel )
190+
188191 if ( span ) span . end ( )
189192
190193 return
191194 }
192195
193196 const takePartInstance = nextPartInstance
194- if ( ! takePartInstance ) throw new Error ( 'takePart not found!' )
197+ if ( ! takePartInstance ) throw new Error ( 'takePartInstance not found!' )
195198 const takeRundown = playoutModel . getRundown ( takePartInstance . partInstance . rundownId )
196199 if ( ! takeRundown )
197200 throw new Error ( `takeRundown: takeRundown not found! ("${ takePartInstance . partInstance . rundownId } ")` )
@@ -263,12 +266,10 @@ export async function performTakeToNextedPart(
263266 // Once everything is synced, we can choose the next part
264267 await setNextPart ( context , playoutModel , nextPart , false )
265268
266- // Setup the parts for the HOLD we are starting
267- if (
268- playoutModel . playlist . previousPartInfo &&
269- ( playoutModel . playlist . holdState as RundownHoldState ) === RundownHoldState . ACTIVE
270- ) {
271- startHold ( context , currentPartInstance , nextPartInstance )
269+ // If the Hold is PENDING, make it active
270+ if ( playoutModel . playlist . holdState === RundownHoldState . PENDING ) {
271+ // Setup the parts for the HOLD we are starting
272+ activateHold ( context , playoutModel , currentPartInstance , takePartInstance )
272273 }
273274 await afterTake ( context , playoutModel , takePartInstance )
274275
@@ -535,35 +536,39 @@ export async function afterTake(
535536/**
536537 * A Hold starts by extending the "extendOnHold"-able pieces in the previous Part.
537538 */
538- function startHold (
539+ function activateHold (
539540 context : JobContext ,
541+ playoutModel : PlayoutModel ,
540542 holdFromPartInstance : PlayoutPartInstanceModel | null ,
541543 holdToPartInstance : PlayoutPartInstanceModel | undefined
542544) {
543545 if ( ! holdFromPartInstance ) throw new Error ( 'previousPart not found!' )
544546 if ( ! holdToPartInstance ) throw new Error ( 'currentPart not found!' )
545- const span = context . startSpan ( 'startHold' )
547+ const span = context . startSpan ( 'activateHold' )
548+
549+ playoutModel . setHoldState ( RundownHoldState . ACTIVE )
546550
547551 // Make a copy of any item which is flagged as an 'infinite' extension
548552 const pieceInstancesToCopy = holdFromPartInstance . pieceInstances . filter ( ( p ) => ! ! p . pieceInstance . piece . extendOnHold )
549- pieceInstancesToCopy . forEach ( ( instance ) => {
550- if ( ! instance . pieceInstance . infinite ) {
551- // mark current one as infinite
552- instance . prepareForHold ( )
553-
554- // This gets deleted once the nextpart is activated, so it doesnt linger for long
555- const extendedPieceInstance = holdToPartInstance . insertHoldPieceInstance ( instance )
556-
557- const content = clone ( instance . pieceInstance . piece . content ) as VTContent | undefined
558- if ( content ?. fileName && content . sourceDuration && instance . pieceInstance . plannedStartedPlayback ) {
559- content . seek = Math . min (
560- content . sourceDuration ,
561- getCurrentTime ( ) - instance . pieceInstance . plannedStartedPlayback
562- )
563- }
564- extendedPieceInstance . updatePieceProps ( { content } )
553+ for ( const instance of pieceInstancesToCopy ) {
554+ // skip any infinites
555+ if ( instance . pieceInstance . infinite ) continue
556+
557+ instance . prepareForHold ( )
558+
559+ // This gets deleted once the nextpart is activated, so it doesnt linger for long
560+ const extendedPieceInstance = holdToPartInstance . insertHoldPieceInstance ( instance )
561+
562+ const content = clone ( instance . pieceInstance . piece . content ) as VTContent | undefined
563+ if ( content ?. fileName && content . sourceDuration && instance . pieceInstance . plannedStartedPlayback ) {
564+ content . seek = Math . min (
565+ content . sourceDuration ,
566+ getCurrentTime ( ) - instance . pieceInstance . plannedStartedPlayback
567+ )
565568 }
566- } )
569+ extendedPieceInstance . updatePieceProps ( { content } )
570+ }
571+
567572 if ( span ) span . end ( )
568573}
569574
@@ -575,19 +580,16 @@ async function completeHold(
575580) : Promise < void > {
576581 playoutModel . setHoldState ( RundownHoldState . COMPLETE )
577582
578- if ( playoutModel . playlist . currentPartInfo ) {
579- if ( ! currentPartInstance ) throw new Error ( 'currentPart not found!' )
583+ if ( ! playoutModel . playlist . currentPartInfo ) return
584+ if ( ! currentPartInstance ) throw new Error ( 'currentPart not found!' )
580585
581- // Clear the current extension line
582- innerStopPieces (
583- context ,
584- playoutModel ,
585- showStyleCompound . sourceLayers ,
586- currentPartInstance ,
587- ( p ) => ! ! p . infinite ?. fromHold ,
588- undefined
589- )
590- }
591-
592- await updateTimeline ( context , playoutModel )
586+ // Clear the current extension line
587+ innerStopPieces (
588+ context ,
589+ playoutModel ,
590+ showStyleCompound . sourceLayers ,
591+ currentPartInstance ,
592+ ( p ) => ! ! p . infinite ?. fromHold ,
593+ undefined
594+ )
593595}
0 commit comments