@@ -56,9 +56,9 @@ export class Composition extends EventEmitterMixin<CompositionEvents, typeof Ser
5656
5757 /**
5858 * User defined fixed duration, use the duration
59- * property to change this value
59+ * property to set this value
6060 */
61- public durationLimit ?: Timestamp ;
61+ public fixedDuration ?: Timestamp ;
6262
6363 /**
6464 * Defines the current state of the composition
@@ -92,13 +92,12 @@ export class Composition extends EventEmitterMixin<CompositionEvents, typeof Ser
9292
9393 this . settings = { height, width, background, backend } ;
9494
95- this . on ( 'update' , this . computeFrame . bind ( this ) ) ;
96- this . on ( 'attach' , this . computeFrame . bind ( this ) ) ;
97- this . on ( 'detach' , this . computeFrame . bind ( this ) ) ;
98- this . on ( 'load' , this . computeFrame . bind ( this ) ) ;
99- this . on ( 'frame' , this . computeFrame . bind ( this ) ) ;
100- this . on ( 'error' , this . computeFrame . bind ( this ) ) ;
101- this . on ( '*' , this . updateDuration . bind ( this ) ) ;
95+ this . on ( 'update' , this . update . bind ( this ) ) ;
96+ this . on ( 'attach' , this . update . bind ( this ) ) ;
97+ this . on ( 'detach' , this . update . bind ( this ) ) ;
98+ this . on ( 'load' , this . update . bind ( this ) ) ;
99+ this . on ( 'frame' , this . update . bind ( this ) ) ;
100+ this . on ( 'error' , this . update . bind ( this ) ) ;
102101
103102 autoDetectRenderer ( { ...this . settings , preference : backend } )
104103 . then ( renderer => {
@@ -147,8 +146,8 @@ export class Composition extends EventEmitterMixin<CompositionEvents, typeof Ser
147146 * This is where the playback stops playing
148147 */
149148 public get duration ( ) : Timestamp {
150- if ( this . durationLimit ) {
151- return this . durationLimit ;
149+ if ( this . fixedDuration ) {
150+ return this . fixedDuration ;
152151 }
153152 return this . _duration ;
154153 }
@@ -158,14 +157,14 @@ export class Composition extends EventEmitterMixin<CompositionEvents, typeof Ser
158157 */
159158 public set duration ( time : frame | Timestamp | undefined ) {
160159 if ( ! time ) {
161- this . durationLimit = undefined ;
160+ this . fixedDuration = undefined ;
162161 } else if ( time instanceof Timestamp ) {
163- this . durationLimit = time ;
162+ this . fixedDuration = time ;
164163 } else {
165- this . durationLimit = Timestamp . fromFrames ( time ) ;
164+ this . fixedDuration = Timestamp . fromFrames ( time ) ;
166165 }
167166
168- this . trigger ( 'frame' , this . durationLimit ?. frames ?? 0 ) ;
167+ this . trigger ( 'frame' , this . fixedDuration ?. frames ?? 0 ) ;
169168 }
170169
171170 /**
@@ -256,10 +255,6 @@ export class Composition extends EventEmitterMixin<CompositionEvents, typeof Ser
256255 const removed = this . tracks . filter ( ( track ) => track instanceof Track ) ;
257256 this . tracks = this . tracks . filter ( ( track ) => ! ( track instanceof Track ) ) ;
258257
259- if ( removed . length > 0 ) {
260- this . updateDuration ( ) ;
261- }
262-
263258 return removed ;
264259 }
265260
@@ -508,15 +503,17 @@ export class Composition extends EventEmitterMixin<CompositionEvents, typeof Ser
508503 }
509504 }
510505
511- private updateDuration ( ) : void {
512- const lastFrames = this . tracks
513- . filter ( ( track ) => ! track . disabled )
514- . map ( ( track ) => track . stop ?. frames ?? 0 ) ;
515-
516- const lastFrame = Math . max ( ...lastFrames , 0 ) ;
506+ /**
507+ * Updates the state of the composition
508+ */
509+ private update ( ) : void {
510+ this . _duration . frames = Math . max (
511+ ...this . tracks
512+ . filter ( ( track ) => ! track . disabled )
513+ . map ( ( track ) => track . stop ?. frames ?? 0 ) ,
514+ 0
515+ ) ;
517516
518- if ( lastFrame != this . _duration . frames ) {
519- this . _duration . frames = lastFrame ;
520- }
517+ this . computeFrame ( ) ;
521518 }
522519}
0 commit comments