changeset 185:f957e93dc979

Keep track of the components layers and only remove those from the timeline when cleaning up.
author Lucas Thompson <dev@lucas.im>
date Wed, 22 Mar 2017 14:23:45 +0000
parents 7643e60dc1dd
children 17be44abc2d9
files src/app/waveform/waveform.component.ts
diffstat 1 files changed, 11 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/app/waveform/waveform.component.ts	Wed Mar 22 11:22:48 2017 +0000
+++ b/src/app/waveform/waveform.component.ts	Wed Mar 22 14:23:45 2017 +0000
@@ -35,6 +35,7 @@
   private _audioBuffer: AudioBuffer;
   private timeline: Timeline;
   private cursorLayer: any;
+  private layers: Layer[];
 
   @Input()
   set audioBuffer(buffer: AudioBuffer) {
@@ -62,6 +63,7 @@
   constructor(private audioService: AudioPlayerService,
               private piperService: FeatureExtractionService,
               public ngZone: NgZone) {
+    this.layers = [];
     this._audioBuffer = undefined;
     this.timeline = undefined;
     this.cursorLayer = undefined;
@@ -255,13 +257,15 @@
       const trackLayers = Array.from(track.layers);
       while (trackLayers.length) {
         let layer: Layer = trackLayers.pop();
-        track.remove(layer);
-
-        const index = timeContextChildren.indexOf(layer.timeContext);
-        if (index >= 0) {
-          timeContextChildren.splice(index, 1);
+        if (this.layers.includes(layer)) {
+          track.remove(layer);
+          this.layers.splice(this.layers.indexOf(layer), 1);
+          const index = timeContextChildren.indexOf(layer.timeContext);
+          if (index >= 0) {
+            timeContextChildren.splice(index, 1);
+          }
+          layer.destroy();
         }
-        layer.destroy();
       }
     }
   }
@@ -646,6 +650,7 @@
         timeContext : new wavesUI.core.LayerTimeContext(timeContext));
     }
     track.add(layer);
+    this.layers.push(layer);
     layer.render();
     layer.update();
     if (this.cursorLayer && track.$layout.contains(this.cursorLayer.$el)) {