comparison src/app/analysis-item/analysis-item.component.ts @ 350:524f5cd75737

Split AnalysisItem out into individual types for root audio items and features. This is messy as is, these need revising and should perhaps be actual concrete types with methods.
author Lucas Thompson <dev@lucas.im>
date Fri, 26 May 2017 12:59:41 +0100
parents d17d5038b11a
children e108249fc2ff
comparison
equal deleted inserted replaced
349:bf038a51f7e3 350:524f5cd75737
7 Input, 7 Input,
8 OnInit 8 OnInit
9 } from '@angular/core'; 9 } from '@angular/core';
10 import {naivePagingMapper} from '../visualisations/WavesJunk'; 10 import {naivePagingMapper} from '../visualisations/WavesJunk';
11 import {OnSeekHandler, TimePixelMapper} from '../playhead/PlayHeadHelpers'; 11 import {OnSeekHandler, TimePixelMapper} from '../playhead/PlayHeadHelpers';
12 import {HigherLevelFeatureShape} from '../visualisations/FeatureUtilities';
12 13
13 export interface AnalysisItem { 14 export interface Item {
14 rootAudioUri: string; 15 id: string;
15 hasSharedTimeline: boolean; 16 hasSharedTimeline: boolean;
16 isRoot: boolean;
17 extractorKey: string;
18 title?: string; 17 title?: string;
19 description?: string; 18 description?: string;
20 id?: string;
21 progress?: number; 19 progress?: number;
22 audioData?: AudioBuffer; 20 }
21
22 export interface PendingRootAudioItem extends Item {
23 uri: string;
24 }
25 export interface RootAudioItem extends PendingRootAudioItem{
26 audioData: AudioBuffer;
27 }
28
29 export interface PendingAnalysisItem extends Item {
30 parent: RootAudioItem;
31 extractorKey: string;
32 }
33
34 export interface AnalysisItem extends PendingAnalysisItem {
35 kind: HigherLevelFeatureShape;
36 }
37
38 export function isPendingRootAudioItem(item: Item): item is PendingRootAudioItem {
39 return typeof (item as RootAudioItem).uri === 'string';
40 }
41
42 export function isRootAudioItem(item: Item): item is RootAudioItem {
43 return isPendingRootAudioItem(item) &&
44 typeof (item as RootAudioItem).uri === 'string';
45 }
46
47 export function isPendingAnalysisItem(item: Item): item is AnalysisItem {
48 const downcast = (item as AnalysisItem);
49 return isRootAudioItem(downcast.parent)
50 && typeof downcast.extractorKey === 'string';
51 }
52
53 export function isAnalysisItem(item: Item): item is AnalysisItem {
54 const downcast = (item as AnalysisItem);
55 return isPendingAnalysisItem(item) && downcast.kind != null;
56 }
57
58 // these should probably be actual concrete types with their own getUri methods
59 export function getRootUri(item: Item): string {
60 if (isPendingRootAudioItem(item)) {
61 return item.uri;
62 }
63 if (isPendingAnalysisItem(item)) {
64 return item.parent.uri;
65 }
66 throw new Error('Invalid item: No URI property set.');
23 } 67 }
24 68
25 @Component({ 69 @Component({
26 selector: 'ugly-analysis-item', 70 selector: 'ugly-analysis-item',
27 templateUrl: './analysis-item.component.html', 71 templateUrl: './analysis-item.component.html',
28 styleUrls: ['./analysis-item.component.css'], 72 styleUrls: ['./analysis-item.component.css'],
29 changeDetection: ChangeDetectionStrategy.OnPush 73 changeDetection: ChangeDetectionStrategy.OnPush
30 }) 74 })
31 export class AnalysisItemComponent implements OnInit { 75 export class AnalysisItemComponent implements OnInit {
32 76
33 @Input() timeline: Timeline; 77 @Input() timeline: Timeline; // TODO should be TimelineTimeContext?
34 @Input() isActive: boolean; 78 @Input() isActive: boolean;
35 @Input() item: AnalysisItem; 79 @Input() item: Item;
36 @Input() contentWidth: number; 80 @Input() contentWidth: number;
37 @Input() onSeek: OnSeekHandler; 81 @Input() onSeek: OnSeekHandler;
38 private hasProgressOnInit = false; 82 private hasProgressOnInit = false;
39 83
40 84
49 isLoading(): boolean { 93 isLoading(): boolean {
50 return this.hasProgressOnInit && this.item.progress < 100; 94 return this.hasProgressOnInit && this.item.progress < 100;
51 } 95 }
52 96
53 isAudioItem(): boolean { 97 isAudioItem(): boolean {
54 return this.item && 98 console.warn('is root?', isRootAudioItem(this.item), this.item);
55 this.item.isRoot && 99 return isRootAudioItem(this.item);
56 this.item.audioData instanceof AudioBuffer;
57 } 100 }
58 } 101 }