diff src/app/visualisations/vertical-scale.component.ts @ 488:64ed45a0bad3

Introduce PlayheadRenderer, implement in the waves base. Make VerticallyBounded and VerticalScaleRenderer generic and remove bin equivalents. Forward calls for a PlayheadRenderer from VerticalScaleComponent on to its children. Also update other components accordingly.
author Lucas Thompson <dev@lucas.im>
date Wed, 05 Jul 2017 18:42:12 +0100
parents 40ea40ebc2b3
children ab43880f1cd5
line wrap: on
line diff
--- a/src/app/visualisations/vertical-scale.component.ts	Wed Jul 05 17:28:24 2017 +0100
+++ b/src/app/visualisations/vertical-scale.component.ts	Wed Jul 05 18:42:12 2017 +0100
@@ -1,7 +1,11 @@
 /**
  * Created by lucas on 01/06/2017.
  */
-import {VerticalScaleRenderer} from './waves-base.component';
+import {
+  PlayheadManager,
+  PlayheadRenderer,
+  VerticalScaleRenderer
+} from './waves-base.component';
 import {
   ChangeDetectionStrategy,
   Component,
@@ -13,14 +17,20 @@
 @Component({
   selector: 'ugly-vertical-scale',
   template: '<ng-content></ng-content>',
-  changeDetection: ChangeDetectionStrategy.OnPush
+  changeDetection: ChangeDetectionStrategy.OnPush,
+  providers: [
+    {provide: PlayheadRenderer, useExisting: VerticalScaleComponent }
+  ]
 })
-export class VerticalScaleComponent implements AfterViewInit {
+export class VerticalScaleComponent implements AfterViewInit, PlayheadRenderer {
 
   @ContentChildren(
     VerticalScaleRenderer
-  ) bounded: QueryList<VerticalScaleRenderer>;
-  protected cachedRange: [number, number];
+  ) bounded: QueryList<VerticalScaleRenderer<any>>;
+  @ContentChildren(
+    PlayheadRenderer
+  ) seekable: QueryList<PlayheadRenderer>;
+  protected cachedRange: any;
 
   ngAfterViewInit(): void {
     this.bounded.forEach(component => {
@@ -30,4 +40,16 @@
       }
     });
   }
+
+  renderPlayhead(initialTime: number, colour: string): PlayheadManager {
+    const rendered = this.seekable
+      .filter(x => x !== this) // why does QueryList consider itself as a child?
+      .map(component => component.renderPlayhead(initialTime, colour));
+    return {
+      update: (time: number) => {
+        rendered.forEach(component => component.update(time));
+      },
+      remove: () => rendered.map(component => component.remove)
+    };
+  }
 }