# HG changeset patch # User Lucas Thompson # Date 1481022218 0 # Node ID af0b4b05311cc63c72e5215f207496bb9eec3dc1 # Parent 933c64ebcd138f977df72ee142979fa61f38a9ca Guard against extraction when no audio is loaded. diff -r 933c64ebcd13 -r af0b4b05311c src/app/app.component.html --- a/src/app/app.component.html Mon Dec 05 16:57:34 2016 +0000 +++ b/src/app/app.component.html Tue Dec 06 11:03:38 2016 +0000 @@ -22,7 +22,9 @@ - + diff -r 933c64ebcd13 -r af0b4b05311c src/app/app.component.ts --- a/src/app/app.component.ts Mon Dec 05 16:57:34 2016 +0000 +++ b/src/app/app.component.ts Tue Dec 06 11:03:38 2016 +0000 @@ -10,11 +10,15 @@ }) export class AppComponent { audioBuffer: AudioBuffer; // TODO consider revising + hasAudioBuffer: boolean; constructor(private audioService: AudioPlayerService, - private piperService: FeatureExtractionService) {} + private piperService: FeatureExtractionService) { + this.hasAudioBuffer = false; + } onFileOpened(file: File) { + this.hasAudioBuffer = false; const reader: FileReader = new FileReader(); const mimeType = file.type; reader.onload = (event: any) => { @@ -24,12 +28,15 @@ // TODO use a rxjs/Subject instead? this.audioService.decodeAudioData(event.target.result).then(audioBuffer => { this.audioBuffer = audioBuffer; + if (this.audioBuffer) + this.hasAudioBuffer = true; }); }; reader.readAsArrayBuffer(file); } - extractFeatures(outputInfo: ExtractorOutputInfo) { + extractFeatures(outputInfo: ExtractorOutputInfo): void { + if (!this.hasAudioBuffer) return; this.piperService.process({ audioData: [...Array(this.audioBuffer.numberOfChannels).keys()] .map(i => this.audioBuffer.getChannelData(i)), diff -r 933c64ebcd13 -r af0b4b05311c src/app/feature-extraction-menu/feature-extraction-menu.component.html --- a/src/app/feature-extraction-menu/feature-extraction-menu.component.html Mon Dec 05 16:57:34 2016 +0000 +++ b/src/app/feature-extraction-menu/feature-extraction-menu.component.html Tue Dec 06 11:03:38 2016 +0000 @@ -7,5 +7,6 @@

+ (click)="extract(extractorOutputs.value)" + [disabled]="disabled">Extract

diff -r 933c64ebcd13 -r af0b4b05311c src/app/feature-extraction-menu/feature-extraction-menu.component.ts --- a/src/app/feature-extraction-menu/feature-extraction-menu.component.ts Mon Dec 05 16:57:34 2016 +0000 +++ b/src/app/feature-extraction-menu/feature-extraction-menu.component.ts Tue Dec 06 11:03:38 2016 +0000 @@ -1,4 +1,4 @@ -import {Component, OnInit, Output, EventEmitter} from '@angular/core'; +import {Component, OnInit, Output, EventEmitter, Input} from '@angular/core'; import {FeatureExtractionService} from "../services/feature-extraction/feature-extraction.service"; export interface ExtractorOutputInfo { @@ -15,8 +15,18 @@ }) export class FeatureExtractionMenuComponent implements OnInit { + @Input() + set disabled(isDisabled: boolean) { + this.isDisabled = isDisabled; + } + + get disabled() { + return this.isDisabled; + } + @Output() requestOutput: EventEmitter; + private isDisabled: boolean; private extractorsMap: Map; extractors: Iterable; @@ -24,6 +34,7 @@ this.extractorsMap = new Map(); this.extractors = []; this.requestOutput = new EventEmitter(); + this.isDisabled = true; } ngOnInit() {