@@ -174,20 +174,23 @@ export async function performTakeToNextedPart(
174174 }
175175 }
176176
177+ // If hold is COMPLETE, clear the hold state by this take
177178 if ( playoutModel . playlist . holdState === RundownHoldState . COMPLETE ) {
178179 playoutModel . setHoldState ( RundownHoldState . NONE )
179180
180- // If hold is active , then this take is to clear it
181+ // If hold is ACTIVE , then this take is to complete it
181182 } else if ( playoutModel . playlist . holdState === RundownHoldState . ACTIVE ) {
182183 await completeHold ( context , playoutModel , await pShowStyle , currentPartInstance )
183184
185+ await updateTimeline ( context , playoutModel )
186+
184187 if ( span ) span . end ( )
185188
186189 return
187190 }
188191
189192 const takePartInstance = nextPartInstance
190- if ( ! takePartInstance ) throw new Error ( 'takePart not found!' )
193+ if ( ! takePartInstance ) throw new Error ( 'takePartInstance not found!' )
191194 const takeRundown = playoutModel . getRundown ( takePartInstance . partInstance . rundownId )
192195 if ( ! takeRundown )
193196 throw new Error ( `takeRundown: takeRundown not found! ("${ takePartInstance . partInstance . rundownId } ")` )
@@ -264,12 +267,10 @@ export async function performTakeToNextedPart(
264267 // Once everything is synced, we can choose the next part
265268 await setNextPart ( context , playoutModel , nextPart , false )
266269
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 )
273274 }
274275 await afterTake ( context , playoutModel , takePartInstance )
275276
@@ -555,35 +556,39 @@ export async function afterTake(
555556/**
556557 * A Hold starts by extending the "extendOnHold"-able pieces in the previous Part.
557558 */
558- function startHold (
559+ function activateHold (
559560 context : JobContext ,
561+ playoutModel : PlayoutModel ,
560562 holdFromPartInstance : PlayoutPartInstanceModel | null ,
561563 holdToPartInstance : PlayoutPartInstanceModel | undefined
562564) {
563565 if ( ! holdFromPartInstance ) throw new Error ( 'previousPart not found!' )
564566 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 )
566570
567571 // Make a copy of any item which is flagged as an 'infinite' extension
568572 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+ )
585588 }
586- } )
589+ extendedPieceInstance . updatePieceProps ( { content } )
590+ }
591+
587592 if ( span ) span . end ( )
588593}
589594
@@ -595,19 +600,16 @@ async function completeHold(
595600) : Promise < void > {
596601 playoutModel . setHoldState ( RundownHoldState . COMPLETE )
597602
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!' )
611605
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+ )
613615}
0 commit comments