@@ -10,10 +10,18 @@ import { getPieceControlObjectId } from './ids'
1010/**
1111 * Get the `enable: { start: ?? }` for the new piece in terms that can be used as an `end` for another object
1212 */
13- function getPieceStartTime ( newPieceStart : number | 'now' , newPiece : PieceInstance ) : number | string {
13+ function getPieceStartTimeAsReference ( newPieceStart : number | 'now' , newPiece : PieceInstance ) : number | string {
1414 return typeof newPieceStart === 'number' ? newPieceStart : `#${ getPieceControlObjectId ( newPiece ) } .start`
1515}
1616
17+ function getPieceStartTimeWithinPart ( p : PieceInstance ) : 'now' | number {
18+ if ( p . piece . enable . start === 'now' || ! p . dynamicallyInserted ) {
19+ return p . piece . enable . start
20+ } else {
21+ return p . piece . enable . start + ( p . piece . prerollDuration ?? 0 )
22+ }
23+ }
24+
1725function isClear ( piece ?: PieceInstance ) : boolean {
1826 return ! ! piece ?. piece . virtual
1927}
@@ -85,7 +93,7 @@ export function processAndPrunePieceInstanceTimings(
8593 for ( const pieces of groupedPieces . values ( ) ) {
8694 // Group and sort the pieces so that we can step through each point in time
8795 const piecesByStart : Array < [ number | 'now' , PieceInstance [ ] ] > = _ . sortBy (
88- Array . from ( groupByToMapFunc ( pieces , ( p ) => p . piece . enable . start ) . entries ( ) ) . map ( ( [ k , v ] ) =>
96+ Array . from ( groupByToMapFunc ( pieces , ( p ) => getPieceStartTimeWithinPart ( p ) ) . entries ( ) ) . map ( ( [ k , v ] ) =>
8997 literal < [ number | 'now' , PieceInstance [ ] ] > ( [ k === 'now' ? 'now' : Number ( k ) , v ] )
9098 ) ,
9199 ( [ k ] ) => ( k === 'now' ? nowInPart : k )
@@ -120,7 +128,7 @@ function updateWithNewPieces(
120128 if ( newPiece ) {
121129 const activePiece = activePieces [ key ]
122130 if ( activePiece ) {
123- activePiece . resolvedEndCap = getPieceStartTime ( newPiecesStart , newPiece )
131+ activePiece . resolvedEndCap = getPieceStartTimeAsReference ( newPiecesStart , newPiece )
124132 }
125133 // track the new piece
126134 activePieces [ key ] = newPiece
@@ -145,7 +153,7 @@ function updateWithNewPieces(
145153 ( newPiecesStart !== 0 || isCandidateBetterToBeContinued ( activePieces . other , newPiece ) )
146154 ) {
147155 // These modes should stop the 'other' when they start if not hidden behind a higher priority onEnd
148- activePieces . other . resolvedEndCap = getPieceStartTime ( newPiecesStart , newPiece )
156+ activePieces . other . resolvedEndCap = getPieceStartTimeAsReference ( newPiecesStart , newPiece )
149157 activePieces . other = undefined
150158 }
151159 }
0 commit comments