# HG changeset patch # User Lucas Thompson # Date 1496246976 -3600 # Node ID b220ed78a25086a6606dc79e27f4bf36bd3e7b34 # Parent b81ed55fdee3613871235148509c14adc4a1fd25 Rig up instants and add dynamic colour selection to feature components. Structure of a derived WaveComponent is now pretty clear, some refactoring is in order. diff -r b81ed55fdee3 -r b220ed78a250 src/app/analysis-item/analysis-item.component.html --- a/src/app/analysis-item/analysis-item.component.html Wed May 31 15:15:55 2017 +0100 +++ b/src/app/analysis-item/analysis-item.component.html Wed May 31 17:09:36 2017 +0100 @@ -34,6 +34,7 @@
- +
Feature cannot be visualised.
diff -r b81ed55fdee3 -r b220ed78a250 src/app/analysis-item/analysis-item.component.ts --- a/src/app/analysis-item/analysis-item.component.ts Wed May 31 15:15:55 2017 +0100 +++ b/src/app/analysis-item/analysis-item.component.ts Wed May 31 17:09:36 2017 +0100 @@ -10,6 +10,7 @@ import {naivePagingMapper} from '../visualisations/WavesJunk'; import {OnSeekHandler, TimePixelMapper} from '../playhead/PlayHeadHelpers'; import { + defaultColourGenerator, HigherLevelFeatureShape, KnownShapedFeature } from '../visualisations/FeatureUtilities'; @@ -109,4 +110,8 @@ return !isPendingRootAudioItem(this.item) && isAnalysisItem(this.item) ? this.item.shape : null; } + + getNextColour(): string { + return defaultColourGenerator.next().value; + } } diff -r b81ed55fdee3 -r b220ed78a250 src/app/app.module.ts --- a/src/app/app.module.ts Wed May 31 15:15:55 2017 +0100 +++ b/src/app/app.module.ts Wed May 31 17:09:36 2017 +0100 @@ -34,6 +34,7 @@ import {CurveComponent} from './visualisations/curve/curve.component'; import {TracksComponent} from './visualisations/tracks/tracks.components'; import {NotesComponent} from './visualisations/notes/notes.component'; +import {InstantsComponent} from './visualisations/instants/instants.component'; export function createAudioContext(): AudioContext { return new ( @@ -124,7 +125,8 @@ LivePlayHeadComponent, CurveComponent, TracksComponent, - NotesComponent + NotesComponent, + InstantsComponent ], imports: [ BrowserModule, diff -r b81ed55fdee3 -r b220ed78a250 src/app/visualisations/instants/instants.component.ts --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/app/visualisations/instants/instants.component.ts Wed May 31 17:09:36 2017 +0100 @@ -0,0 +1,61 @@ +/** + * Created by lucast on 31/05/2017. + */ +import {WavesComponent} from '../waves-base.component'; +import { + AfterViewInit, + ChangeDetectionStrategy, + Component, + ElementRef, + Input, + ViewChild +} from '@angular/core'; +import {Instant} from '../FeatureUtilities'; +import Waves from 'waves-ui-piper'; + +@Component({ + selector: 'ugly-instants', + templateUrl: '../waves-template.html', + styleUrls: ['../waves-template.css'], + changeDetection: ChangeDetectionStrategy.OnPush +}) +export class InstantsComponent extends WavesComponent implements AfterViewInit { + @ViewChild('track') trackDiv: ElementRef; + + private mFeature: Instant[]; + private height: number; // As it stands, height is fixed. Store once onInit. + + @Input() set instants(instants: Instant[]) { + this.mFeature = instants; + this.update(); + } + + get instants(): Instant[] { + return this.mFeature; + } + + ngAfterViewInit(): void { + this.height = this.trackDiv.nativeElement.getBoundingClientRect().height; + this.renderTimeline(this.trackDiv); + this.update(); + } + + update(): void { + if (!this.waveTrack || !this.instants) { return; } + this.clearTimeline(this.trackDiv); + + this.addLayer( + new Waves.helpers.TickLayer( + this.instants, + { + height: this.height, + color: this.colour, + labelPosition: 'bottom', + shadeSegments: true + } + ), + this.waveTrack, + this.timeline.timeContext + ); + } +}