annotate src/app/visualisations/waveform/waveform.component.ts @ 454:f93582c38b70

Don't dispose of old audio when loading new audio files. Also move resource manager type out of audio-player.
author Lucas Thompson <dev@lucas.im>
date Thu, 29 Jun 2017 20:08:11 +0100
parents 0329495fd822
children 64ed45a0bad3
rev   line source
dev@347 1 import {
dev@347 2 Component,
dev@354 3 Input,
dev@357 4 ChangeDetectionStrategy
dev@347 5 } from '@angular/core';
dev@347 6 import wavesUI from 'waves-ui-piper';
dev@354 7 import {WavesComponent} from '../waves-base.component';
dev@347 8
dev@347 9
dev@347 10 @Component({
dev@347 11 selector: 'ugly-waveform',
dev@355 12 templateUrl: '../waves-template.html',
dev@357 13 styleUrls: ['../waves-template.css'],
dev@405 14 changeDetection: ChangeDetectionStrategy.OnPush,
dev@405 15 providers: [
dev@405 16 {provide: WavesComponent, useExisting: WaveformComponent}
dev@405 17 ]
dev@347 18 })
dev@383 19 export class WaveformComponent extends WavesComponent<AudioBuffer> {
dev@347 20 @Input() set audioBuffer(buffer: AudioBuffer) {
dev@414 21 this.duration = buffer.duration;
dev@383 22 this.timeline.pixelsPerSecond = this.timeline.visibleWidth / buffer.duration;
dev@383 23 this.feature = buffer;
dev@347 24 }
dev@347 25
dev@383 26 protected get featureLayers(): Layer[] {
dev@383 27 const nChannels = this.feature.numberOfChannels;
dev@383 28 const totalWaveHeight = this.height * 0.9;
dev@383 29 const waveHeight = totalWaveHeight / nChannels;
dev@383 30
dev@383 31 const channelLayers: Layer[] = [];
dev@383 32 for (let ch = 0; ch < nChannels; ++ch) {
dev@383 33 channelLayers.push(new wavesUI.helpers.WaveformLayer(this.feature, {
dev@383 34 top: (this.height - totalWaveHeight) / 2 + waveHeight * ch,
dev@383 35 height: waveHeight,
dev@383 36 color: this.colour,
dev@383 37 channel: ch
dev@383 38 })
dev@383 39 );
dev@347 40 }
dev@383 41 return channelLayers;
dev@347 42 }
dev@347 43 }