Mercurial > hg > ugly-duckling
comparison src/app/waveform/waveform.component.ts @ 16:7e3ab6f8792f
Rough waveform loading, issues exist regarding communicating changes from child components (unless using the current workaround with explicit zone running)... investigating.
author | Lucas Thompson <dev@lucas.im> |
---|---|
date | Thu, 27 Oct 2016 17:08:57 +0100 |
parents | 0b24b8ae62f8 |
children | ff964b28a272 |
comparison
equal
deleted
inserted
replaced
15:0571cf863026 | 16:7e3ab6f8792f |
---|---|
1 import { | 1 import { |
2 Component, OnInit, ViewChild, ElementRef, | 2 Component, OnInit, ViewChild, ElementRef, |
3 AfterViewInit | 3 AfterViewInit, OnChanges, SimpleChanges, Input |
4 } from '@angular/core'; | 4 } from '@angular/core'; |
5 | 5 |
6 declare var wavesUI: any; | 6 declare var wavesUI: any; // TODO non-global app scope import |
7 | 7 |
8 @Component({ | 8 @Component({ |
9 selector: 'app-waveform', | 9 selector: 'app-waveform', |
10 templateUrl: './waveform.component.html', | 10 templateUrl: './waveform.component.html', |
11 styleUrls: ['./waveform.component.css'] | 11 styleUrls: ['./waveform.component.css'] |
12 }) | 12 }) |
13 export class WaveformComponent implements OnInit, AfterViewInit { | 13 export class WaveformComponent implements OnInit, AfterViewInit, OnChanges { |
14 @ViewChild('track') trackDiv: ElementRef; | 14 @ViewChild('track') trackDiv: ElementRef; |
15 | 15 |
16 private _audioBuffer: AudioBuffer = undefined; | |
17 | |
18 @Input() | |
19 set audioBuffer(buffer: AudioBuffer) { | |
20 console.log("setter"); | |
21 this._audioBuffer = buffer || undefined; | |
22 } | |
23 | |
24 get audioBuffer(): AudioBuffer { | |
25 return this._audioBuffer; | |
26 } | |
27 | |
28 | |
29 | |
30 private timeline: any; // TODO what type is it? | |
31 | |
16 constructor() { | 32 constructor() { |
17 console.log(wavesUI.core); | |
18 } | 33 } |
19 | 34 |
20 ngOnInit() {} | 35 ngOnInit() {} |
21 | 36 |
22 ngAfterViewInit(): void { | 37 ngAfterViewInit(): void { |
38 // const track: HTMLElement = this.trackDiv.nativeElement; | |
39 // const duration: number = 1.0; | |
40 // const height: number = track.getBoundingClientRect().height; | |
41 // const width: number = track.getBoundingClientRect().width; | |
42 // const pixelsPerSecond = width / duration; | |
43 // const timeline = new wavesUI.core.Timeline(pixelsPerSecond, width); | |
44 // timeline.createTrack(track, height, 'main'); | |
45 // | |
46 // // time axis | |
47 // const timeAxis = new wavesUI.helpers.TimeAxisLayer({ | |
48 // height: height, | |
49 // top: 10, | |
50 // color: 'gray' | |
51 // }); | |
52 // | |
53 // timeline.addLayer(timeAxis, 'main', 'default', true); | |
54 // timeline.state = new wavesUI.states.CenteredZoomState(timeline); | |
55 } | |
56 | |
57 ngOnChanges(changes: SimpleChanges): void { | |
58 console.log("ng changes"); | |
59 if (changes.hasOwnProperty("audioBuffer")) { // why wouldn't it? | |
60 if (changes["audioBuffer"].currentValue) | |
61 this.renderWaveform(changes["audioBuffer"].currentValue); | |
62 } | |
63 } | |
64 | |
65 renderWaveform(buffer: AudioBuffer) { | |
66 // TODO reduce dupe from original timeline state, anyway to actually not instantiate new timeline? | |
67 console.log("render wave"); | |
23 const track: HTMLElement = this.trackDiv.nativeElement; | 68 const track: HTMLElement = this.trackDiv.nativeElement; |
24 const duration: number = 1.0; | 69 const duration: number = buffer.duration; |
25 const height: number = track.getBoundingClientRect().height; | 70 const height: number = track.getBoundingClientRect().height; |
26 const width: number = track.getBoundingClientRect().width; | 71 const width: number = track.getBoundingClientRect().width; |
27 const pixelsPerSecond = width / duration; | 72 const pixelsPerSecond = width / duration; |
28 const timeline: any = new wavesUI.core.Timeline(pixelsPerSecond, width); | 73 const timeline = new wavesUI.core.Timeline(pixelsPerSecond, width); |
29 timeline.createTrack(track, height, 'main'); | 74 timeline.createTrack(track, height, 'main'); |
75 | |
30 // time axis | 76 // time axis |
31 const timeAxis = new wavesUI.helpers.TimeAxisLayer({ | 77 const timeAxis = new wavesUI.helpers.TimeAxisLayer({ |
32 height: height, | 78 height: height, |
33 top: 10, | 79 top: 10, |
34 color: 'gray' | 80 color: 'gray' |
35 }); | 81 }); |
82 | |
36 timeline.addLayer(timeAxis, 'main', 'default', true); | 83 timeline.addLayer(timeAxis, 'main', 'default', true); |
37 timeline.state = new wavesUI.states.CenteredZoomState(timeline); | 84 timeline.state = new wavesUI.states.CenteredZoomState(timeline); |
85 // TODO dispose of the existing layer? | |
86 const waveformLayer = new wavesUI.helpers.WaveformLayer(buffer, { | |
87 height: 600, | |
88 color: 'darkblue' | |
89 }); | |
90 timeline.addLayer(waveformLayer, 'main'); | |
38 } | 91 } |
92 | |
39 } | 93 } |