@@ -67,6 +67,26 @@ export interface PieceInstanceWithTimings extends ReadonlyDeep<PieceInstance> {
6767 priority : number
6868}
6969
70+ export interface PartCurrentTimes {
71+ /** The current time when this was sampled */
72+ readonly currentTime : number
73+ /** The time the part started playback, if it has begun */
74+ readonly partStartTime : number | null
75+ /** An approximate current time within the part */
76+ readonly nowInPart : number
77+ }
78+
79+ export function createPartCurrentTimes (
80+ currentTime : number ,
81+ partStartTime : number | undefined | null
82+ ) : PartCurrentTimes {
83+ return {
84+ currentTime,
85+ partStartTime : partStartTime ?? null ,
86+ nowInPart : typeof partStartTime === 'number' ? currentTime - partStartTime : 0 ,
87+ }
88+ }
89+
7090/**
7191 * Process the infinite pieces to determine the start time and a maximum end time for each.
7292 * Any pieces which have no chance of being shown (duplicate start times) are pruned
@@ -76,7 +96,7 @@ export interface PieceInstanceWithTimings extends ReadonlyDeep<PieceInstance> {
7696export function processAndPrunePieceInstanceTimings (
7797 sourceLayers : SourceLayers ,
7898 pieces : ReadonlyDeep < PieceInstance [ ] > ,
79- nowInPart : number ,
99+ partTimes : PartCurrentTimes ,
80100 keepDisabledPieces ?: boolean ,
81101 includeVirtual ?: boolean
82102) : PieceInstanceWithTimings [ ] {
@@ -90,22 +110,28 @@ export function processAndPrunePieceInstanceTimings(
90110 }
91111 }
92112
93- const groupedPieces = groupByToMapFunc (
94- keepDisabledPieces ? pieces : pieces . filter ( ( p ) => ! p . disabled ) ,
113+ // If the part has a start times, we have concrete times for everything so we know how to interleave any absolute timed pieces.
114+
115+ // nocommit For now we can ignore absolute timed pieces,
116+ const relativePieces = pieces . filter ( ( p ) => ! p . piece . enable . isAbsolute )
117+
118+ const piecesGroupedByExclusiveGroupOrLayer = groupByToMapFunc (
119+ keepDisabledPieces ? relativePieces : relativePieces . filter ( ( p ) => ! p . disabled ) ,
95120 // At this stage, if a Piece is disabled, the `keepDisabledPieces` must be turned on. If that's the case
96121 // we split out the disabled Pieces onto the sourceLayerId they actually exist on, instead of putting them
97122 // onto the shared "exclusivityGroup" layer. This may cause it to not display "exactly" accurately
98123 // while in the disabled state, but it should keep it from affecting any not-disabled Pieces.
99124 ( p ) =>
100125 p . disabled ? p . piece . sourceLayerId : exclusiveGroupMap . get ( p . piece . sourceLayerId ) || p . piece . sourceLayerId
101126 )
102- for ( const pieces of groupedPieces . values ( ) ) {
127+ for ( const piecesInExclusiveGroupOrLayer of piecesGroupedByExclusiveGroupOrLayer . values ( ) ) {
103128 // Group and sort the pieces so that we can step through each point in time
129+ const piecesByStartMap = groupByToMapFunc ( piecesInExclusiveGroupOrLayer , ( p ) => getPieceStartTimeWithinPart ( p ) )
104130 const piecesByStart : Array < [ number | 'now' , ReadonlyDeep < PieceInstance [ ] > ] > = _ . sortBy (
105- Array . from ( groupByToMapFunc ( pieces , ( p ) => getPieceStartTimeWithinPart ( p ) ) . entries ( ) ) . map ( ( [ k , v ] ) =>
131+ Array . from ( piecesByStartMap . entries ( ) ) . map ( ( [ k , v ] ) =>
106132 literal < [ number | 'now' , ReadonlyDeep < PieceInstance [ ] > ] > ( [ k === 'now' ? 'now' : Number ( k ) , v ] )
107133 ) ,
108- ( [ k ] ) => ( k === 'now' ? nowInPart : k )
134+ ( [ k ] ) => ( k === 'now' ? partTimes . nowInPart : k )
109135 )
110136
111137 // Step through time
0 commit comments