diff src/app/app.component.ts @ 49:92c139e16b51

Disable button whilst extracting (for now) - quick fix to stop multiple process requests being sent (as they aren't queued / no request-response matching is done / process requests are synchronous)
author Lucas Thompson <dev@lucas.im>
date Tue, 06 Dec 2016 11:12:56 +0000
parents af0b4b05311c
children f31b14e2132e
line wrap: on
line diff
--- a/src/app/app.component.ts	Tue Dec 06 11:03:38 2016 +0000
+++ b/src/app/app.component.ts	Tue Dec 06 11:12:56 2016 +0000
@@ -10,15 +10,15 @@
 })
 export class AppComponent {
   audioBuffer: AudioBuffer; // TODO consider revising
-  hasAudioBuffer: boolean;
+  canExtract: boolean;
 
   constructor(private audioService: AudioPlayerService,
               private piperService: FeatureExtractionService) {
-    this.hasAudioBuffer = false;
+    this.canExtract = false;
   }
 
   onFileOpened(file: File) {
-    this.hasAudioBuffer = false;
+    this.canExtract = false;
     const reader: FileReader = new FileReader();
     const mimeType = file.type;
     reader.onload = (event: any) => {
@@ -29,14 +29,15 @@
       this.audioService.decodeAudioData(event.target.result).then(audioBuffer => {
         this.audioBuffer = audioBuffer;
         if (this.audioBuffer)
-          this.hasAudioBuffer = true;
+          this.canExtract = true;
       });
     };
     reader.readAsArrayBuffer(file);
   }
 
   extractFeatures(outputInfo: ExtractorOutputInfo): void {
-    if (!this.hasAudioBuffer) return;
+    if (!this.canExtract) return;
+    this.canExtract = false;
     this.piperService.process({
       audioData: [...Array(this.audioBuffer.numberOfChannels).keys()]
         .map(i => this.audioBuffer.getChannelData(i)),
@@ -46,6 +47,9 @@
       },
       key: outputInfo.extractorKey,
       outputId: outputInfo.outputId
-    }).then(data => console.log(data)).catch(err => console.error(err));
+    }).then(data => {
+      this.canExtract = true;
+      console.log(data);
+    }).catch(err => console.error(err));
   }
 }