@@ -46,29 +46,34 @@ const PROBE: HeardProbe = {
4646} ;
4747
4848/** Every clip the render mixes, read as the render reads them (scenes inlined, on the film's clock), each ended where
49- * its media runs out if that comes first; a ramped rate or a loop keeps its end. */
49+ * its media runs out if that comes first, and left out if it starts past that ; a ramped rate or a loop keeps its end. */
5050export async function heardClips (
5151 projectDir : string ,
5252 probe : HeardProbe = PROBE ,
5353) : Promise < HeardClip [ ] > {
54- const { bundleToSingleHtml } = await import ( "@hyperframes/core/compiler" ) ;
55- const { audios } = ( await loadProducer ( ) ) . collectRenderMedia (
56- await bundleToSingleHtml ( projectDir ) ,
57- ) ;
58- return Promise . all ( audios . map ( ( clip ) => endedClip ( clip , projectDir , probe ) ) ) ;
54+ const { audios } = await collectProjectMedia ( projectDir ) ;
55+ const lengths = new Map < string , Promise < number | null > > ( ) ;
56+ const length = ( src : string ) : Promise < number | null > => {
57+ const path = mediaPath ( src , projectDir ) ;
58+ const known = lengths . get ( path ) ?? probe . seconds ( path ) . catch ( ( ) => null ) ;
59+ lengths . set ( path , known ) ;
60+ return known ;
61+ } ;
62+ const clips = await Promise . all ( audios . map ( ( clip ) => endedClip ( clip , length ) ) ) ;
63+ return clips . filter ( ( clip ) => clip !== null ) ;
5964}
6065
6166async function endedClip (
6267 clip : AudioElement ,
63- projectDir : string ,
64- probe : HeardProbe ,
65- ) : Promise < HeardClip > {
68+ length : ( src : string ) => Promise < number | null > ,
69+ ) : Promise < HeardClip | null > {
6670 const { id, src, start, mediaStart, playbackRate, volume, type } = clip ;
6771 const heard = { id, src, start, end : clip . end , mediaStart, playbackRate, volume, type } ;
6872 const rate = playbackRate === undefined ? 1 : playbackRate ;
6973 if ( clip . loop || typeof rate !== "number" || ! ( rate > 0 ) ) return heard ;
70- const seconds = await probe . seconds ( mediaPath ( src , projectDir ) ) . catch ( ( ) => null ) ;
71- if ( seconds === null || seconds <= mediaStart ) return heard ;
74+ const seconds = await length ( src ) ;
75+ if ( seconds === null ) return heard ;
76+ if ( seconds <= mediaStart ) return null ;
7277 const runsOut = start + ( seconds - mediaStart ) / rate ;
7378 return { ...heard , end : clip . end > 0 ? Math . min ( clip . end , runsOut ) : runsOut } ;
7479}
0 commit comments