comparison src/app/waveform/waveform.component.ts @ 10:0b24b8ae62f8

Get some wave-ui layers rendering inside the waveform component, a real shame about the global scope of the waves-ui library currently.
author Lucas Thompson <dev@lucas.im>
date Thu, 27 Oct 2016 08:20:49 +0100
parents a50a4e814ff3
children 7e3ab6f8792f
comparison
equal deleted inserted replaced
9:1fcc8c9ec54c 10:0b24b8ae62f8
1 import {Component, OnInit, ViewChild, ElementRef} from '@angular/core'; 1 import {
2 Component, OnInit, ViewChild, ElementRef,
3 AfterViewInit
4 } from '@angular/core';
2 5
3 declare var wavesUI: any; 6 declare var wavesUI: any;
4 7
5 @Component({ 8 @Component({
6 selector: 'app-waveform', 9 selector: 'app-waveform',
7 templateUrl: './waveform.component.html', 10 templateUrl: './waveform.component.html',
8 styleUrls: ['./waveform.component.css'] 11 styleUrls: ['./waveform.component.css']
9 }) 12 })
10 export class WaveformComponent implements OnInit { 13 export class WaveformComponent implements OnInit, AfterViewInit {
11 @ViewChild('track') trackDiv: ElementRef; 14 @ViewChild('track') trackDiv: ElementRef;
12 15
13 constructor() { 16 constructor() {
14 console.log(wavesUI.core); 17 console.log(wavesUI.core);
15 } 18 }
16 19
17 ngOnInit() { 20 ngOnInit() {}
18 console.log(this.trackDiv.nativeElement.getBoundingClientRect().width); 21
22 ngAfterViewInit(): void {
23 const track: HTMLElement = this.trackDiv.nativeElement;
24 const duration: number = 1.0;
25 const height: number = track.getBoundingClientRect().height;
26 const width: number = track.getBoundingClientRect().width;
27 const pixelsPerSecond = width / duration;
28 const timeline: any = new wavesUI.core.Timeline(pixelsPerSecond, width);
29 timeline.createTrack(track, height, 'main');
30 // time axis
31 const timeAxis = new wavesUI.helpers.TimeAxisLayer({
32 height: height,
33 top: 10,
34 color: 'gray'
35 });
36 timeline.addLayer(timeAxis, 'main', 'default', true);
37 timeline.state = new wavesUI.states.CenteredZoomState(timeline);
19 } 38 }
20 } 39 }